class DefaultSingleLazyPluginCollectionTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php \Drupal\Tests\Core\Plugin\DefaultSingleLazyPluginCollectionTest
- 8.9.x core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php \Drupal\Tests\Core\Plugin\DefaultSingleLazyPluginCollectionTest
- 10 core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php \Drupal\Tests\Core\Plugin\DefaultSingleLazyPluginCollectionTest
@coversDefaultClass \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection @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\LazyPluginCollectionTestBase extends \Drupal\Tests\UnitTestCase
- class \Drupal\Tests\Core\Plugin\DefaultSingleLazyPluginCollectionTest extends \Drupal\Tests\Core\Plugin\LazyPluginCollectionTestBase
- class \Drupal\Tests\Core\Plugin\LazyPluginCollectionTestBase extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of DefaultSingleLazyPluginCollectionTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Plugin/ DefaultSingleLazyPluginCollectionTest.php, line 16
Namespace
Drupal\Tests\Core\PluginView source
class DefaultSingleLazyPluginCollectionTest extends LazyPluginCollectionTestBase {
/**
* {@inheritdoc}
*/
protected function setupPluginCollection(?InvocationOrder $create_count = NULL) : void {
$definitions = $this->getPluginDefinitions();
$this->pluginInstances['apple'] = new ConfigurablePlugin([
'id' => 'apple',
'key' => 'value',
], 'apple', $definitions['apple']);
$this->pluginInstances['banana'] = new ConfigurablePlugin([
'id' => 'banana',
'key' => 'other_value',
], 'banana', $definitions['banana']);
$create_count = $create_count ?: $this->never();
$this->pluginManager
->expects($create_count)
->method('createInstance')
->willReturnCallback(function ($id) {
return $this->pluginInstances[$id];
});
$this->defaultPluginCollection = new DefaultSingleLazyPluginCollection($this->pluginManager, 'apple', [
'id' => 'apple',
'key' => 'value',
]);
}
/**
* Tests the get() method.
*/
public function testGet() : void {
$this->setupPluginCollection($this->once());
$apple = $this->pluginInstances['apple'];
$this->assertSame($apple, $this->defaultPluginCollection
->get('apple'));
}
/**
* @covers ::addInstanceId
* @covers ::getConfiguration
* @covers ::setConfiguration
*/
public function testAddInstanceId() : void {
$this->setupPluginCollection($this->any());
$this->assertEquals([
'id' => 'apple',
'key' => 'value',
], $this->defaultPluginCollection
->get('apple')
->getConfiguration());
$this->assertEquals([
'id' => 'apple',
'key' => 'value',
], $this->defaultPluginCollection
->getConfiguration());
$this->defaultPluginCollection
->addInstanceId('banana', [
'id' => 'banana',
'key' => 'other_value',
]);
$this->assertEquals([
'id' => 'apple',
'key' => 'value',
], $this->defaultPluginCollection
->get('apple')
->getConfiguration());
$this->assertEquals([
'id' => 'banana',
'key' => 'other_value',
], $this->defaultPluginCollection
->getConfiguration());
$this->assertEquals([
'id' => 'banana',
'key' => 'other_value',
], $this->defaultPluginCollection
->get('banana')
->getConfiguration());
}
/**
* @covers ::getInstanceIds
*/
public function testGetInstanceIds() : void {
$this->setupPluginCollection($this->any());
$this->assertEquals([
'apple' => 'apple',
], $this->defaultPluginCollection
->getInstanceIds());
$this->defaultPluginCollection
->addInstanceId('banana', [
'id' => 'banana',
'key' => 'other_value',
]);
$this->assertEquals([
'banana' => 'banana',
], $this->defaultPluginCollection
->getInstanceIds());
}
/**
* @covers ::setConfiguration
*/
public function testConfigurableSetConfiguration() : void {
$this->setupPluginCollection($this->any());
$this->defaultPluginCollection
->setConfiguration([
'apple' => [
'value' => 'pineapple',
'id' => 'apple',
],
]);
$config = $this->defaultPluginCollection
->getConfiguration();
$this->assertSame([
'apple' => [
'value' => 'pineapple',
'id' => 'apple',
],
], $config);
$plugin = $this->pluginInstances['apple'];
$this->assertSame([
'apple' => [
'value' => 'pineapple',
'id' => 'apple',
],
], $plugin->getConfiguration());
$this->defaultPluginCollection
->setConfiguration([]);
$this->assertSame([], $this->defaultPluginCollection
->getConfiguration());
$this->defaultPluginCollection
->setConfiguration([
'cherry' => [
'value' => 'kiwi',
'id' => 'cherry',
],
]);
$expected['cherry'] = [
'value' => 'kiwi',
'id' => 'cherry',
];
$config = $this->defaultPluginCollection
->getConfiguration();
$this->assertSame($expected, $config);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
DefaultSingleLazyPluginCollectionTest::setupPluginCollection | protected | function | Overrides LazyPluginCollectionTestBase::setupPluginCollection | ||
DefaultSingleLazyPluginCollectionTest::testAddInstanceId | public | function | @covers ::addInstanceId @covers ::getConfiguration @covers ::setConfiguration |
||
DefaultSingleLazyPluginCollectionTest::testConfigurableSetConfiguration | public | function | @covers ::setConfiguration | ||
DefaultSingleLazyPluginCollectionTest::testGet | public | function | Tests the get() method. | ||
DefaultSingleLazyPluginCollectionTest::testGetInstanceIds | public | function | @covers ::getInstanceIds | ||
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. | ||
LazyPluginCollectionTestBase::$config | protected | property | Contains the plugin configuration. | ||
LazyPluginCollectionTestBase::$defaultPluginCollection | protected | property | The tested plugin collection. | ||
LazyPluginCollectionTestBase::$pluginInstances | protected | property | Stores all setup plugin instances. | 1 | |
LazyPluginCollectionTestBase::$pluginManager | protected | property | The mocked plugin manager. | ||
LazyPluginCollectionTestBase::getPluginDefinitions | protected | function | Returns some example plugin definitions. | ||
LazyPluginCollectionTestBase::getPluginMock | protected | function | Returns a mocked plugin object. | 1 | |
LazyPluginCollectionTestBase::returnPluginMap | public | function | Return callback for createInstance. | ||
LazyPluginCollectionTestBase::setUp | protected | function | Overrides UnitTestCase::setUp | ||
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::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 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.