@@ -38,6 +38,18 @@ public function testGeneratePatch(array $originalFiles, array $newFiles, string
38
38
// original files need to be present to avoid patcher thinking they were deleting and skipping patch
39
39
foreach ($ originalFiles as $ file => $ contents ) {
40
40
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 ();
41
53
}
42
54
43
55
$ patcher = new RecipePatcher (FLEX_TEST_DIR , $ this ->createMock (IOInterface::class));
@@ -46,6 +58,11 @@ public function testGeneratePatch(array $originalFiles, array $newFiles, string
46
58
$ this ->assertSame ($ expectedPatch , rtrim ($ patch ->getPatch (), "\n" ));
47
59
$ this ->assertSame ($ expectedDeletedFiles , $ patch ->getDeletedFiles ());
48
60
61
+ // when testing ignored files the patch is empty
62
+ if ('' === $ expectedPatch ) {
63
+ return ;
64
+ }
65
+
49
66
// find all "index 7d30dc7.." in patch
50
67
$ matches = [];
51
68
preg_match_all ('/index\ ([0-9|a-z]+)\.\./ ' , $ patch ->getPatch (), $ matches );
@@ -158,6 +175,12 @@ public function getGeneratePatchTests(): iterable
158
175
,
159
176
['will_be_deleted.txt ' ],
160
177
];
178
+
179
+ yield 'ignored_file ' => [
180
+ ['file1.txt ' => 'Original contents ' , '.gitignore ' => 'file1.txt ' ],
181
+ ['file1.txt ' => 'Updated contents ' , '.gitignore ' => 'file1.txt ' ],
182
+ '' ,
183
+ ];
161
184
}
162
185
163
186
public function testGeneratePatchOnDeletedFile ()
0 commit comments