You are here

public function DerivativeDiscoveryDecoratorTest::testInvalidDerivativeFetcher in Drupal 8

Tests the getDerivativeFetcher method with an invalid class.

See also

\Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriver().\

File

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

Class

DerivativeDiscoveryDecoratorTest
Unit tests for the derivative discovery decorator.

Namespace

Drupal\Tests\Core\Plugin\Discovery

Code

public function testInvalidDerivativeFetcher() {
  $definitions = [];

  // Do this with a class that doesn't implement the interface.
  $definitions['invalid_discovery'] = [
    'id' => 'invalid_discovery',
    'deriver' => '\\Drupal\\KernelTests\\Core\\Plugin\\DerivativeTest',
  ];
  $this->discoveryMain
    ->expects($this
    ->any())
    ->method('getDefinitions')
    ->will($this
    ->returnValue($definitions));
  $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain);
  $this
    ->expectException(InvalidDeriverException::class);
  $this
    ->expectExceptionMessage('Plugin (invalid_discovery) deriver "\\Drupal\\KernelTests\\Core\\Plugin\\DerivativeTest" must implement \\Drupal\\Component\\Plugin\\Derivative\\DeriverInterface.');
  $discovery
    ->getDefinitions();
}