@@ -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