Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More descriptive exception when the bundled-extension class does not exist #6839

Merged
merged 3 commits into from
Jul 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,16 @@ public static function run($rootPath)
function ($extensions) use ($config) {
foreach ((array) $config['extensions'] as $extensionClass) {
if (is_string($extensionClass)) {
if (!class_exists($extensionClass)) {
throw new LogicException(sprintf('Extension class name "%s" is defined in .bolt.yml or .bolt.php, but the class name is misspelled or not loadable by Composer.', $extensionClass));
}
if (!is_a($extensionClass, ExtensionInterface::class, true)) {
throw new LogicException("$extensionClass needs to implement " . ExtensionInterface::class);
throw new LogicException(sprintf('Extension class "%s" must implement %s', $extensionClass, ExtensionInterface::class));
}
$extensionClass = new $extensionClass();
}
if (!$extensionClass instanceof ExtensionInterface) {
throw new LogicException(get_class($extensionClass) . ' needs to be an instance of ' . ExtensionInterface::class);
throw new LogicException(sprintf('Extension class "%s" must be an instance of %s', get_class($extensionClass), ExtensionInterface::class));
}
$extensions->add($extensionClass);
}
Expand Down
27 changes: 25 additions & 2 deletions tests/phpunit/unit/Bootstrap/BootstrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public function testRunExtensionString()

/**
* @expectedException \LogicException
* @expectedExceptionMessage stdClass needs to implement Bolt\Extension\ExtensionInterface
* @expectedExceptionMessage Extension class "stdClass" must implement Bolt\Extension\ExtensionInterface
*/
public function testRunExtensionStringInvalid()
{
Expand All @@ -358,6 +358,29 @@ public function testRunExtensionStringInvalid()
$this->assertInstanceOf(NormalExtension::class, $ext);
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage Extension class name "DropBear\Ninja" is defined in .bolt.yml or .bolt.php, but the class name is misspelled or not loadable by Composer.
*/
public function testRunExtensionStringNotFound()
{
$config = [
'extensions' => [
'DropBear\Ninja',
],
];

$yaml = (new Dumper())->dump($config, 4, 0, true);
$fs = new Filesystem();
$fs->dumpFile($this->rootPath . '/.bolt.yml', $yaml);

$app = Bootstrap::run($this->rootPath);
$extensions = $app['extensions'];

$ext = $extensions->get('Bolt/Normal');
$this->assertInstanceOf(NormalExtension::class, $ext);
}

public function testRunExtensionObject()
{
$config = <<<EOF
Expand All @@ -381,7 +404,7 @@ public function testRunExtensionObject()

/**
* @expectedException \LogicException
* @expectedExceptionMessage stdClass needs to be an instance of Bolt\Extension\ExtensionInterface
* @expectedExceptionMessage Extension class "stdClass" must be an instance of Bolt\Extension\ExtensionInterface
*/
public function testRunExtensionObjectInvalid()
{
Expand Down