Skip to content

Commit 5420701

Browse files
authored
Merge pull request #71 from cakephp/2.x-plugins-folder-doesnt-exist
2.x: fix error if plugin-paths contains unknown folder
2 parents d800ea4 + fd89d2d commit 5420701

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/Plugin.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public function preAutoloadDump(Event $event): void
6565

6666
$root = dirname(realpath($event->getComposer()->getConfig()->get('vendor-dir'))) . '/';
6767
foreach ($extra['plugin-paths'] as $pluginsPath) {
68+
if (!is_dir($root . $pluginsPath)) {
69+
continue;
70+
}
6871
foreach (new DirectoryIterator($root . $pluginsPath) as $fileInfo) {
6972
if (!$fileInfo->isDir() || $fileInfo->isDot()) {
7073
continue;

tests/TestCase/PluginTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,45 @@ public function testPreAutoloadDump()
163163
$this->assertEquals($expected, $package->getDevAutoload());
164164
}
165165

166+
public function testPreAutoloadDumpNonExistentPluginPaths()
167+
{
168+
$package = new RootPackage('App', '1.0.0', '1.0.0');
169+
$package->setExtra([
170+
'plugin-paths' => [
171+
'unknown_folder',
172+
],
173+
]);
174+
$package->setAutoload([
175+
'psr-4' => [
176+
'Foo\\' => 'xyz/Foo/src',
177+
],
178+
]);
179+
$package->setDevAutoload([
180+
'psr-4' => [
181+
'Foo\Test\\' => 'xyz/Foo/tests',
182+
],
183+
]);
184+
$this->composer->setPackage($package);
185+
186+
$event = new Event('', $this->composer, $this->io);
187+
188+
$this->plugin->preAutoloadDump($event);
189+
190+
$expected = [
191+
'psr-4' => [
192+
'Foo\\' => 'xyz/Foo/src',
193+
],
194+
];
195+
$this->assertEquals($expected, $package->getAutoload());
196+
197+
$expected = [
198+
'psr-4' => [
199+
'Foo\Test\\' => 'xyz/Foo/tests',
200+
],
201+
];
202+
$this->assertEquals($expected, $package->getDevAutoload());
203+
}
204+
166205
public function testGetPrimaryNamespace()
167206
{
168207
$autoload = [

0 commit comments

Comments
 (0)