@@ -174,6 +174,19 @@ public function getGeneratePatchTests(): iterable
174
174
];
175
175
}
176
176
177
+ public function testGeneratePatchOnDeletedFile ()
178
+ {
179
+ // make sure the target directory is empty
180
+ $ this ->getFilesystem ()->remove (FLEX_TEST_DIR );
181
+ $ this ->getFilesystem ()->mkdir (FLEX_TEST_DIR );
182
+
183
+ $ patcher = new RecipePatcher (FLEX_TEST_DIR , $ this ->createMock (IOInterface::class));
184
+
185
+ // try to update a file that does not exist in the project
186
+ $ patch = $ patcher ->generatePatch (['.env ' => 'original contents ' ], ['.env ' => 'new contents ' ]);
187
+ $ this ->assertSame ('' , $ patch ->getPatch ());
188
+ }
189
+
177
190
/**
178
191
* @dataProvider getApplyPatchTests
179
192
*/
@@ -294,11 +307,30 @@ public function testIntegration(bool $useNullForMissingFiles)
294
307
$ files = $ this ->getFilesForPatching ();
295
308
(new Process (['git ' , 'init ' ], FLEX_TEST_DIR ))->mustRun ();
296
309
310
+ $ startingFiles = [
311
+ '.env ' => $ files ['dot_env_clean ' ]['in_app ' ],
312
+ 'package.json ' => $ files ['package_json_conflict ' ]['in_app ' ],
313
+ // no webpack_encore.yaml in app
314
+ 'config/packages/security.yaml ' => $ files ['security_removed ' ]['in_app ' ],
315
+ // no cache.yaml in app - the update patch will be skipped
316
+ ];
317
+ foreach ($ startingFiles as $ file => $ contents ) {
318
+ if (!file_exists (dirname (FLEX_TEST_DIR .'/ ' .$ file ))) {
319
+ @mkdir (dirname (FLEX_TEST_DIR .'/ ' .$ file ), 0777 , true );
320
+ }
321
+
322
+ file_put_contents (FLEX_TEST_DIR .'/ ' .$ file , $ contents );
323
+ }
324
+ // commit the files in the app
325
+ (new Process (['git ' , 'add ' , '-A ' ], FLEX_TEST_DIR ))->mustRun ();
326
+ (new Process (['git ' , 'commit ' , '-m ' , 'committing in app start files ' ], FLEX_TEST_DIR ))->mustRun ();
327
+
297
328
$ patcher = new RecipePatcher (FLEX_TEST_DIR , $ this ->createMock (IOInterface::class));
298
329
$ originalFiles = [
299
330
'.env ' => $ files ['dot_env_clean ' ]['original_recipe ' ],
300
331
'package.json ' => $ files ['package_json_conflict ' ]['original_recipe ' ],
301
332
'config/packages/security.yaml ' => $ files ['security_removed ' ]['original_recipe ' ],
333
+ 'config/packages/cache.yaml ' => 'original cache.yaml ' ,
302
334
];
303
335
if ($ useNullForMissingFiles ) {
304
336
$ originalFiles ['config/packages/webpack_encore.yaml ' ] = null ;
@@ -307,31 +339,16 @@ public function testIntegration(bool $useNullForMissingFiles)
307
339
$ updatedFiles = [
308
340
'.env ' => $ files ['dot_env_clean ' ]['updated_recipe ' ],
309
341
'package.json ' => $ files ['package_json_conflict ' ]['updated_recipe ' ],
310
- 'config/packages/webpack_encore.yaml ' => $ files ['webpack_encore_added ' ]['updated_recipe ' ]
342
+ 'config/packages/webpack_encore.yaml ' => $ files ['webpack_encore_added ' ]['updated_recipe ' ],
343
+ 'config/packages/cache.yaml ' => 'updated cache.yaml ' ,
311
344
];
312
345
if ($ useNullForMissingFiles ) {
313
346
$ updatedFiles ['config/packages/security.yaml ' ] = null ;
314
347
}
315
- $ recipePatch = $ patcher ->generatePatch ($ originalFiles , $ updatedFiles );
316
-
317
- $ startingFiles = [
318
- '.env ' => $ files ['dot_env_clean ' ]['in_app ' ],
319
- 'package.json ' => $ files ['package_json_conflict ' ]['in_app ' ],
320
- // no webpack_encore.yaml in app
321
- 'config/packages/security.yaml ' => $ files ['security_removed ' ]['in_app ' ],
322
- ];
323
- foreach ($ startingFiles as $ file => $ contents ) {
324
- if (!file_exists (dirname (FLEX_TEST_DIR .'/ ' .$ file ))) {
325
- @mkdir (dirname (FLEX_TEST_DIR .'/ ' .$ file ), 0777 , true );
326
- }
327
-
328
- file_put_contents (FLEX_TEST_DIR .'/ ' .$ file , $ contents );
329
- }
330
- // commit the files in the app
331
- (new Process (['git ' , 'add ' , '-A ' ], FLEX_TEST_DIR ))->mustRun ();
332
- (new Process (['git ' , 'commit ' , '-m ' , 'committing in app start files ' ], FLEX_TEST_DIR ))->mustRun ();
333
348
349
+ $ recipePatch = $ patcher ->generatePatch ($ originalFiles , $ updatedFiles );
334
350
$ appliedCleanly = $ patcher ->applyPatch ($ recipePatch );
351
+
335
352
$ this ->assertFalse ($ appliedCleanly );
336
353
$ this ->assertSame ($ files ['dot_env_clean ' ]['expected ' ], file_get_contents (FLEX_TEST_DIR .'/.env ' ));
337
354
$ this ->assertSame ($ files ['package_json_conflict ' ]['expected ' ], file_get_contents (FLEX_TEST_DIR .'/package.json ' ));
0 commit comments