class YamlDiscoveryDecoratorTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryDecoratorTest.php \Drupal\Tests\Core\Plugin\Discovery\YamlDiscoveryDecoratorTest
- 8.9.x core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryDecoratorTest.php \Drupal\Tests\Core\Plugin\Discovery\YamlDiscoveryDecoratorTest
- 10 core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryDecoratorTest.php \Drupal\Tests\Core\Plugin\Discovery\YamlDiscoveryDecoratorTest
YamlDiscoveryDecorator unit tests.
@group Plugin
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Plugin\Discovery\YamlDiscoveryDecoratorTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of YamlDiscoveryDecoratorTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Plugin/ Discovery/ YamlDiscoveryDecoratorTest.php, line 15
Namespace
Drupal\Tests\Core\Plugin\DiscoveryView source
class YamlDiscoveryDecoratorTest extends UnitTestCase {
/**
* The YamlDiscovery instance to test.
*
* @var \Drupal\Core\Plugin\Discovery\YamlDiscoveryDecorator
*/
protected $discoveryDecorator;
/**
* Expected provider => key mappings for testing.
*
* @var array
*/
protected $expectedKeys = [
'test_1' => 'test_1_a',
'another_provider_1' => 'test_1_b',
'another_provider_2' => 'test_2_a',
'test_2' => 'test_2_b',
'decorated_1' => 'decorated_test_1',
'decorated_2' => 'decorated_test_2',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$base_path = __DIR__ . '/Fixtures';
// Set up the directories to search.
$directories = [
'test_1' => $base_path . '/test_1',
'test_2' => $base_path . '/test_2',
];
$definitions = [
'decorated_test_1' => [
'id' => 'decorated_test_1',
'name' => 'Decorated test 1',
'provider' => 'decorated_1',
],
'decorated_test_2' => [
'id' => 'decorated_test_2',
'name' => 'Decorated test 1',
'provider' => 'decorated_2',
],
];
$decorated = $this->createMock('Drupal\\Component\\Plugin\\Discovery\\DiscoveryInterface');
$decorated->expects($this->once())
->method('getDefinitions')
->willReturn($definitions);
$this->discoveryDecorator = new YamlDiscoveryDecorator($decorated, 'test', $directories);
}
/**
* Tests the getDefinitions() method.
*/
public function testGetDefinitions() : void {
$definitions = $this->discoveryDecorator
->getDefinitions();
$this->assertIsArray($definitions);
$this->assertCount(6, $definitions);
foreach ($this->expectedKeys as $expected_key) {
$this->assertArrayHasKey($expected_key, $definitions);
}
foreach ($definitions as $id => $definition) {
foreach ([
'name',
'id',
'provider',
] as $key) {
$this->assertArrayHasKey($key, $definition);
}
$this->assertEquals($id, $definition['id']);
$this->assertEquals(array_search($id, $this->expectedKeys), $definition['provider']);
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
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::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUpBeforeClass | public static | function | ||
YamlDiscoveryDecoratorTest::$discoveryDecorator | protected | property | The YamlDiscovery instance to test. | |
YamlDiscoveryDecoratorTest::$expectedKeys | protected | property | Expected provider => key mappings for testing. | |
YamlDiscoveryDecoratorTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
YamlDiscoveryDecoratorTest::testGetDefinitions | public | function | Tests the getDefinitions() method. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.