diff --git a/app/Domain/PackageAnalyser.php b/app/Domain/PackageAnalyser.php index 18e4bb0..6f64459 100644 --- a/app/Domain/PackageAnalyser.php +++ b/app/Domain/PackageAnalyser.php @@ -336,13 +336,13 @@ private function checkCliBinaryDirectoryExistence(): ViolationStatus if ($this->isACliOrTui) { $finder = new Finder(); - if ($finder->depth(1)->path('bin')->in($this->directoryToAnalyse)->hasResults()) { + if ($finder->depth(0)->path('bin')->in($this->directoryToAnalyse)->hasResults()) { $this->alternateStepStatus('cli-binary', ViolationStatus::True); return ViolationStatus::True; } - $this->alternateStepStatus('cli-binary', ViolationStatus::True); + $this->alternateStepStatus('cli-binary', ViolationStatus::False); return ViolationStatus::False; } diff --git a/tests/Feature/AnalyseCommandTest.php b/tests/Feature/AnalyseCommandTest.php index ee65b23..3f27427 100644 --- a/tests/Feature/AnalyseCommandTest.php +++ b/tests/Feature/AnalyseCommandTest.php @@ -18,8 +18,47 @@ $this->artisan('analyse '.$this->temporaryDirectory)->expectsOutputToContain('Ran 16 analysis steps'); }); -it('has violations in output', function () { +it('has success emoji for successful analyse step', function () { + $this->artisan('analyse '.$this->temporaryDirectory)->expectsOutputToContain(' ✅'); +}); + +it('has violations in output and fails', function () { $this->artisan('analyse '.$this->temporaryDirectory)->expectsOutputToContain('optimiseable aspects')->assertExitCode( Command::FAILURE ); }); + +it('can alternate command failure state', function () { + $this->artisan('analyse '.$this->temporaryDirectory.' --violations-threshold=16')->assertExitCode(Command::SUCCESS); +}); + +it('writes a HTML report if desired', function () { + $this->artisan('analyse '.$this->temporaryDirectory.' --write-report')->expectsOutputToContain('Writing package analysis report to'); +}); + +it('has its expected options', function () { + $this->artisan('analyse --help')->expectsOutputToContain('--write-report', '--violations-threshold[=VIOLATIONS-THRESHOLD]'); +}); + +it('succeeds for failureless analysis', function () { + \touch($this->temporaryDirectory.DIRECTORY_SEPARATOR.'.gitignore'); + \touch($this->temporaryDirectory.DIRECTORY_SEPARATOR.'.gitattributes'); + \touch($this->temporaryDirectory.DIRECTORY_SEPARATOR.'.gitlab-ci.yml'); + + \exec('cd '.$this->temporaryDirectory.' && touch foo.txt && git add foo.txt && git commit -m "Foo" && git tag v1.0.0 2>&1'); + + if (! file_exists($this->temporaryDirectory.DIRECTORY_SEPARATOR.'src')) { + \mkdir($this->temporaryDirectory.DIRECTORY_SEPARATOR.'src'); + } + + if (! file_exists($this->temporaryDirectory.DIRECTORY_SEPARATOR.'bin')) { + \mkdir($this->temporaryDirectory.DIRECTORY_SEPARATOR.'bin'); + } + + \touch($this->temporaryDirectory.DIRECTORY_SEPARATOR.'box.json'); + \touch($this->temporaryDirectory.DIRECTORY_SEPARATOR.'CHANGELOG.md'); + \touch($this->temporaryDirectory.DIRECTORY_SEPARATOR.'README.md'); + \touch($this->temporaryDirectory.DIRECTORY_SEPARATOR.'LICENSE.md'); + + $this->artisan('analyse '.$this->temporaryDirectory)->assertExitCode(Command::SUCCESS); +})->only(); diff --git a/tests/Unit/PackageAnalyserTest.php b/tests/Unit/PackageAnalyserTest.php index ee76094..881801a 100644 --- a/tests/Unit/PackageAnalyserTest.php +++ b/tests/Unit/PackageAnalyserTest.php @@ -10,7 +10,7 @@ new PackageAnalyser($nonExistentPackageDirectory); })->throws(NonExistentPackageDirectory::class, sprintf("Provided package directory '%s' does not exist", '/tmp/non-existent-package-directory')); -test('violations have status ViolationStatus::False', function () { +test('violations have default status ViolationStatus::False', function () { $packageAnalyser = new PackageAnalyser('/tmp'); $violations = $packageAnalyser->getViolations(); foreach ($violations as $violation) {