Skip to content

Commit 42c2aa3

Browse files
committed
fix: add test
1 parent e9f3010 commit 42c2aa3

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

tests/Configurator/CopyFromRecipeConfiguratorTest.php

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,76 @@ 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+
193263
protected function setUp(): void
194264
{
195265
parent::setUp();
@@ -223,7 +293,7 @@ protected function tearDown(): void
223293

224294
private function createConfigurator(): CopyFromRecipeConfigurator
225295
{
226-
return new CopyFromRecipeConfigurator($this->getMockBuilder(Composer::class)->getMock(), $this->io, new Options(['root-dir' => FLEX_TEST_DIR], $this->io));
296+
return new CopyFromRecipeConfigurator($this->getMockBuilder(Composer::class)->getMock(), $this->io, new Options(['root-dir' => FLEX_TEST_DIR, 'config-dir' => 'config'], $this->io));
227297
}
228298

229299
private function cleanUpTargetFiles()

0 commit comments

Comments
 (0)