PaymentTypeBaseTest.php in Payment 8.2
File
tests/src/Unit/Plugin/Payment/Type/PaymentTypeBaseTest.php
View source
<?php
namespace Drupal\Tests\payment\Unit\Plugin\Payment\Type;
use Drupal\payment\Entity\PaymentInterface;
use Drupal\payment\EventDispatcherInterface;
use Drupal\payment\Plugin\Payment\Type\PaymentTypeBase;
use Drupal\payment\Response\ResponseInterface;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PaymentTypeBaseTest extends UnitTestCase {
protected $eventDispatcher;
protected $sut;
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();
}
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);
$class_name = get_class($this->sut);
$sut = $class_name::create($container, [], $this
->randomMachineName(), []);
$this
->assertInstanceOf(PaymentTypeBase::class, $sut);
}
public function testCalculateDependencies() {
$this
->assertSame([], $this->sut
->calculateDependencies());
}
public function testDefaultConfiguration() {
$this
->assertSame([], $this->sut
->defaultConfiguration());
}
public function testGetConfiguration() {
$configuration = [
'foo' => $this
->randomMachineName(),
];
$this
->assertNull($this->sut
->setConfiguration($configuration));
$this
->assertSame($configuration, $this->sut
->getConfiguration());
}
public function testGetPayment() {
$payment = $this
->createMock(PaymentInterface::class);
$this
->assertSame($this->sut, $this->sut
->setPayment($payment));
$this
->assertSame($payment, $this->sut
->getPayment());
}
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());
}
}