You are here

class PaymentTypeBaseTest in Payment 8.2

@coversDefaultClass \Drupal\payment\Plugin\Payment\Type\PaymentTypeBase

@group Payment

Hierarchy

Expanded class hierarchy of PaymentTypeBaseTest

File

tests/src/Unit/Plugin/Payment/Type/PaymentTypeBaseTest.php, line 17

Namespace

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

  /**
   * The event dispatcher.
   *
   * @var \Drupal\payment\EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $eventDispatcher;

  /**
   * The class under test.
   *
   * @var \Drupal\payment\Plugin\Payment\Type\PaymentTypeBase|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $sut;

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    $this->eventDispatcher = $this
      ->createMock(EventDispatcherInterface::class);
    $configuration = [];
    $plugin_id = $this
      ->randomMachineName();
    $plugin_definition = [];
    $this->sut = $this
      ->getMockBuilder(PaymentTypeBase::class)
      ->setConstructorArgs([
      $configuration,
      $plugin_id,
      $plugin_definition,
      $this->eventDispatcher,
    ])
      ->getMockForAbstractClass();
  }

  /**
   * @covers ::create
   * @covers ::__construct
   */
  public function testCreate() {
    $container = $this
      ->createMock(ContainerInterface::class);
    $map = [
      [
        'payment.event_dispatcher',
        ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
        $this->eventDispatcher,
      ],
    ];
    $container
      ->expects($this
      ->any())
      ->method('get')
      ->willReturnMap($map);

    /** @var \Drupal\payment\Plugin\Payment\Type\PaymentTypeBase $class_name */
    $class_name = get_class($this->sut);
    $sut = $class_name::create($container, [], $this
      ->randomMachineName(), []);
    $this
      ->assertInstanceOf(PaymentTypeBase::class, $sut);
  }

  /**
   * @covers ::calculateDependencies
   */
  public function testCalculateDependencies() {
    $this
      ->assertSame([], $this->sut
      ->calculateDependencies());
  }

  /**
   * @covers ::defaultConfiguration
   */
  public function testDefaultConfiguration() {
    $this
      ->assertSame([], $this->sut
      ->defaultConfiguration());
  }

  /**
   * @covers ::setConfiguration
   * @covers ::getConfiguration
   */
  public function testGetConfiguration() {
    $configuration = [
      'foo' => $this
        ->randomMachineName(),
    ];
    $this
      ->assertNull($this->sut
      ->setConfiguration($configuration));
    $this
      ->assertSame($configuration, $this->sut
      ->getConfiguration());
  }

  /**
   * @covers ::setPayment
   * @covers ::getPayment
   */
  public function testGetPayment() {
    $payment = $this
      ->createMock(PaymentInterface::class);
    $this
      ->assertSame($this->sut, $this->sut
      ->setPayment($payment));
    $this
      ->assertSame($payment, $this->sut
      ->getPayment());
  }

  /**
   * @covers ::getResumeContextResponse
   *
   * @depends testGetPayment
   */
  public function testGetResumeContextResponse() {
    $response = $this
      ->createMock(ResponseInterface::class);
    $payment = $this
      ->createMock(PaymentInterface::class);
    $this->sut
      ->setPayment($payment);
    $this->sut
      ->expects($this
      ->atLeastOnce())
      ->method('doGetResumeContextResponse')
      ->willReturn($response);
    $this->eventDispatcher
      ->expects($this
      ->once())
      ->method('preResumeContext')
      ->with($payment);
    $this
      ->assertSame($response, $this->sut
      ->getResumeContextResponse());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PaymentTypeBaseTest::$eventDispatcher protected property The event dispatcher.
PaymentTypeBaseTest::$sut protected property The class under test.
PaymentTypeBaseTest::setUp public function Overrides UnitTestCase::setUp
PaymentTypeBaseTest::testCalculateDependencies public function @covers ::calculateDependencies
PaymentTypeBaseTest::testCreate public function @covers ::create @covers ::__construct
PaymentTypeBaseTest::testDefaultConfiguration public function @covers ::defaultConfiguration
PaymentTypeBaseTest::testGetConfiguration public function @covers ::setConfiguration @covers ::getConfiguration
PaymentTypeBaseTest::testGetPayment public function @covers ::setPayment @covers ::getPayment
PaymentTypeBaseTest::testGetResumeContextResponse public function @covers ::getResumeContextResponse
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.