@@ -190,6 +190,84 @@ public function testUpdate()
190190 $ this ->assertSame ($ newRecipeFiles , $ recipeUpdate ->getNewFiles ());
191191 }
192192
193+ public function testUpdateResolveDirectories ()
194+ {
195+ $ configurator = $ this ->createConfigurator ();
196+
197+ $ lock = $ this ->createMock (Lock::class);
198+ $ lock ->expects ($ this ->once ())
199+ ->method ('add ' )
200+ ->with (
201+ 'test-package ' ,
202+ [
203+ 'files ' => [
204+ 'config/packages/framework.yaml ' ,
205+ 'test.yaml ' ,
206+ ],
207+ ]
208+ );
209+
210+ $ originalRecipeFiles = [
211+ 'symfony8config/packages/framework.yaml ' => 'before ' ,
212+ 'root/test.yaml ' => 'before ' ,
213+ ];
214+ $ newRecipeFiles = [
215+ 'symfony8config/packages/framework.yaml ' => 'after ' ,
216+ 'root/test.yaml ' => 'after ' ,
217+ ];
218+
219+ $ originalRecipeFileData = [];
220+ foreach ($ originalRecipeFiles as $ file => $ contents ) {
221+ $ originalRecipeFileData [$ file ] = ['contents ' => $ contents , 'executable ' => false ];
222+ }
223+
224+ $ newRecipeFileData = [];
225+ foreach ($ newRecipeFiles as $ file => $ contents ) {
226+ $ newRecipeFileData [$ file ] = ['contents ' => $ contents , 'executable ' => false ];
227+ }
228+
229+ $ originalRecipe = $ this ->createMock (Recipe::class);
230+ $ originalRecipe ->method ('getName ' )
231+ ->willReturn ('test-package ' );
232+ $ originalRecipe ->method ('getFiles ' )
233+ ->willReturn ($ originalRecipeFileData );
234+
235+ $ newRecipe = $ this ->createMock (Recipe::class);
236+ $ newRecipe ->method ('getFiles ' )
237+ ->willReturn ($ newRecipeFileData );
238+
239+ $ recipeUpdate = new RecipeUpdate (
240+ $ originalRecipe ,
241+ $ newRecipe ,
242+ $ lock ,
243+ FLEX_TEST_DIR
244+ );
245+
246+ $ configurator ->update (
247+ $ recipeUpdate ,
248+ [
249+ 'root/ ' => '' ,
250+ 'symfony8config/ ' => '%CONFIG_DIR%/ ' ,
251+ ],
252+ [
253+ 'root/ ' => '' ,
254+ 'symfony8config/ ' => '%CONFIG_DIR%/ ' ,
255+ ]
256+ );
257+
258+ // Due to root/ => '', we expect that root/ has been stripped
259+ $ this ->assertArrayHasKey ('test.yaml ' , $ recipeUpdate ->getOriginalFiles ());
260+ $ this ->assertArrayHasKey ('test.yaml ' , $ recipeUpdate ->getNewFiles ());
261+
262+ $ this ->assertSame ('after ' , $ recipeUpdate ->getNewFiles ()['test.yaml ' ]);
263+
264+ // %CONFIG-DIR%, got resolved to config/packages back
265+ $ this ->assertArrayHasKey ('config/packages/framework.yaml ' , $ recipeUpdate ->getOriginalFiles ());
266+ $ this ->assertArrayHasKey ('config/packages/framework.yaml ' , $ recipeUpdate ->getNewFiles ());
267+
268+ $ this ->assertSame ('after ' , $ recipeUpdate ->getNewFiles ()['config/packages/framework.yaml ' ]);
269+ }
270+
193271 protected function setUp (): void
194272 {
195273 parent ::setUp ();
@@ -223,7 +301,7 @@ protected function tearDown(): void
223301
224302 private function createConfigurator (): CopyFromRecipeConfigurator
225303 {
226- return new CopyFromRecipeConfigurator ($ this ->getMockBuilder (Composer::class)->getMock (), $ this ->io , new Options (['root-dir ' => FLEX_TEST_DIR ], $ this ->io ));
304+ return new CopyFromRecipeConfigurator ($ this ->getMockBuilder (Composer::class)->getMock (), $ this ->io , new Options (['root-dir ' => FLEX_TEST_DIR , ' config-dir ' => ' config ' ], $ this ->io ));
227305 }
228306
229307 private function cleanUpTargetFiles ()
0 commit comments