class DefaultSingleLazyPluginCollectionTest

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php \Drupal\Tests\Core\Plugin\DefaultSingleLazyPluginCollectionTest
  2. 10 core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php \Drupal\Tests\Core\Plugin\DefaultSingleLazyPluginCollectionTest
  3. 11.x core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php \Drupal\Tests\Core\Plugin\DefaultSingleLazyPluginCollectionTest

@coversDefaultClass \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection @group Plugin

Hierarchy

Expanded class hierarchy of DefaultSingleLazyPluginCollectionTest

File

core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php, line 14

Namespace

Drupal\Tests\Core\Plugin
View source
class DefaultSingleLazyPluginCollectionTest extends LazyPluginCollectionTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected function setupPluginCollection(InvokedRecorder $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

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
DefaultSingleLazyPluginCollectionTest::setupPluginCollection protected function Sets up the default plugin collection. Overrides LazyPluginCollectionTestBase::setupPluginCollection
DefaultSingleLazyPluginCollectionTest::testAddInstanceId public function @covers ::addInstanceId
@covers ::getConfiguration
@covers ::setConfiguration
DefaultSingleLazyPluginCollectionTest::testGet public function Tests the get() method.
DefaultSingleLazyPluginCollectionTest::testGetInstanceIds public function @covers ::getInstanceIds
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
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
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::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.