Commit 2c359274 authored by alexpott's avatar alexpott

Issue #2333465 by marcvangend: Fixed Confusing exception message when Deriver...

Issue #2333465 by marcvangend: Fixed Confusing exception message when Deriver plugin does not exist.
parent 60441ca1
......@@ -209,8 +209,11 @@ protected function getDeriver($base_plugin_id, $base_definition) {
protected function getDeriverClass($base_definition) {
$class = NULL;
if ((is_array($base_definition) || ($base_definition = (array) $base_definition)) && (isset($base_definition['deriver']) && $class = $base_definition['deriver'])) {
if (!class_exists($class)) {
throw new InvalidDeriverException(sprintf('Plugin (%s) deriver "%s" does not exist.', $base_definition['id'], $class));
}
if (!is_subclass_of($class, '\Drupal\Component\Plugin\Derivative\DeriverInterface')) {
throw new InvalidDeriverException(sprintf('Plugin (%s) deriver "%s" must implement \Drupal\Component\Plugin\Derivative\DeriverInterface', $base_definition['id'], $class));
throw new InvalidDeriverException(sprintf('Plugin (%s) deriver "%s" must implement \Drupal\Component\Plugin\Derivative\DeriverInterface.', $base_definition['id'], $class));
}
}
return $class;
......
......@@ -88,12 +88,36 @@ public function testGetDerivativeFetcherWithAnnotationObjects() {
$this->assertEquals('\Drupal\Tests\Core\Plugin\Discovery\TestDerivativeDiscoveryWithObject', $definitions['non_container_aware_discovery:test_discovery_1']->deriver);
}
/**
* Tests the getDerivativeFetcher method with a non-existent class.
*
* @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriver().\
*
* @expectedException \Drupal\Component\Plugin\Exception\InvalidDeriverException
* @expectedExceptionMessage Plugin (non_existent_discovery) deriver "\Drupal\system\Tests\Plugin\NonExistentDeriver" does not exist.
*/
public function testNonExistentDerivativeFetcher() {
$definitions = array();
// Do this with a class that doesn't exist.
$definitions['non_existent_discovery'] = array(
'id' => 'non_existent_discovery',
'deriver' => '\Drupal\system\Tests\Plugin\NonExistentDeriver',
);
$this->discoveryMain->expects($this->any())
->method('getDefinitions')
->will($this->returnValue($definitions));
$discovery = new DerivativeDiscoveryDecorator($this->discoveryMain);
$discovery->getDefinitions();
}
/**
* Tests the getDerivativeFetcher method with an invalid class.
*
* @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriver().\
*
* @expectedException \Drupal\Component\Plugin\Exception\InvalidDeriverException
* @expectedExceptionMessage Plugin (invalid_discovery) deriver "\Drupal\system\Tests\Plugin\DerivativeTest" must implement \Drupal\Component\Plugin\Derivative\DeriverInterface.
*/
public function testInvalidDerivativeFetcher() {
$definitions = array();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment