1717use Stolt \LeanPackage \Archive ;
1818use Stolt \LeanPackage \Archive \Validator ;
1919use Stolt \LeanPackage \Commands \ValidateCommand ;
20+ use Stolt \LeanPackage \Exceptions \InvalidGlobPattern ;
2021use Stolt \LeanPackage \Exceptions \NoLicenseFilePresent ;
2122use Stolt \LeanPackage \Helpers \Str as OsHelper ;
2223use Stolt \LeanPackage \Presets \Finder ;
@@ -34,7 +35,7 @@ class ValidateCommandTest extends TestCase
3435 use InteractsWithConsole;
3536
3637 /**
37- * Set up test environment.
38+ * Set up a test environment.
3839 */
3940 protected function setUp (): void
4041 {
@@ -53,7 +54,7 @@ protected function setUp(): void
5354 }
5455
5556 /**
56- * Tear down test environment.
57+ * Tear down the test environment.
5758 *
5859 * @return void
5960 */
@@ -195,9 +196,10 @@ public function showsDifferenceBetweenActualAndExpectedGitattributesContent(): v
195196 #[Test]
196197 public function filesInGlobalGitignoreAreExportIgnored (): void
197198 {
198- $ analyserMock = Mockery::mock (Analyser::class)->makePartial ();
199-
200199 $ globPattern = '{ ' . \implode (', ' , (new PhpPreset ())->getPresetGlob ()) . '}* ' ;
200+
201+ $ analyserMock = Mockery::mock (Analyser::class, [new Finder (new PhpPreset ())])->makePartial ();
202+
201203 $ analyserMock ->setGlobPattern ($ globPattern );
202204
203205 $ application = $ this ->getApplicationWithMockedAnalyser ($ analyserMock );
@@ -265,7 +267,7 @@ public function filesInGlobalGitignoreAreExportIgnored(): void
265267 #[Ticket('https://github.com/raphaelstolt/lean-package-validator/issues/16 ' )]
266268 public function gitattributesFileWithNoExportIgnoresContentShowsExpectedContent (): void
267269 {
268- $ analyserMock = Mockery::mock (Analyser::class)->makePartial ();
270+ $ analyserMock = Mockery::mock (Analyser::class, [ new Finder ( new PhpPreset ())] )->makePartial ();
269271
270272 $ globPattern = '{ ' . \implode (', ' , (new PhpPreset ())->getPresetGlob ()) . '}* ' ;
271273 $ analyserMock ->setGlobPattern ($ globPattern );
@@ -1302,10 +1304,13 @@ public function nonLeanArchiveIsNotConsideredLeanSingular(): void
13021304 $ this ->assertTrue ($ commandTester ->getStatusCode () > Command::SUCCESS );
13031305 }
13041306
1307+ /**
1308+ * @throws InvalidGlobPattern
1309+ */
13051310 #[Test]
13061311 public function impossibilityToResolveExpectedGitattributesFileContentIsInfoed (): void
13071312 {
1308- $ mock = Mockery::mock (Analyser::class)->makePartial ();
1313+ $ mock = Mockery::mock (Analyser::class, [ new Finder ( new PhpPreset ())] )->makePartial ();
13091314
13101315 $ globPattern = '{ ' . \implode (', ' , (new PhpPreset ())->getPresetGlob ()) . '}* ' ;
13111316 $ mock ->setGlobPattern ($ globPattern );
@@ -2283,6 +2288,51 @@ public function detectsValidGitattributeContentInStdinInput(): void
22832288 ->assertSuccessful ();
22842289 }
22852290
2291+ #[Test]
2292+ #[RunInSeparateProcess]
2293+ public function usesTheRustPresetIfRequested (): void
2294+ {
2295+ $ artifactFilenames = [
2296+ 'CODE_OF_CONDUCT.md ' ,
2297+ '.rustfmt.toml ' ,
2298+ '.clippy.toml ' ,
2299+ 'LICENSE.md ' ,
2300+ ];
2301+
2302+ $ this ->createTemporaryFiles (
2303+ $ artifactFilenames ,
2304+ ['src ' ]
2305+ );
2306+
2307+ $ gitattributesContent = <<<CONTENT
2308+ * text=auto eol=lf
2309+
2310+ .clippy.toml export-ignore
2311+ .gitattributes export-ignore
2312+ .rustfmt.toml export-ignore
2313+ CODE_OF_CONDUCT.md export-ignore
2314+ LICENSE.md export-ignore
2315+ CONTENT ;
2316+
2317+ $ expectedDisplay = <<<CONTENT
2318+ The present .gitattributes file is considered valid.
2319+
2320+ CONTENT ;
2321+
2322+ $ this ->createTemporaryGitattributesFile ($ gitattributesContent );
2323+
2324+ $ command = $ this ->application ->find ('validate ' );
2325+ $ commandTester = new CommandTester ($ command );
2326+ $ commandTester ->execute ([
2327+ 'command ' => $ command ->getName (),
2328+ 'directory ' => WORKING_DIRECTORY ,
2329+ '--preset ' => 'Rust ' ,
2330+ ]);
2331+
2332+ $ this ->assertSame ($ expectedDisplay , $ commandTester ->getDisplay ());
2333+ $ commandTester ->assertCommandIsSuccessful ();
2334+ }
2335+
22862336 /**
22872337 * @return array
22882338 */
0 commit comments