class DefaultSingleLazyPluginCollectionTest
Same name and namespace in other branches
- 11.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
- 8.9.x 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 uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- 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 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());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.