@@ -133,6 +133,103 @@ public function testSetGitCommitter()
133133 $ output
134134 );
135135 }
136+ /**
137+ * @covers ::distributePackage
138+ */
139+ public function testRun ()
140+ {
141+ $ cwd = getcwd ();
142+ $ cli = new Split ();
143+ $ cli ->setEscapeCharacter ('# ' );
144+ $ dist = new Update ();
145+
146+ $ directory1 = sys_get_temp_dir ().'/split-test- ' .mt_rand (0 , 9999999 );
147+ FileSystem::createDir ($ directory1 );
148+ FileSystem::createDir ("$ directory1/sub-package " );
149+ FileSystem::createDir ("$ directory1/api/vendor " );
150+ $ directory1 = realpath ($ directory1 );
151+ $ subPackageDirectory = realpath ("$ directory1/sub-package " );
152+
153+ $ directory2 = sys_get_temp_dir ().'/split-test- ' .mt_rand (0 , 9999999 );
154+ FileSystem::createDir ("$ directory2/tests " );
155+ $ directory2 = realpath ($ directory2 );
156+
157+ chdir ($ directory1 );
158+ file_put_contents ('composer.json ' , json_encode (['name ' => 'vendor/package ' ]));
159+ file_put_contents ('sub-package/composer.json ' , json_encode (['name ' => 'vendor/sub-package ' ]));
160+ file_put_contents ('a.txt ' , 'A ' );
161+ file_put_contents ('b.txt ' , 'B ' );
162+ file_put_contents ('c.txt ' , 'C ' );
163+ shell_exec ('git init 2>&1 ' );
164+ shell_exec ('git add --all 2>&1 ' );
165+ shell_exec ('git commit --message=Init 2>&1 ' );
166+ preg_match ('/^commit (\S+)/ ' , shell_exec ('git log -n 1 ' ), $ match );
167+ $ hash1 = $ match [1 ];
168+
169+ file_put_contents ('api/vendor/sub-package.json ' , json_encode ([
170+ 'packages ' => [
171+ 'vendor/sub-package ' => [
172+ 'dev-master ' => [
173+ 'source ' => [
174+ 'type ' => 'git ' ,
175+ 'url ' => $ directory2 ,
176+ ],
177+ ],
178+ ],
179+ ],
180+ ]));
181+
182+ chdir ($ directory2 );
183+ file_put_contents ('composer.json ' , json_encode (['name ' => 'vendor/sub-package ' ]));
184+ file_put_contents ('d.txt ' , 'D ' );
185+ file_put_contents ('e.txt ' , 'E ' );
186+ file_put_contents ('f.txt ' , 'F ' );
187+ shell_exec ('git init 2>&1 ' );
188+ shell_exec ('git add --all 2>&1 ' );
189+ file_put_contents ('message.txt ' , "ABC \n\nsplit: $ hash1 " );
190+ shell_exec ('git commit --file=message.txt 2>&1 ' );
191+
192+ chdir ($ directory1 );
193+
194+ ob_start ();
195+ $ dist ->api = 'api/%s.json ' ;
196+ $ return = $ dist ->run ($ cli );
197+ $ output = ob_get_contents ();
198+ ob_end_clean ();
199+
200+ $ outputDirectory = realpath ("$ directory1/dist " );
201+ $ contentD = @file_get_contents ("$ outputDirectory/vendor/sub-package/d.txt " );
202+ $ contentE = @file_get_contents ("$ outputDirectory/vendor/sub-package/e.txt " );
203+ $ contentF = @file_get_contents ("$ outputDirectory/vendor/sub-package/f.txt " );
204+
205+ chdir ($ cwd );
206+
207+ foreach ([$ directory1 , $ directory2 ] as $ directory ) {
208+ @shell_exec ('rm -rf ' . escapeshellarg ($ directory ) . ' 2>&1 ' );
209+ file_exists ($ directory ) && @shell_exec ('rmdir /S /Q ' . escapeshellarg ($ directory ) . ' 2>&1 ' );
210+ @FileSystem::delete ($ directory );
211+ }
212+
213+ $ path = $ directory1 .DIRECTORY_SEPARATOR ;
214+ $ expected = implode ("\n" , array_merge ([
215+ 'vendor/package ' ,
216+ '#[1;35mBuild vendor/sub-package ' ,
217+ "#[0m#[1;32mgit clone $ directory2 {$ path }dist/vendor/sub-package " ,
218+ "#[0m#[1;30mCloning into ' {$ path }dist/vendor/sub-package'... " ,
219+ 'done. ' ,
220+ "#[0m#[1;34mcd {$ path }dist/vendor/sub-package " ,
221+ '#[0m#[1;32mgit checkout master ' ,
222+ "#[0m#[1;34mcd $ subPackageDirectory " ,
223+ '#[0m#[0;32mvendor/sub-package is already up to date. ' ,
224+ "#[0m#[1;35mBuild distributed in {$ path }dist " ,
225+ '#[0m ' ,
226+ ]));
227+ $ this ->assertSame ($ expected , $ output );
228+ $ this ->assertTrue ($ return );
229+ $ this ->assertSame ('D ' , $ contentD );
230+ $ this ->assertSame ('E ' , $ contentE );
231+ $ this ->assertSame ('F ' , $ contentF );
232+ }
136233
137234 /**
138235 * @covers ::distributePackage
0 commit comments