Skip to content

Commit d248ebc

Browse files
theofidrynjutn95
andauthored
fix: Allow to use the default value for the output directory (#801)
Co-authored-by: njutn95 <njutn95@yahoo.com>
1 parent 606b0fe commit d248ebc

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/Console/Command/AddPrefixCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public function getConfiguration(): CommandConfiguration
9393
'o',
9494
InputOption::VALUE_REQUIRED,
9595
'The output directory in which the prefixed code will be dumped.',
96+
''
9697
),
9798
new InputOption(
9899
self::FORCE_OPT,

tests/Console/Command/AddPrefixCommandTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,66 @@ public function test_can_scope_projects_with_invalid_files(): void
596596
->shouldHaveBeenCalledTimes(count($expectedFiles));
597597
}
598598

599+
public function test_it_outputs_in_the_build_directory_if_no_output_dir_is_given(): void
600+
{
601+
$input = [
602+
'add-prefix',
603+
'--prefix' => 'MyPrefix',
604+
'paths' => [
605+
$root = self::FIXTURE_PATH.'/set002/original',
606+
],
607+
'--no-interaction',
608+
'--no-config' => null,
609+
];
610+
611+
$outDir = 'build';
612+
613+
$this->fileSystemProphecy->isAbsolutePath($outDir)->willReturn(false);
614+
$this->fileSystemProphecy->isAbsolutePath(Argument::cetera())->willReturn(true);
615+
616+
$this->fileSystemProphecy->mkdir($this->tmp.DIRECTORY_SEPARATOR.$outDir)->shouldBeCalled();
617+
$this->fileSystemProphecy->exists(Argument::cetera())->willReturn(false);
618+
$this->fileSystemProphecy->remove(Argument::cetera())->shouldNotBeCalled();
619+
620+
$expectedFiles = [
621+
'composer/installed.json' => 'f1',
622+
'executable-file.php' => 'f5',
623+
'file.php' => 'f2',
624+
'invalid-file.php' => 'f3',
625+
'scoper.inc.php' => 'f4',
626+
];
627+
628+
$root = realpath($root);
629+
630+
$this->fileSystemProphecy
631+
->chmod(
632+
$this->tmp.DIRECTORY_SEPARATOR.$outDir.'/executable-file.php',
633+
493,
634+
)
635+
->shouldBeCalled();
636+
637+
foreach ($expectedFiles as $expectedFile => $prefixedContents) {
638+
$inputPath = escape_path($root.'/'.$expectedFile);
639+
$outputPath = escape_path($this->tmp.DIRECTORY_SEPARATOR.$outDir.'/'.$expectedFile);
640+
641+
$inputContents = file_get_contents($inputPath);
642+
643+
$this->scoperProphecy
644+
->scope($inputPath, $inputContents)
645+
->willReturn($prefixedContents);
646+
647+
$this->fileSystemProphecy->dumpFile($outputPath, $prefixedContents)->shouldBeCalled();
648+
}
649+
650+
$this->appTester->run($input);
651+
652+
self::assertSame(0, $this->appTester->getStatusCode());
653+
654+
$this->scoperProphecy
655+
->scope(Argument::cetera())
656+
->shouldHaveBeenCalledTimes(count($expectedFiles));
657+
}
658+
599659
private function createAppTester(): ApplicationTester
600660
{
601661
/** @var Filesystem $fileSystem */

0 commit comments

Comments
 (0)