class DefaultSingleLazyPluginCollectionTest in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php \Drupal\Tests\Core\Plugin\DefaultSingleLazyPluginCollectionTest
- 9 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, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitWarnings
- class \Drupal\Tests\Core\Plugin\LazyPluginCollectionTestBase
- class \Drupal\Tests\Core\Plugin\DefaultSingleLazyPluginCollectionTest
- class \Drupal\Tests\Core\Plugin\LazyPluginCollectionTestBase
Expanded class hierarchy of DefaultSingleLazyPluginCollectionTest
File
- core/
tests/ Drupal/ Tests/ Core/ Plugin/ DefaultSingleLazyPluginCollectionTest.php, line 14
Namespace
Drupal\Tests\Core\PluginView source
class DefaultSingleLazyPluginCollectionTest extends LazyPluginCollectionTestBase {
/**
* {@inheritdoc}
*/
protected function setupPluginCollection(InvocationOrder $create_count = NULL) {
$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() {
$this
->setupPluginCollection($this
->once());
$apple = $this->pluginInstances['apple'];
$this
->assertSame($apple, $this->defaultPluginCollection
->get('apple'));
}
/**
* @covers ::addInstanceId
* @covers ::getConfiguration
* @covers ::setConfiguration
*/
public function testAddInstanceId() {
$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() {
$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());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DefaultSingleLazyPluginCollectionTest:: |
protected | function |
Sets up the default plugin collection. Overrides LazyPluginCollectionTestBase:: |
|
DefaultSingleLazyPluginCollectionTest:: |
public | function | @covers ::addInstanceId @covers ::getConfiguration @covers ::setConfiguration | |
DefaultSingleLazyPluginCollectionTest:: |
public | function | Tests the get() method. | |
DefaultSingleLazyPluginCollectionTest:: |
public | function | @covers ::getInstanceIds | |
LazyPluginCollectionTestBase:: |
protected | property | Contains the plugin configuration. | |
LazyPluginCollectionTestBase:: |
protected | property | The tested plugin collection. | |
LazyPluginCollectionTestBase:: |
protected | property | Stores all setup plugin instances. | 1 |
LazyPluginCollectionTestBase:: |
protected | property | The mocked plugin manager. | |
LazyPluginCollectionTestBase:: |
protected | function | Returns some example plugin definitions. | |
LazyPluginCollectionTestBase:: |
protected | function | Returns a mocked plugin object. | 1 |
LazyPluginCollectionTestBase:: |
public | function | Return callback for createInstance. | |
LazyPluginCollectionTestBase:: |
protected | function |
Overrides UnitTestCase:: |
|
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 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. | |
UnitTestCase:: |
public static | function |