class PaymentStatusManagerTest in Payment 8.2
@coversDefaultClass \Drupal\payment\Plugin\Payment\Status\PaymentStatusManager
@group Payment
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment\Unit\Plugin\Payment\Status\PaymentStatusManagerTest
Expanded class hierarchy of PaymentStatusManagerTest
File
- tests/
src/ Unit/ Plugin/ Payment/ Status/ PaymentStatusManagerTest.php, line 20
Namespace
Drupal\Tests\payment\Unit\Plugin\Payment\StatusView source
class PaymentStatusManagerTest extends UnitTestCase {
/**
* The cache backend.
*
* @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $cache;
/**
* The class resolver.
*
* @var \Drupal\Core\DependencyInjection\ClassResolverInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $classResolver;
/**
* The plugin discovery.
*
* @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $discovery;
/**
* The plugin factory.
*
* @var \Drupal\Component\Plugin\Factory\FactoryInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $factory;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $moduleHandler;
/**
* The string translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $stringTranslation;
/**
* The class under test.
*
* @var \Drupal\payment\Plugin\Payment\Status\PaymentStatusManager
*/
public $sut;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->classResolver = $this
->createMock(ClassResolverInterface::class);
$this->discovery = $this
->createMock(DiscoveryInterface::class);
$this->factory = $this
->createMock(FactoryInterface::class);
$this->moduleHandler = $this
->createMock(ModuleHandlerInterface::class);
$this->moduleHandler
->expects($this
->atLeastOnce())
->method('getModuleDirectories')
->willReturn([]);
$this->cache = $this
->createMock(CacheBackendInterface::class);
$this->stringTranslation = $this
->getStringTranslationStub();
$this->sut = new PaymentStatusManager($this->cache, $this->moduleHandler, $this->classResolver, $this->stringTranslation);
$property = new \ReflectionProperty($this->sut, 'discovery');
$property
->setAccessible(TRUE);
$property
->setValue($this->sut, $this->discovery);
$property = new \ReflectionProperty($this->sut, 'factory');
$property
->setAccessible(TRUE);
$property
->setValue($this->sut, $this->factory);
}
/**
* @covers ::getFallbackPluginId
*/
public function testGetFallbackPluginId() {
$plugin_id = $this
->randomMachineName();
$plugin_configuration = array(
$this
->randomMachineName(),
);
$this
->assertIsString($this->sut
->getFallbackPluginId($plugin_id, $plugin_configuration));
}
/**
* @covers ::getDefinitions
* @covers ::processDefinition
*/
public function testGetDefinitions() {
$discovery_definitions = array(
'foo' => array(
'id' => NULL,
'parent_id' => NULL,
'label' => $this
->randomMachineName(),
'description' => NULL,
'operations_provider' => NULL,
'class' => DefaultPaymentStatus::class,
),
);
$manager_definitions = $discovery_definitions;
$manager_definitions['foo']['label'] = new TranslatableMarkup($manager_definitions['foo']['label'], [], [], $this->stringTranslation);
$this->discovery
->expects($this
->once())
->method('getDefinitions')
->willReturn($discovery_definitions);
$this->moduleHandler
->expects($this
->once())
->method('alter')
->with('payment_status');
$this
->assertEquals($manager_definitions, $this->sut
->getDefinitions());
}
/**
* @covers ::getChildren
* @depends testGetDefinitions
*/
public function testGetChildren() {
$definitions = array(
'foo' => array(
'id' => 'foo',
),
'bar' => array(
'id' => 'bar',
'parent_id' => 'foo',
),
);
$this->discovery
->expects($this
->once())
->method('getDefinitions')
->willReturn($definitions);
$this
->assertSame(array(
'bar',
), $this->sut
->getChildren('foo'));
}
/**
* @covers ::getDescendants
* @depends testGetDefinitions
*/
public function testGetDescendants() {
$definitions = array(
'foo' => array(
'id' => 'foo',
),
'bar' => array(
'id' => 'bar',
'parent_id' => 'foo',
),
'baz' => array(
'id' => 'baz',
'parent_id' => 'bar',
),
);
$this->discovery
->expects($this
->once())
->method('getDefinitions')
->willReturn($definitions);
$this
->assertSame(array(
'bar',
'baz',
), $this->sut
->getDescendants('foo'));
}
/**
* @covers ::getAncestors
* @depends testGetDefinitions
*/
public function testGetAncestors() {
$definitions = array(
'foo' => array(
'id' => 'foo',
),
'bar' => array(
'id' => 'bar',
'parent_id' => 'foo',
),
'baz' => array(
'id' => 'baz',
'parent_id' => 'bar',
),
);
$this->discovery
->expects($this
->once())
->method('getDefinitions')
->willReturn($definitions);
$this
->assertSame(array(
'bar',
'foo',
), $this->sut
->getAncestors('baz'));
}
/**
* @covers ::hasAncestor
* @depends testGetDefinitions
*/
public function testHasAncestor() {
$definitions = array(
'foo' => array(
'id' => 'foo',
),
'bar' => array(
'id' => 'bar',
'parent_id' => 'foo',
),
'baz' => array(
'id' => 'baz',
'parent_id' => 'bar',
),
);
$this->discovery
->expects($this
->once())
->method('getDefinitions')
->willReturn($definitions);
$this
->assertTrue($this->sut
->hasAncestor('baz', 'foo'));
$this
->assertFalse($this->sut
->hasAncestor('baz', 'baz'));
}
/**
* @covers ::isOrHasAncestor
* @depends testGetDefinitions
*/
public function testIsOrHasAncestor() {
$definitions = array(
'foo' => array(
'id' => 'foo',
),
'bar' => array(
'id' => 'bar',
'parent_id' => 'foo',
),
'baz' => array(
'id' => 'baz',
'parent_id' => 'bar',
),
);
$this->discovery
->expects($this
->once())
->method('getDefinitions')
->willReturn($definitions);
$this
->assertTrue($this->sut
->isOrHasAncestor('baz', 'foo'));
$this
->assertTrue($this->sut
->isOrHasAncestor('baz', 'baz'));
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PaymentStatusManagerTest:: |
protected | property | The cache backend. | |
PaymentStatusManagerTest:: |
protected | property | The class resolver. | |
PaymentStatusManagerTest:: |
protected | property | The plugin discovery. | |
PaymentStatusManagerTest:: |
protected | property | The plugin factory. | |
PaymentStatusManagerTest:: |
protected | property | The module handler. | |
PaymentStatusManagerTest:: |
protected | property | The string translator. | |
PaymentStatusManagerTest:: |
public | property | The class under test. | |
PaymentStatusManagerTest:: |
public | function |
Overrides UnitTestCase:: |
|
PaymentStatusManagerTest:: |
public | function | @covers ::getAncestors @depends testGetDefinitions | |
PaymentStatusManagerTest:: |
public | function | @covers ::getChildren @depends testGetDefinitions | |
PaymentStatusManagerTest:: |
public | function | @covers ::getDefinitions @covers ::processDefinition | |
PaymentStatusManagerTest:: |
public | function | @covers ::getDescendants @depends testGetDefinitions | |
PaymentStatusManagerTest:: |
public | function | @covers ::getFallbackPluginId | |
PaymentStatusManagerTest:: |
public | function | @covers ::hasAncestor @depends testGetDefinitions | |
PaymentStatusManagerTest:: |
public | function | @covers ::isOrHasAncestor @depends testGetDefinitions | |
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. |