class PaymentTypeBaseTest in Payment 8.2
@coversDefaultClass \Drupal\payment\Plugin\Payment\Type\PaymentTypeBase
@group Payment
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment\Unit\Plugin\Payment\Type\PaymentTypeBaseTest
Expanded class hierarchy of PaymentTypeBaseTest
File
- tests/
src/ Unit/ Plugin/ Payment/ Type/ PaymentTypeBaseTest.php, line 17
Namespace
Drupal\Tests\payment\Unit\Plugin\Payment\TypeView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PaymentTypeBaseTest:: |
protected | property | The event dispatcher. | |
PaymentTypeBaseTest:: |
protected | property | The class under test. | |
PaymentTypeBaseTest:: |
public | function |
Overrides UnitTestCase:: |
|
PaymentTypeBaseTest:: |
public | function | @covers ::calculateDependencies | |
PaymentTypeBaseTest:: |
public | function | @covers ::create @covers ::__construct | |
PaymentTypeBaseTest:: |
public | function | @covers ::defaultConfiguration | |
PaymentTypeBaseTest:: |
public | function | @covers ::setConfiguration @covers ::getConfiguration | |
PaymentTypeBaseTest:: |
public | function | @covers ::setPayment @covers ::getPayment | |
PaymentTypeBaseTest:: |
public | function | @covers ::getResumeContextResponse | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |