You are here

class SymfonyEventDispatcherTest in Payment 8.2

@coversDefaultClass \Drupal\payment\SymfonyEventDispatcher

@group Payment

Hierarchy

Expanded class hierarchy of SymfonyEventDispatcherTest

File

tests/src/Unit/SymfonyEventDispatcherTest.php, line 27

Namespace

Drupal\Tests\payment\Unit
View source
class SymfonyEventDispatcherTest extends UnitTestCase {

  /**
   * The Symfony event dispatcher.
   *
   * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $symfonyEventDispatcher;

  /**
   * The subject under test.
   *
   * @var \Drupal\payment\SymfonyEventDispatcher
   */
  protected $sut;

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    $this->symfonyEventDispatcher = $this
      ->createMock(EventDispatcherInterface::class);
    $this->sut = new SymfonyEventDispatcher($this->symfonyEventDispatcher);
  }

  /**
   * @covers ::alterQueueLoadedPaymentIds
   */
  public function testAlterQueueLoadedPaymentIds() {
    $queue_id = $this
      ->randomMachineName();
    $category_id = $this
      ->randomMachineName();
    $owner_id = mt_rand();
    $payment_ids = [
      mt_rand(),
      mt_rand(),
      mt_rand(),
    ];
    $this->symfonyEventDispatcher
      ->expects($this
      ->once())
      ->method('dispatch')
      ->with(PaymentEvents::PAYMENT_QUEUE_PAYMENT_IDS_ALTER, $this
      ->isInstanceOf(PaymentQueuePaymentIdsAlter::class));
    $this
      ->assertSame($payment_ids, $this->sut
      ->alterQueueLoadedPaymentIds($queue_id, $category_id, $owner_id, $payment_ids));
  }

  /**
   * @covers ::setPaymentStatus
   */
  public function testSetPaymentStatus() {
    $payment = $this
      ->createMock(PaymentInterface::class);
    $previous_payment_status = $this
      ->createMock(PaymentStatusInterface::class);
    $this->symfonyEventDispatcher
      ->expects($this
      ->once())
      ->method('dispatch')
      ->with(PaymentEvents::PAYMENT_STATUS_SET, $this
      ->isInstanceOf(PaymentStatusSet::class));
    $this->sut
      ->setPaymentStatus($payment, $previous_payment_status);
  }

  /**
   * @covers ::preExecutePayment
   *
   */
  public function testPreExecutePayment() {
    $payment = $this
      ->createMock(PaymentInterface::class);
    $this->symfonyEventDispatcher
      ->expects($this
      ->once())
      ->method('dispatch')
      ->with(PaymentEvents::PAYMENT_PRE_EXECUTE, $this
      ->isInstanceOf(PaymentPreExecute::class));
    $this->sut
      ->preExecutePayment($payment);
  }

  /**
   * @covers ::executePaymentAccess
   */
  public function testExecutePaymentAccess() {
    $payment = $this
      ->createMock(PaymentInterface::class);
    $payment_method = $this
      ->createMock(PaymentMethodInterface::class);
    $account = $this
      ->createMock(AccountInterface::class);
    $this->symfonyEventDispatcher
      ->expects($this
      ->once())
      ->method('dispatch')
      ->with(PaymentEvents::PAYMENT_EXECUTE_ACCESS, $this
      ->isInstanceOf(PaymentExecuteAccess::class));
    $this
      ->assertInstanceOf(AccessResultInterface::class, $this->sut
      ->executePaymentAccess($payment, $payment_method, $account));
  }

  /**
   * @covers ::preCapturePayment
   */
  public function testPreCapturePayment() {
    $payment = $this
      ->createMock(PaymentInterface::class);
    $this->symfonyEventDispatcher
      ->expects($this
      ->once())
      ->method('dispatch')
      ->with(PaymentEvents::PAYMENT_PRE_CAPTURE, $this
      ->isInstanceOf(PaymentPreCapture::class));
    $this->sut
      ->preCapturePayment($payment);
  }

  /**
   * @covers ::preRefundPayment
   */
  public function testPreRefundPayment() {
    $payment = $this
      ->createMock(PaymentInterface::class);
    $this->symfonyEventDispatcher
      ->expects($this
      ->once())
      ->method('dispatch')
      ->with(PaymentEvents::PAYMENT_PRE_REFUND, $this
      ->isInstanceOf(PaymentPreRefund::class));
    $this->sut
      ->preRefundPayment($payment);
  }

  /**
   * @covers ::preResumeContext
   */
  public function testPreResumeContext() {
    $payment = $this
      ->createMock(PaymentInterface::class);
    $this->symfonyEventDispatcher
      ->expects($this
      ->once())
      ->method('dispatch')
      ->with(PaymentEvents::PAYMENT_TYPE_PRE_RESUME_CONTEXT, $this
      ->isInstanceOf(PaymentTypePreResumeContext::class));
    $this->sut
      ->preResumeContext($payment);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
SymfonyEventDispatcherTest::$sut protected property The subject under test.
SymfonyEventDispatcherTest::$symfonyEventDispatcher protected property The Symfony event dispatcher.
SymfonyEventDispatcherTest::setUp public function Overrides UnitTestCase::setUp
SymfonyEventDispatcherTest::testAlterQueueLoadedPaymentIds public function @covers ::alterQueueLoadedPaymentIds
SymfonyEventDispatcherTest::testExecutePaymentAccess public function @covers ::executePaymentAccess
SymfonyEventDispatcherTest::testPreCapturePayment public function @covers ::preCapturePayment
SymfonyEventDispatcherTest::testPreExecutePayment public function @covers ::preExecutePayment
SymfonyEventDispatcherTest::testPreRefundPayment public function @covers ::preRefundPayment
SymfonyEventDispatcherTest::testPreResumeContext public function @covers ::preResumeContext
SymfonyEventDispatcherTest::testSetPaymentStatus public function @covers ::setPaymentStatus
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.