You are here

class PaymentAwarePluginFilteredPluginManagerTest in Payment 8.2

@coversDefaultClass \Drupal\payment\Plugin\Payment\PaymentAwarePluginManagerDecorator

@group Payment

Hierarchy

Expanded class hierarchy of PaymentAwarePluginFilteredPluginManagerTest

File

tests/src/Unit/Plugin/Payment/PaymentAwarePluginFilteredPluginManagerTest.php, line 17

Namespace

Drupal\Tests\payment\Unit\Plugin\Payment
View source
class PaymentAwarePluginFilteredPluginManagerTest extends UnitTestCase {

  /**
   * The payment to filter methods by.
   *
   * @var \Drupal\payment\Entity\PaymentInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $payment;

  /**
   * The original plugin manager.
   *
   * @var \Drupal\Component\Plugin\PluginManagerInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $pluginManager;

  /**
   * The class under test.
   *
   * @var \Drupal\payment\Plugin\Payment\PaymentAwarePluginManagerDecorator
   */
  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);
  }

  /**
   * @covers ::createInstance
   */
  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));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PaymentAwarePluginFilteredPluginManagerTest::$payment protected property The payment to filter methods by.
PaymentAwarePluginFilteredPluginManagerTest::$pluginManager protected property The original plugin manager.
PaymentAwarePluginFilteredPluginManagerTest::$sut protected property The class under test.
PaymentAwarePluginFilteredPluginManagerTest::setUp public function Overrides UnitTestCase::setUp
PaymentAwarePluginFilteredPluginManagerTest::testCreateInstance public function @covers ::createInstance
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.