function DerivativeDiscoveryDecoratorTest::testGetDerivativeFetcherWithAnnotationObjects

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php \Drupal\Tests\Core\Plugin\Discovery\DerivativeDiscoveryDecoratorTest::testGetDerivativeFetcherWithAnnotationObjects()
  2. 8.9.x core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php \Drupal\Tests\Core\Plugin\Discovery\DerivativeDiscoveryDecoratorTest::testGetDerivativeFetcherWithAnnotationObjects()
  3. 10 core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php \Drupal\Tests\Core\Plugin\Discovery\DerivativeDiscoveryDecoratorTest::testGetDerivativeFetcherWithAnnotationObjects()

Tests the getDerivativeFetcher method with objects instead of arrays.

File

core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php, line 68

Class

DerivativeDiscoveryDecoratorTest
Unit tests for the derivative discovery decorator.

Namespace

Drupal\Tests\Core\Plugin\Discovery

Code

public function testGetDerivativeFetcherWithAnnotationObjects() : void {
    $definitions = [];
    $definitions['non_container_aware_discovery'] = (object) [
        'id' => 'non_container_aware_discovery',
        'deriver' => '\\Drupal\\Tests\\Core\\Plugin\\Discovery\\TestDerivativeDiscoveryWithObject',
    ];
    $this->discoveryMain
        ->expects($this->any())
        ->method('getDefinitions')
        ->willReturn($definitions);
    $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain);
    $definitions = $discovery->getDefinitions();
    // Ensure that both test derivatives got added.
    $this->assertCount(2, $definitions);
    $this->assertInstanceOf('\\stdClass', $definitions['non_container_aware_discovery:test_discovery_0']);
    $this->assertEquals('non_container_aware_discovery', $definitions['non_container_aware_discovery:test_discovery_0']->id);
    $this->assertEquals('\\Drupal\\Tests\\Core\\Plugin\\Discovery\\TestDerivativeDiscoveryWithObject', $definitions['non_container_aware_discovery:test_discovery_0']->deriver);
    $this->assertInstanceOf('\\stdClass', $definitions['non_container_aware_discovery:test_discovery_1']);
    $this->assertEquals('non_container_aware_discovery', $definitions['non_container_aware_discovery:test_discovery_1']->id);
    $this->assertEquals('\\Drupal\\Tests\\Core\\Plugin\\Discovery\\TestDerivativeDiscoveryWithObject', $definitions['non_container_aware_discovery:test_discovery_1']->deriver);
}

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