Skip to content

Commit cdf1300

Browse files
committed
fix: add test
1 parent e9f3010 commit cdf1300

File tree

2 files changed

+81
-3
lines changed

2 files changed

+81
-3
lines changed

tests/Configurator/CopyFromRecipeConfiguratorTest.php

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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()

tests/FlexTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public function testInstallWithPackageJsonToSynchronizeSkipped()
322322

323323
$this->assertStringContainsString(
324324
'Skip synchronizing package.json with PHP packages',
325-
$io->getOutput(),
325+
$io->getOutput()
326326
);
327327
}
328328

@@ -339,7 +339,7 @@ public function testInstallWithoutPackageJsonToSynchronizeSkipped(array $extra)
339339

340340
$this->assertStringNotContainsString(
341341
'Skip synchronizing package.json with PHP packages',
342-
$io->getOutput(),
342+
$io->getOutput()
343343
);
344344
}
345345

0 commit comments

Comments
 (0)