Skip to content

Commit

Permalink
fix error if plugin-paths contains unknown folder
Browse files Browse the repository at this point in the history
  • Loading branch information
LordSimal committed Sep 10, 2023
1 parent d800ea4 commit fd89d2d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public function preAutoloadDump(Event $event): void

$root = dirname(realpath($event->getComposer()->getConfig()->get('vendor-dir'))) . '/';
foreach ($extra['plugin-paths'] as $pluginsPath) {
if (!is_dir($root . $pluginsPath)) {
continue;
}
foreach (new DirectoryIterator($root . $pluginsPath) as $fileInfo) {
if (!$fileInfo->isDir() || $fileInfo->isDot()) {
continue;
Expand Down
39 changes: 39 additions & 0 deletions tests/TestCase/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,45 @@ public function testPreAutoloadDump()
$this->assertEquals($expected, $package->getDevAutoload());
}

public function testPreAutoloadDumpNonExistentPluginPaths()
{
$package = new RootPackage('App', '1.0.0', '1.0.0');
$package->setExtra([
'plugin-paths' => [
'unknown_folder',
],
]);
$package->setAutoload([
'psr-4' => [
'Foo\\' => 'xyz/Foo/src',
],
]);
$package->setDevAutoload([
'psr-4' => [
'Foo\Test\\' => 'xyz/Foo/tests',
],
]);
$this->composer->setPackage($package);

$event = new Event('', $this->composer, $this->io);

$this->plugin->preAutoloadDump($event);

$expected = [
'psr-4' => [
'Foo\\' => 'xyz/Foo/src',
],
];
$this->assertEquals($expected, $package->getAutoload());

$expected = [
'psr-4' => [
'Foo\Test\\' => 'xyz/Foo/tests',
],
];
$this->assertEquals($expected, $package->getDevAutoload());
}

public function testGetPrimaryNamespace()
{
$autoload = [
Expand Down

0 comments on commit fd89d2d

Please sign in to comment.