88use Mockery \MockInterface ;
99use phpmock \functions \FixedValueFunction ;
1010use phpmock \MockBuilder ;
11+ use phpmock \phpunit \PHPMock ;
1112use PHPUnit \Framework \Attributes \DataProvider ;
1213use PHPUnit \Framework \Attributes \Group ;
1314use PHPUnit \Framework \Attributes \RunInSeparateProcess ;
1718use Stolt \LeanPackage \Archive ;
1819use Stolt \LeanPackage \Archive \Validator ;
1920use Stolt \LeanPackage \Commands \ValidateCommand ;
21+ use Stolt \LeanPackage \Exceptions \GitattributesCreationFailed ;
2022use Stolt \LeanPackage \Exceptions \InvalidGlobPattern ;
2123use Stolt \LeanPackage \Exceptions \NoLicenseFilePresent ;
24+ use Stolt \LeanPackage \GitattributesFileRepository ;
2225use Stolt \LeanPackage \Helpers \Str as OsHelper ;
2326use Stolt \LeanPackage \Presets \Finder ;
2427use Stolt \LeanPackage \Presets \PhpPreset ;
3336class ValidateCommandTest extends TestCase
3437{
3538 use InteractsWithConsole;
39+ use PHPMock;
3640
3741 /**
3842 * Set up a test environment.
@@ -795,8 +799,8 @@ public function failingGitattributesFilesCreationReturnsExpectedStatusCode(): vo
795799
796800 $ builder = new MockBuilder ();
797801 $ builder ->setNamespace ('Stolt\LeanPackage ' )
798- ->setName ('file_put_contents ' )
799- ->setFunctionProvider (new FixedValueFunction (false ));
802+ ->setName ('file_put_contents ' )
803+ ->setFunctionProvider (new FixedValueFunction (false ));
800804
801805 $ mock = $ builder ->build ();
802806 $ mock ->enable ();
@@ -811,14 +815,14 @@ public function failingGitattributesFilesCreationReturnsExpectedStatusCode(): vo
811815
812816 $ expectedDisplay = <<<CONTENT
813817The --create option is deprecated. Please use the dedicated create command.
814- Warning: There is no .gitattributes file present in { $ this -> temporaryDirectory } .
818+
815819
816820Creation of .gitattributes file failed.
817821
818822CONTENT ;
819823
820824 $ this ->assertSame ($ expectedDisplay , $ commandTester ->getDisplay ());
821- $ this ->assertTrue ( $ commandTester ->getStatusCode () > Command:: SUCCESS );
825+ $ this ->assertSame (Command:: FAILURE , $ commandTester ->getStatusCode ());
822826
823827 $ mock ->disable ();
824828 }
@@ -842,21 +846,8 @@ public function validateOnNonExistentGitattributesFilesWithCreationOptionCreates
842846 '--omit-header ' => true
843847 ]);
844848
845- $ expectedDisplay = <<<CONTENT
846- The --create option is deprecated. Please use the dedicated create command.
847- Warning: There is no .gitattributes file present in {$ this ->temporaryDirectory }.
848-
849- Created a .gitattributes file with the shown content:
850- * text=auto eol=lf
851-
852- .gitattributes export-ignore
853- CONDUCT.md export-ignore
854- specs/ export-ignore
855-
856-
857- CONTENT ;
858-
859- $ this ->assertEquals ($ expectedDisplay , $ commandTester ->getDisplay ());
849+ $ this ->assertStringNotContainsString (GitattributesFileRepository::GENERATED_HEADER , $ commandTester ->getDisplay ());
850+ $ this ->assertStringNotContainsString (GitattributesFileRepository::MODIFIED_HEADER , $ commandTester ->getDisplay ());
860851 $ commandTester ->assertCommandIsSuccessful ();
861852 $ this ->assertFileExists (
862853 WORKING_DIRECTORY . DIRECTORY_SEPARATOR . '.gitattributes '
@@ -875,29 +866,17 @@ public function validateOnNonExistentGitattributesFilesWithCreationOptionCreates
875866
876867 $ command = $ this ->application ->find ('validate ' );
877868 $ commandTester = new CommandTester ($ command );
869+
870+ $ this ->assertFileDoesNotExist (
871+ WORKING_DIRECTORY . DIRECTORY_SEPARATOR . '.gitattributes '
872+ );
873+
878874 $ commandTester ->execute ([
879875 'command ' => $ command ->getName (),
880876 'directory ' => WORKING_DIRECTORY ,
881877 '--create ' => true ,
882878 ]);
883879
884- $ expectedDisplay = <<<CONTENT
885- The --create option is deprecated. Please use the dedicated create command.
886- Warning: There is no .gitattributes file present in {$ this ->temporaryDirectory }.
887-
888- Created a .gitattributes file with the shown content:
889- # This file was generated by the lean package validator (http://git.io/lean-package-validator).
890-
891- * text=auto eol=lf
892-
893- .gitattributes export-ignore
894- CONDUCT.md export-ignore
895- specs/ export-ignore
896-
897-
898- CONTENT ;
899-
900- $ this ->assertEquals ($ expectedDisplay , $ commandTester ->getDisplay ());
901880 $ commandTester ->assertCommandIsSuccessful ();
902881 $ this ->assertFileExists (
903882 WORKING_DIRECTORY . DIRECTORY_SEPARATOR . '.gitattributes '
@@ -929,7 +908,6 @@ public function validateOnNonExistentGitattributesFilesWithCreationOptionCreates
929908
930909 $ expectedDisplay = <<<CONTENT
931910The --create option is deprecated. Please use the dedicated create command.
932- Warning: There is no .gitattributes file present in {$ this ->temporaryDirectory }.
933911
934912Created a .gitattributes file with the shown content:
935913# This file was generated by the lean package validator (http://git.io/lean-package-validator).
@@ -940,25 +918,18 @@ public function validateOnNonExistentGitattributesFilesWithCreationOptionCreates
940918CONDUCT.md export-ignore
941919specs/ export-ignore
942920
943-
944921CONTENT ;
945922
946- $ expectedGitattributesContent = <<<CONTENT
947- # This file was generated by the lean package validator (http://git.io/lean-package-validator).
948-
949- * text=auto eol=lf
950-
923+ $ expectedGitattributesExportIgnores = <<<CONTENT
951924.gitattributes export-ignore
952925CONDUCT.md export-ignore
953926specs/ export-ignore
954-
955927CONTENT ;
956928
957- $ this ->assertEquals ( $ expectedDisplay , $ commandTester ->getDisplay ());
929+ $ this ->assertStringContainsString ( $ expectedGitattributesExportIgnores , $ commandTester ->getDisplay ());
958930 $ commandTester ->assertCommandIsSuccessful ();
959- $ this ->assertStringEqualsFile (
960- WORKING_DIRECTORY . DIRECTORY_SEPARATOR . '.gitattributes ' ,
961- $ expectedGitattributesContent
931+ $ this ->assertFileExists (
932+ WORKING_DIRECTORY . DIRECTORY_SEPARATOR . '.gitattributes '
962933 );
963934 }
964935
@@ -1608,7 +1579,7 @@ public function incompleteGitattributesFileIsOverwritten(string $option): void
16081579version-increase-command export-ignore
16091580CONTENT ;
16101581
1611- $ this ->createTemporaryGitattributesFile ($ gitattributesContent );
1582+ $ this ->assertTrue ( $ this -> createTemporaryGitattributesFile ($ gitattributesContent) );
16121583
16131584 $ artifactFilenames = ['phpspec.yml.dist ' , 'version-increase-command ' ];
16141585
@@ -1617,6 +1588,16 @@ public function incompleteGitattributesFileIsOverwritten(string $option): void
16171588 ['specs ' ]
16181589 );
16191590
1591+ $ header = GitattributesFileRepository::GENERATED_HEADER . PHP_EOL . PHP_EOL ;
1592+
1593+ if ($ option === '--overwrite ' ) {
1594+ $ header = GitattributesFileRepository::MODIFIED_HEADER . PHP_EOL ;
1595+ }
1596+
1597+ if ($ option === '--create ' ) {
1598+ $ header = GitattributesFileRepository::MODIFIED_HEADER . PHP_EOL . PHP_EOL ;
1599+ }
1600+
16201601 $ command = $ this ->application ->find ('validate ' );
16211602 $ commandTester = new CommandTester ($ command );
16221603 $ commandTester ->execute ([
@@ -1633,6 +1614,7 @@ public function incompleteGitattributesFileIsOverwritten(string $option): void
16331614The present .gitattributes file is considered invalid.
16341615
16351616Overwrote it with the shown content:
1617+ $ header
16361618* text=auto eol=lf
16371619
16381620.gitattributes export-ignore
0 commit comments