15
15
use PHPUnit \Framework \TestCase ;
16
16
use Symfony \Component \Filesystem \Filesystem ;
17
17
use Symfony \Component \Process \Process ;
18
+ use Symfony \Flex \Lock ;
18
19
use Symfony \Flex \Update \RecipePatch ;
19
20
use Symfony \Flex \Update \RecipePatcher ;
20
21
@@ -52,7 +53,7 @@ public function testGeneratePatch(array $originalFiles, array $newFiles, string
52
53
(new Process (['git ' , 'commit ' , '-m ' , '"original files" ' ], FLEX_TEST_DIR ))->mustRun ();
53
54
}
54
55
55
- $ patcher = new RecipePatcher (FLEX_TEST_DIR , $ this ->createMock (IOInterface::class));
56
+ $ patcher = new RecipePatcher (FLEX_TEST_DIR , $ this ->createMock (IOInterface::class), $ this -> createMock (Lock::class) );
56
57
57
58
$ patch = $ patcher ->generatePatch ($ originalFiles , $ newFiles );
58
59
$ this ->assertSame ($ expectedPatch , rtrim ($ patch ->getPatch (), "\n" ));
@@ -189,7 +190,7 @@ public function testGeneratePatchOnDeletedFile()
189
190
$ this ->getFilesystem ()->remove (FLEX_TEST_DIR );
190
191
$ this ->getFilesystem ()->mkdir (FLEX_TEST_DIR );
191
192
192
- $ patcher = new RecipePatcher (FLEX_TEST_DIR , $ this ->createMock (IOInterface::class));
193
+ $ patcher = new RecipePatcher (FLEX_TEST_DIR , $ this ->createMock (IOInterface::class), $ this -> createMock (Lock::class) );
193
194
194
195
// try to update a file that does not exist in the project
195
196
$ patch = $ patcher ->generatePatch (['.env ' => 'original contents ' ], ['.env ' => 'new contents ' ]);
@@ -217,7 +218,7 @@ public function testApplyPatch(array $filesCurrentlyInApp, RecipePatch $recipePa
217
218
(new Process (['git ' , 'commit ' , '-m ' , 'Committing original files ' ], FLEX_TEST_DIR ))->mustRun ();
218
219
}
219
220
220
- $ patcher = new RecipePatcher (FLEX_TEST_DIR , $ this ->createMock (IOInterface::class));
221
+ $ patcher = new RecipePatcher (FLEX_TEST_DIR , $ this ->createMock (IOInterface::class), $ this -> createMock (Lock::class) );
221
222
$ hadConflicts = !$ patcher ->applyPatch ($ recipePatch );
222
223
223
224
foreach ($ expectedFiles as $ file => $ expectedContents ) {
@@ -233,6 +234,38 @@ public function testApplyPatch(array $filesCurrentlyInApp, RecipePatch $recipePa
233
234
$ this ->assertSame ($ expectedConflicts , $ hadConflicts );
234
235
}
235
236
237
+ public function testApplyPatchFileOwnedByMultipleRecipes ()
238
+ {
239
+ (new Process (['git ' , 'init ' ], FLEX_TEST_DIR ))->mustRun ();
240
+ (new Process (['git ' , 'config ' , 'user.name ' , 'Unit test ' ], FLEX_TEST_DIR ))->mustRun ();
241
+ (new Process (['git ' , 'config ' , 'user.email ' , '' ], FLEX_TEST_DIR ))->mustRun ();
242
+
243
+ $ dir = FLEX_TEST_DIR .'/config/packages ' ;
244
+ @mkdir ($ dir , 0777 , true );
245
+ file_put_contents ($ dir .'/security.yaml ' , '# contents ' );
246
+ (new Process (['git ' , 'add ' , '-A ' ], FLEX_TEST_DIR ))->mustRun ();
247
+ (new Process (['git ' , 'commit ' , '-m ' , 'Committing original files ' ], FLEX_TEST_DIR ))->mustRun ();
248
+
249
+
250
+ $ lock = $ this ->createMock (Lock::class);
251
+ $ lock ->expects ($ this ->any ())->method ('all ' )->willReturn ([
252
+ 'symfony/security-bundle ' => ['files ' => ['config/packages/security.yaml ' ]],
253
+ 'symfony/security ' => ['files ' => ['config/packages/security.yaml ' ]],
254
+ ]);
255
+ $ patcher = new RecipePatcher (FLEX_TEST_DIR , $ this ->createMock (IOInterface::class), $ lock );
256
+
257
+ $ patchData = $ this ->generatePatchData ('config/packages/security.yaml ' , '# contents ' , null );
258
+ $ hadConflicts = !$ patcher ->applyPatch (new RecipePatch (
259
+ '' ,
260
+ [$ patchData ['hash ' ] => $ patchData ['blob ' ]],
261
+ ['config/packages/security.yaml ' ]
262
+ ), 'symfony/security-bundle ' );
263
+
264
+ $ this ->assertFileExists ($ dir .'/security.yaml ' );
265
+ $ this ->assertSame ('# contents ' , file_get_contents ($ dir .'/security.yaml ' ));
266
+ $ this ->assertFalse ($ hadConflicts );
267
+ }
268
+
236
269
/**
237
270
* @dataProvider getApplyPatchTests
238
271
*/
@@ -261,7 +294,7 @@ public function testApplyPatchOnSubfolder(array $filesCurrentlyInApp, RecipePatc
261
294
(new Process (['git ' , 'commit ' , '-m ' , 'Committing original files ' ], $ subProjectPath ))->mustRun ();
262
295
}
263
296
264
- $ patcher = new RecipePatcher ($ subProjectPath , $ this ->createMock (IOInterface::class));
297
+ $ patcher = new RecipePatcher ($ subProjectPath , $ this ->createMock (IOInterface::class), $ this -> createMock (Lock::class) );
265
298
$ hadConflicts = !$ patcher ->applyPatch ($ recipePatch );
266
299
267
300
foreach ($ expectedFiles as $ file => $ expectedContents ) {
@@ -390,7 +423,7 @@ public function testIntegration(bool $useNullForMissingFiles)
390
423
(new Process (['git ' , 'add ' , '-A ' ], FLEX_TEST_DIR ))->mustRun ();
391
424
(new Process (['git ' , 'commit ' , '-m ' , 'committing in app start files ' ], FLEX_TEST_DIR ))->mustRun ();
392
425
393
- $ patcher = new RecipePatcher (FLEX_TEST_DIR , $ this ->createMock (IOInterface::class));
426
+ $ patcher = new RecipePatcher (FLEX_TEST_DIR , $ this ->createMock (IOInterface::class), $ this -> createMock (Lock::class) );
394
427
$ originalFiles = [
395
428
'.env ' => $ files ['dot_env_clean ' ]['original_recipe ' ],
396
429
'package.json ' => $ files ['package_json_conflict ' ]['original_recipe ' ],
0 commit comments