class PaymentStatusBaseTest in Payment 8.2
@coversDefaultClass \Drupal\payment\Plugin\Payment\Status\PaymentStatusBase
@group Payment
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment\Unit\Plugin\Payment\Status\PaymentStatusBaseTest
Expanded class hierarchy of PaymentStatusBaseTest
File
- tests/
src/ Unit/ Plugin/ Payment/ Status/ PaymentStatusBaseTest.php, line 20
Namespace
Drupal\Tests\payment\Unit\Plugin\Payment\StatusView source
class PaymentStatusBaseTest extends UnitTestCase {
/**
* The default datetime.
*
* @var \Drupal\Core\Datetime\DrupalDateTime|\PHPUnit\Framework\MockObject\MockObject
*/
protected $defaultDateTime;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $languageManager;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $moduleHandler;
/**
* The payment status plugin manager.
*
* @var \Drupal\payment\Plugin\Payment\Status\PaymentStatusManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
public $paymentStatusManager;
/**
* The definition of the payment status under test.
*
* @var array
*/
public $pluginDefinition;
/**
* The ID of the payment status under test.
*
* @var string
*/
public $pluginId;
/**
* The class under test.
*
* @var \Drupal\payment\Plugin\Payment\Status\PaymentStatusBase|\PHPUnit\Framework\MockObject\MockObject
*/
public $sut;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->defaultDateTime = $this
->getMockBuilder(DrupalDateTime::class)
->disableOriginalConstructor()
->getMock();
$language = $this
->createMock(LanguageInterface::class);
$this->languageManager = $this
->createMock(LanguageManagerInterface::class);
$this->languageManager
->expects($this
->any())
->method('getCurrentLanguage')
->willReturn($language);
$this->moduleHandler = $this
->createMock(ModuleHandlerInterface::class);
$this->paymentStatusManager = $this
->createMock(PaymentStatusManagerInterface::class);
$configuration = [];
$this->pluginId = $this
->randomMachineName();
$this->pluginDefinition = array(
'label' => $this
->randomMachineName(),
);
$this->sut = $this
->getMockBuilder(PaymentStatusBase::class)
->setConstructorArgs(array(
$configuration,
$this->pluginId,
$this->pluginDefinition,
$this->moduleHandler,
$this->paymentStatusManager,
$this->defaultDateTime,
))
->getMockForAbstractClass();
}
/**
* @covers ::create
* @covers ::__construct
*/
public function testCreate() {
$container = $this
->createMock(ContainerInterface::class);
\Drupal::setContainer($container);
$map = array(
array(
'language_manager',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->languageManager,
),
array(
'module_handler',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->moduleHandler,
),
array(
'plugin.manager.payment.status',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->paymentStatusManager,
),
);
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
/** @var \Drupal\payment\Plugin\Payment\LineItem\PaymentLineItemBase $class_name */
$class_name = get_class($this->sut);
$sut = $class_name::create($container, [], $this
->randomMachineName(), []);
$this
->assertInstanceOf(PaymentStatusBase::class, $sut);
}
/**
* @covers ::defaultConfiguration
*/
public function testDefaultConfiguration() {
$expected_configuration = array(
'created' => time(),
'id' => 0,
);
$this
->assertSame($expected_configuration, $this->sut
->defaultConfiguration());
}
/**
* @covers ::setConfiguration
* @covers ::getConfiguration
*/
public function testGetConfiguration() {
$configuration = array(
$this
->randomMachineName() => mt_rand(),
) + $this->sut
->defaultConfiguration();
$this
->assertNull($this->sut
->setConfiguration($configuration));
$this
->assertSame($configuration, $this->sut
->getConfiguration());
}
/**
* @covers ::setCreated
* @covers ::getCreated
*/
public function testGetCreated() {
$created = mt_rand();
$this
->assertSame($this->sut, $this->sut
->setCreated($created));
$this
->assertSame($created, $this->sut
->getCreated());
}
/**
* @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 ::getChildren
*/
public function testGetChildren() {
$children = array(
$this
->randomMachineName(),
);
$this->paymentStatusManager
->expects($this
->once())
->method('getChildren')
->with($this->pluginId)
->willReturn($children);
$this
->assertSame($children, $this->sut
->getChildren());
}
/**
* @covers ::getDescendants
*/
public function testGetDescendants() {
$descendants = array(
$this
->randomMachineName(),
);
$this->paymentStatusManager
->expects($this
->once())
->method('getDescendants')
->with($this->pluginId)
->willReturn($descendants);
$this
->assertSame($descendants, $this->sut
->getDescendants());
}
/**
* @covers ::getAncestors
*/
public function testGetAncestors() {
$ancestors = array(
$this
->randomMachineName(),
);
$this->paymentStatusManager
->expects($this
->once())
->method('getAncestors')
->with($this->pluginId)
->willReturn($ancestors);
$this
->assertSame($ancestors, $this->sut
->getAncestors());
}
/**
* @covers ::hasAncestor
*/
public function testHasAncestor() {
$expected = TRUE;
$this->paymentStatusManager
->expects($this
->once())
->method('hasAncestor')
->with($this->pluginId)
->willReturn($expected);
$this
->assertSame($expected, $this->sut
->hasAncestor($this->pluginId));
}
/**
* @covers ::isOrHasAncestor
*/
public function testIsOrHasAncestor() {
$expected = TRUE;
$this->paymentStatusManager
->expects($this
->once())
->method('isOrHasAncestor')
->with($this->pluginId)
->willReturn($expected);
$this
->assertSame($expected, $this->sut
->isOrHasAncestor($this->pluginId));
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PaymentStatusBaseTest:: |
protected | property | The default datetime. | |
PaymentStatusBaseTest:: |
protected | property | The language manager. | |
PaymentStatusBaseTest:: |
protected | property | The module handler. | |
PaymentStatusBaseTest:: |
public | property | The payment status plugin manager. | |
PaymentStatusBaseTest:: |
public | property | The definition of the payment status under test. | |
PaymentStatusBaseTest:: |
public | property | The ID of the payment status under test. | |
PaymentStatusBaseTest:: |
public | property | The class under test. | |
PaymentStatusBaseTest:: |
public | function |
Overrides UnitTestCase:: |
|
PaymentStatusBaseTest:: |
public | function | @covers ::create @covers ::__construct | |
PaymentStatusBaseTest:: |
public | function | @covers ::defaultConfiguration | |
PaymentStatusBaseTest:: |
public | function | @covers ::getAncestors | |
PaymentStatusBaseTest:: |
public | function | @covers ::getChildren | |
PaymentStatusBaseTest:: |
public | function | @covers ::setConfiguration @covers ::getConfiguration | |
PaymentStatusBaseTest:: |
public | function | @covers ::setCreated @covers ::getCreated | |
PaymentStatusBaseTest:: |
public | function | @covers ::getDescendants | |
PaymentStatusBaseTest:: |
public | function | @covers ::setPayment @covers ::getPayment | |
PaymentStatusBaseTest:: |
public | function | @covers ::hasAncestor | |
PaymentStatusBaseTest:: |
public | function | @covers ::isOrHasAncestor | |
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. |