@@ -233,9 +233,54 @@ public function testApplyPatch(array $filesCurrentlyInApp, RecipePatch $recipePa
233
233
$ this ->assertSame ($ expectedConflicts , $ hadConflicts );
234
234
}
235
235
236
- public function getApplyPatchTests (): iterable
236
+ /**
237
+ * @dataProvider getApplyPatchTests
238
+ */
239
+ public function testApplyPatchOnSubfolder (array $ filesCurrentlyInApp , RecipePatch $ recipePatch , array $ expectedFiles , bool $ expectedConflicts )
237
240
{
238
- $ files = $ this ->getFilesForPatching ();
241
+ $ mainProjectPath = FLEX_TEST_DIR ;
242
+ $ subProjectPath = FLEX_TEST_DIR .'/ProjectA ' ;
243
+
244
+ (new Process (['git ' , 'init ' ], $ mainProjectPath ))->mustRun ();
245
+ (new Process (['git ' , 'config ' , 'user.name ' , 'Unit test ' ], $ mainProjectPath ))->mustRun ();
246
+ (new Process (['git ' , 'config ' , 'user.email ' , '' ], $ mainProjectPath ))->mustRun ();
247
+
248
+ if (!file_exists ($ subProjectPath )) {
249
+ mkdir ($ subProjectPath , 0777 , true );
250
+ }
251
+
252
+ foreach ($ filesCurrentlyInApp as $ file => $ contents ) {
253
+ $ path = $ subProjectPath .'/ ' .$ file ;
254
+ if (!file_exists (\dirname ($ path ))) {
255
+ @mkdir (\dirname ($ path ), 0777 , true );
256
+ }
257
+ file_put_contents ($ path , $ contents );
258
+ }
259
+ if (\count ($ filesCurrentlyInApp ) > 0 ) {
260
+ (new Process (['git ' , 'add ' , '-A ' ], $ subProjectPath ))->mustRun ();
261
+ (new Process (['git ' , 'commit ' , '-m ' , 'Committing original files ' ], $ subProjectPath ))->mustRun ();
262
+ }
263
+
264
+ $ patcher = new RecipePatcher ($ subProjectPath , $ this ->createMock (IOInterface::class));
265
+ $ hadConflicts = !$ patcher ->applyPatch ($ recipePatch );
266
+
267
+ foreach ($ expectedFiles as $ file => $ expectedContents ) {
268
+ if (null === $ expectedContents ) {
269
+ $ this ->assertFileDoesNotExist ($ subProjectPath .'/ ' .$ file );
270
+
271
+ continue ;
272
+ }
273
+ $ this ->assertFileExists ($ subProjectPath .'/ ' .$ file );
274
+ $ this ->assertSame ($ expectedContents , file_get_contents ($ subProjectPath .'/ ' .$ file ));
275
+ }
276
+
277
+ $ this ->assertSame ($ expectedConflicts , $ hadConflicts );
278
+ }
279
+
280
+ public function getApplyPatchTests (string $ testMethodName ): iterable
281
+ {
282
+ $ projectRootPath = ('testApplyPatchOnSubfolder ' === $ testMethodName ) ? 'ProjectA/ ' : '' ;
283
+ $ files = $ this ->getFilesForPatching ($ projectRootPath );
239
284
$ dotEnvClean = $ files ['dot_env_clean ' ];
240
285
$ packageJsonConflict = $ files ['package_json_conflict ' ];
241
286
$ webpackEncoreAdded = $ files ['webpack_encore_added ' ];
@@ -393,7 +438,7 @@ public function getIntegrationTests(): iterable
393
438
* * original_recipe
394
439
* * updated_recipe.
395
440
*/
396
- private function getFilesForPatching (): array
441
+ private function getFilesForPatching (string $ projectPath = '' ): array
397
442
{
398
443
$ files = [
399
444
// .env
@@ -538,7 +583,7 @@ private function getFilesForPatching(): array
538
583
foreach ($ files as $ key => $ data ) {
539
584
$ files [$ key ] = array_merge (
540
585
$ data ,
541
- $ this ->generatePatchData ($ data ['filename ' ], $ data ['original_recipe ' ], $ data ['updated_recipe ' ])
586
+ $ this ->generatePatchData ($ projectPath . $ data ['filename ' ], $ data ['original_recipe ' ], $ data ['updated_recipe ' ])
542
587
);
543
588
}
544
589
0 commit comments