PaymentAwarePluginFilteredPluginManagerTest.php in Payment 8.2
File
tests/src/Unit/Plugin/Payment/PaymentAwarePluginFilteredPluginManagerTest.php
View source
<?php
namespace Drupal\Tests\payment\Unit\Plugin\Payment;
use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\payment\Entity\PaymentInterface;
use Drupal\payment\PaymentAwareInterface;
use Drupal\payment\Plugin\Payment\PaymentAwarePluginManagerDecorator;
use Drupal\Tests\UnitTestCase;
class PaymentAwarePluginFilteredPluginManagerTest extends UnitTestCase {
protected $payment;
protected $pluginManager;
protected $sut;
public function setUp() : void {
$this->payment = $this
->createMock(PaymentInterface::class);
$this->pluginManager = $this
->createMock(PluginManagerInterface::class);
$this->sut = new PaymentAwarePluginManagerDecorator($this->payment, $this->pluginManager);
}
public function testCreateInstance() {
$plugin_id_a = $this
->randomMachineName();
$plugin_a = $this
->createMock(PluginInspectionInterface::class);
$plugin_id_b = $this
->randomMachineName();
$plugin_b = $this
->createMock(PaymentAwarePluginFilteredPluginManagerUnitTestPaymentAwarePlugin::class);
$plugin_b
->expects($this
->atLeastOnce())
->method('setPayment')
->with($this->payment);
$map = [
[
$plugin_id_a,
[],
$plugin_a,
],
[
$plugin_id_b,
[],
$plugin_b,
],
];
$this->pluginManager
->expects($this
->atLeast(count($map)))
->method('createInstance')
->willReturnMap($map);
$this
->assertSame($plugin_a, $this->sut
->createInstance($plugin_id_a));
$this
->assertSame($plugin_b, $this->sut
->createInstance($plugin_id_b));
}
}
abstract class PaymentAwarePluginFilteredPluginManagerUnitTestPaymentAwarePlugin implements PaymentAwareInterface, PluginInspectionInterface {
}