Skip to content

Commit f9ea410

Browse files
committed
Ensure directory exists when generating autload paths.
1 parent dc2b5b4 commit f9ea410

2 files changed

Lines changed: 14 additions & 24 deletions

File tree

src/Plugin.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public function preAutoloadDump(Event $event): void
6363
$extra['plugin-paths'] = ['plugins'];
6464
}
6565

66-
$root = dirname(realpath($event->getComposer()->getConfig()->get('vendor-dir')));
66+
$root = dirname(realpath($event->getComposer()->getConfig()->get('vendor-dir'))) . '/';
6767
foreach ($extra['plugin-paths'] as $pluginsPath) {
68-
foreach (new DirectoryIterator($root . '/' . $pluginsPath) as $fileInfo) {
68+
foreach (new DirectoryIterator($root . $pluginsPath) as $fileInfo) {
6969
if (!$fileInfo->isDir() || $fileInfo->isDot()) {
7070
continue;
7171
}
@@ -78,10 +78,10 @@ public function preAutoloadDump(Event $event): void
7878
$pluginNamespace = $folderName . '\\';
7979
$pluginTestNamespace = $folderName . '\\Test\\';
8080
$path = $pluginsPath . '/' . $folderName . '/';
81-
if (!isset($autoload['psr-4'][$pluginNamespace])) {
81+
if (!isset($autoload['psr-4'][$pluginNamespace]) && is_dir($root . $path . '/src')) {
8282
$autoload['psr-4'][$pluginNamespace] = $path . 'src';
8383
}
84-
if (!isset($devAutoload['psr-4'][$pluginTestNamespace])) {
84+
if (!isset($devAutoload['psr-4'][$pluginTestNamespace]) && is_dir($root . $path . '/tests')) {
8585
$devAutoload['psr-4'][$pluginTestNamespace] = $path . 'tests';
8686
}
8787
}

tests/TestCase/PluginTest.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ class PluginTest extends TestCase
3333
* @var array<string>
3434
*/
3535
protected array $testDirs = [
36-
'',
3736
'vendor',
38-
'plugins',
3937
'plugins/Foo',
40-
'plugins/Fee',
41-
'plugins/Foe',
38+
'plugins/Fee/src',
39+
'plugins/Fee/tests',
40+
'plugins/Foe/src',
4241
'plugins/Fum',
43-
'app_plugins',
44-
'app_plugins/Bar',
42+
'app_plugins/Bar/src',
43+
'app_plugins/Bar/tests',
4544
];
4645

4746
protected string $path;
@@ -62,7 +61,7 @@ public function setUp(): void
6261

6362
foreach ($this->testDirs as $dir) {
6463
if (!is_dir($this->path . '/' . $dir)) {
65-
mkdir($this->path . '/' . $dir);
64+
mkdir($this->path . '/' . $dir, 0777, true);
6665
}
6766
}
6867

@@ -96,16 +95,10 @@ public function tearDown(): void
9695
{
9796
parent::tearDown();
9897

99-
$dirs = array_reverse($this->testDirs);
100-
101-
if (is_file($this->path . '/vendor/cakephp-plugins.php')) {
102-
unlink($this->path . '/vendor/cakephp-plugins.php');
103-
}
104-
105-
foreach ($dirs as $dir) {
106-
if (is_dir($this->path . '/' . $dir)) {
107-
rmdir($this->path . '/' . $dir);
108-
}
98+
if (PHP_OS === 'Windows') {
99+
exec(sprintf('rd /s /q %s', escapeshellarg($this->path)));
100+
} else {
101+
exec(sprintf('rm -rf %s', escapeshellarg($this->path)));
109102
}
110103
}
111104

@@ -154,7 +147,6 @@ public function testPreAutoloadDump()
154147
'psr-4' => [
155148
'Foo\\' => 'xyz/Foo/src',
156149
'Fee\\' => 'plugins/Fee/src',
157-
'Fum\\' => 'plugins/Fum/src',
158150
'Foe\\' => 'plugins/Foe/src',
159151
'Bar\\' => 'app_plugins/Bar/src',
160152
],
@@ -165,8 +157,6 @@ public function testPreAutoloadDump()
165157
'psr-4' => [
166158
'Foo\Test\\' => 'xyz/Foo/tests',
167159
'Fee\Test\\' => 'plugins/Fee/tests',
168-
'Fum\Test\\' => 'plugins/Fum/tests',
169-
'Foe\Test\\' => 'plugins/Foe/tests',
170160
'Bar\Test\\' => 'app_plugins/Bar/tests',
171161
],
172162
];

0 commit comments

Comments
 (0)