@@ -38,6 +38,18 @@ public function testGeneratePatch(array $originalFiles, array $newFiles, string
3838 // original files need to be present to avoid patcher thinking they were deleting and skipping patch
3939 foreach ($ originalFiles as $ file => $ contents ) {
4040 touch (FLEX_TEST_DIR .'/ ' .$ file );
41+ if ('.gitignore ' === $ file ) {
42+ file_put_contents (FLEX_TEST_DIR .'/ ' .$ file , $ contents );
43+ }
44+ }
45+
46+ // make sure the test directory is a git repo
47+ (new Process (['git ' , 'init ' ], FLEX_TEST_DIR ))->mustRun ();
48+ (new Process (['git ' , 'config ' , 'user.name ' , '"Flex Updater" ' ], FLEX_TEST_DIR ))->mustRun ();
49+ (new Process (['git ' , 'config ' , 'user.email ' , '"" ' ], FLEX_TEST_DIR ))->mustRun ();
50+ if (0 !== \count ($ originalFiles )) {
51+ (new Process (['git ' , 'add ' , '-A ' ], FLEX_TEST_DIR ))->mustRun ();
52+ (new Process (['git ' , 'commit ' , '-m ' , '"original files" ' ], FLEX_TEST_DIR ))->mustRun ();
4153 }
4254
4355 $ patcher = new RecipePatcher (FLEX_TEST_DIR , $ this ->createMock (IOInterface::class));
@@ -46,6 +58,11 @@ public function testGeneratePatch(array $originalFiles, array $newFiles, string
4658 $ this ->assertSame ($ expectedPatch , rtrim ($ patch ->getPatch (), "\n" ));
4759 $ this ->assertSame ($ expectedDeletedFiles , $ patch ->getDeletedFiles ());
4860
61+ // when testing ignored files the patch is empty
62+ if ('' === $ expectedPatch ) {
63+ return ;
64+ }
65+
4966 // find all "index 7d30dc7.." in patch
5067 $ matches = [];
5168 preg_match_all ('/index\ ([0-9|a-z]+)\.\./ ' , $ patch ->getPatch (), $ matches );
@@ -158,6 +175,12 @@ public function getGeneratePatchTests(): iterable
158175 ,
159176 ['will_be_deleted.txt ' ],
160177 ];
178+
179+ yield 'ignored_file ' => [
180+ ['file1.txt ' => 'Original contents ' , '.gitignore ' => 'file1.txt ' ],
181+ ['file1.txt ' => 'Updated contents ' , '.gitignore ' => 'file1.txt ' ],
182+ '' ,
183+ ];
161184 }
162185
163186 public function testGeneratePatchOnDeletedFile ()
0 commit comments