88use Composer \Config ;
99use Composer \IO \IOInterface ;
1010use Composer \Package \Package ;
11+ use Composer \Package \RootPackage ;
1112use Composer \Repository \RepositoryManager ;
13+ use Composer \Script \Event ;
1214use Composer \Util \HttpDownloader ;
1315use PHPUnit \Framework \TestCase ;
1416
@@ -31,15 +33,14 @@ class PluginTest extends TestCase
3133 * @var array<string>
3234 */
3335 protected array $ testDirs = [
34- '' ,
3536 'vendor ' ,
36- 'plugins ' ,
3737 'plugins/Foo ' ,
38- 'plugins/Fee ' ,
39- 'plugins/Foe ' ,
38+ 'plugins/Fee/src ' ,
39+ 'plugins/Fee/tests ' ,
40+ 'plugins/Foe/src ' ,
4041 'plugins/Fum ' ,
41- 'app_plugins ' ,
42- 'app_plugins/Bar ' ,
42+ 'app_plugins/Bar/src ' ,
43+ 'app_plugins/Bar/tests ' ,
4344 ];
4445
4546 protected string $ path ;
@@ -60,14 +61,16 @@ public function setUp(): void
6061
6162 foreach ($ this ->testDirs as $ dir ) {
6263 if (!is_dir ($ this ->path . '/ ' . $ dir )) {
63- mkdir ($ this ->path . '/ ' . $ dir );
64+ mkdir ($ this ->path . '/ ' . $ dir, 0777 , true );
6465 }
6566 }
6667
6768 $ this ->composer = new Composer ();
6869 $ config = new Config ();
6970 $ config ->merge ([
70- 'vendor-dir ' => $ this ->path . '/vendor ' ,
71+ 'config ' => [
72+ 'vendor-dir ' => $ this ->path . '/vendor ' ,
73+ ],
7174 ]);
7275
7376 $ this ->composer ->setConfig ($ config );
@@ -92,23 +95,18 @@ public function tearDown(): void
9295 {
9396 parent ::tearDown ();
9497
95- $ dirs = array_reverse ($ this ->testDirs );
96-
97- if (is_file ($ this ->path . '/vendor/cakephp-plugins.php ' )) {
98- unlink ($ this ->path . '/vendor/cakephp-plugins.php ' );
99- }
100-
101- foreach ($ dirs as $ dir ) {
102- if (is_dir ($ this ->path . '/ ' . $ dir )) {
103- rmdir ($ this ->path . '/ ' . $ dir );
104- }
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 )));
105102 }
106103 }
107104
108105 public function testGetSubscribedEvents ()
109106 {
110107 $ expected = [
111108 'post-autoload-dump ' => 'postAutoloadDump ' ,
109+ 'pre-autoload-dump ' => 'preAutoloadDump ' ,
112110 ];
113111
114112 $ this ->assertSame ($ expected , $ this ->plugin ->getSubscribedEvents ());
@@ -120,6 +118,51 @@ public function testGetConfigFilePath()
120118 $ this ->assertFileExists (dirname ($ path ));
121119 }
122120
121+ public function testPreAutoloadDump ()
122+ {
123+ $ package = new RootPackage ('App ' , '1.0.0 ' , '1.0.0 ' );
124+ $ package ->setExtra ([
125+ 'plugin-paths ' => [
126+ 'app_plugins ' ,
127+ 'plugins ' ,
128+ ],
129+ ]);
130+ $ package ->setAutoload ([
131+ 'psr-4 ' => [
132+ 'Foo \\' => 'xyz/Foo/src ' ,
133+ ],
134+ ]);
135+ $ package ->setDevAutoload ([
136+ 'psr-4 ' => [
137+ 'Foo\Test \\' => 'xyz/Foo/tests ' ,
138+ ],
139+ ]);
140+ $ this ->composer ->setPackage ($ package );
141+
142+ $ event = new Event ('' , $ this ->composer , $ this ->io );
143+
144+ $ this ->plugin ->preAutoloadDump ($ event );
145+
146+ $ expected = [
147+ 'psr-4 ' => [
148+ 'Foo \\' => 'xyz/Foo/src ' ,
149+ 'Fee \\' => 'plugins/Fee/src ' ,
150+ 'Foe \\' => 'plugins/Foe/src ' ,
151+ 'Bar \\' => 'app_plugins/Bar/src ' ,
152+ ],
153+ ];
154+ $ this ->assertEquals ($ expected , $ package ->getAutoload ());
155+
156+ $ expected = [
157+ 'psr-4 ' => [
158+ 'Foo\Test \\' => 'xyz/Foo/tests ' ,
159+ 'Fee\Test \\' => 'plugins/Fee/tests ' ,
160+ 'Bar\Test \\' => 'app_plugins/Bar/tests ' ,
161+ ],
162+ ];
163+ $ this ->assertEquals ($ expected , $ package ->getDevAutoload ());
164+ }
165+
123166 public function testGetPrimaryNamespace ()
124167 {
125168 $ autoload = [
0 commit comments