diff --git a/composer.json b/composer.json index 24559da5..98bc3522 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "nunomaduro/collision": "^7.0.5", "nunomaduro/termwind": "^1.15.1", "pestphp/pest-plugin": "^2.0.0", - "phpunit/phpunit": "^10.0.11" + "phpunit/phpunit": "^10.0.12" }, "conflict": { "brianium/paratest": "<7.0.6" @@ -71,7 +71,7 @@ "test:types": "phpstan analyse --ansi --memory-limit=-1 --debug", "test:unit": "php bin/pest --colors=always --exclude-group=integration --compact", "test:inline": "php bin/pest --colors=always --configuration=phpunit.inline.xml", - "test:parallel": "php bin/pest --colors=always --exclude-group=integration --parallel", + "test:parallel": "php bin/pest --colors=always --exclude-group=integration --parallel --processes=10", "test:integration": "php bin/pest --colors=always --group=integration -v", "update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always", "test": [ diff --git a/overrides/Runner/ResultCache/DefaultResultCache.php b/overrides/Runner/ResultCache/DefaultResultCache.php index d3cc22ff..640c3971 100644 --- a/overrides/Runner/ResultCache/DefaultResultCache.php +++ b/overrides/Runner/ResultCache/DefaultResultCache.php @@ -79,6 +79,11 @@ final class DefaultResultCache implements ResultCache */ private array $defects = []; + /** + * @psalm-var array + */ + private array $currentDefects = []; + /** * @psalm-var array */ @@ -96,6 +101,7 @@ final class DefaultResultCache implements ResultCache public function setStatus(string $id, TestStatus $status): void { if ($status->isFailure() || $status->isError()) { + $this->currentDefects[$id] = $status; $this->defects[$id] = $status; } } @@ -107,6 +113,10 @@ final class DefaultResultCache implements ResultCache public function setTime(string $id, float $time): void { + if (! isset($this->currentDefects[$id])) { + unset($this->defects[$id]); + } + $this->times[$id] = $time; } diff --git a/src/Plugins/Init.php b/src/Plugins/Init.php index 641012e6..ac1c8ba2 100644 --- a/src/Plugins/Init.php +++ b/src/Plugins/Init.php @@ -4,11 +4,13 @@ declare(strict_types=1); namespace Pest\Plugins; +use Composer\InstalledVersions; use Pest\Console\Thanks; use Pest\Contracts\Plugins\HandlesArguments; use Pest\Support\View; use Pest\TestSuite; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Process\Process; /** * @internal @@ -26,7 +28,9 @@ final class Init implements HandlesArguments private const STUBS = [ 'phpunit.xml' => 'phpunit.xml', 'Pest.php' => 'tests/Pest.php', - 'ExampleTest.php' => 'tests/ExampleTest.php', + 'TestCase.php' => 'tests/TestCase.php', + 'Unit/ExampleTest.php' => 'tests/Unit/ExampleTest.php', + 'Feature/ExampleTest.php' => 'tests/Feature/ExampleTest.php', ]; /** @@ -59,16 +63,19 @@ final class Init implements HandlesArguments private function init(): void { + if ($this->isLaravelInstalled()) { + exit($this->initLaravel()); + } + $testsBaseDir = "{$this->testSuite->rootPath}/tests"; if (! is_dir($testsBaseDir)) { mkdir($testsBaseDir); } - $this->output->writeln([ - '', - ' INFO Preparing tests directory.', - '', + View::render('components.badge', [ + 'type' => 'INFO', + 'content' => 'Preparing tests directory.', ]); foreach (self::STUBS as $from => $to) { @@ -98,4 +105,43 @@ final class Init implements HandlesArguments exit(0); } + + private function initLaravel(): int + { + $command = [ + 'composer', 'require', + 'pestphp/pest-plugin-laravel 2.x-dev', + '--dev', + ]; + + $result = (new Process($command, $this->testSuite->rootPath, ['COMPOSER_MEMORY_LIMIT' => '-1'])) + ->setTimeout(null) + ->run(function ($type, $output): void { + $this->output->write($output); + }); + + if ($result > 0) { + return $result; + } + + $command = [ + 'php', 'artisan', + 'pest:install', + '--ansi', '--no-interaction', + ]; + + return (new Process($command, $this->testSuite->rootPath, ['COMPOSER_MEMORY_LIMIT' => '-1'])) + ->setTimeout(null) + ->run(function ($type, $output): void { + $this->output->write($output); + }); + } + + /** + * Checks if laravel is installed through Composer + */ + private function isLaravelInstalled(): bool + { + return InstalledVersions::isInstalled('laravel/laravel'); + } } diff --git a/src/Plugins/Parallel/Paratest/WrapperRunner.php b/src/Plugins/Parallel/Paratest/WrapperRunner.php index e2c7079e..5c3bf2e4 100644 --- a/src/Plugins/Parallel/Paratest/WrapperRunner.php +++ b/src/Plugins/Parallel/Paratest/WrapperRunner.php @@ -296,6 +296,30 @@ final class WrapperRunner implements RunnerInterface ); } + $testResultSum = new TestResult( + $testResultSum->numberOfTests(), + $testResultSum->numberOfTestsRun(), + $testResultSum->numberOfAssertions(), + $testResultSum->testErroredEvents(), + $testResultSum->testFailedEvents(), + $testResultSum->testConsideredRiskyEvents(), + $testResultSum->testSuiteSkippedEvents(), + $testResultSum->testSkippedEvents(), + $testResultSum->testMarkedIncompleteEvents(), + $testResultSum->testTriggeredDeprecationEvents(), + $testResultSum->testTriggeredPhpDeprecationEvents(), + $testResultSum->testTriggeredPhpunitDeprecationEvents(), + $testResultSum->testTriggeredErrorEvents(), + $testResultSum->testTriggeredNoticeEvents(), + $testResultSum->testTriggeredPhpNoticeEvents(), + $testResultSum->testTriggeredWarningEvents(), + $testResultSum->testTriggeredPhpWarningEvents(), + $testResultSum->testTriggeredPhpunitErrorEvents(), + $testResultSum->testTriggeredPhpunitWarningEvents(), + $testResultSum->testRunnerTriggeredDeprecationEvents(), + array_values(array_filter($testResultSum->testRunnerTriggeredWarningEvents(), fn ($event): bool => ! str_contains($event->message(), 'No tests found'))), + ); + $this->printer->printResults( $testResultSum, $this->teamcityFiles, @@ -305,7 +329,7 @@ final class WrapperRunner implements RunnerInterface $this->generateCodeCoverageReports(); $this->generateLogs(); - $exitcode = (new ShellExitCodeCalculator())->calculate( + $exitCode = (new ShellExitCodeCalculator())->calculate( $this->options->configuration->failOnEmptyTestSuite(), $this->options->configuration->failOnRisky(), $this->options->configuration->failOnWarning(), @@ -320,7 +344,7 @@ final class WrapperRunner implements RunnerInterface $this->clearFiles($this->teamcityFiles); $this->clearFiles($this->testdoxFiles); - return $exitcode; + return $exitCode; } private function generateCodeCoverageReports(): void diff --git a/stubs/init/ExampleTest.php b/stubs/init/Feature/ExampleTest.php similarity index 100% rename from stubs/init/ExampleTest.php rename to stubs/init/Feature/ExampleTest.php diff --git a/stubs/init/TestCase.php b/stubs/init/TestCase.php new file mode 100644 index 00000000..cfb05b6d --- /dev/null +++ b/stubs/init/TestCase.php @@ -0,0 +1,10 @@ +toBeTrue(); +}); diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index cc563df2..81ae5e23 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -917,4 +917,4 @@ PASS Tests\Visual\Version ✓ visual snapshot of help command output - Tests: 4 incomplete, 4 todos, 18 skipped, 634 passed (1559 assertions) \ No newline at end of file + Tests: 4 incomplete, 4 todos, 18 skipped, 634 passed (1560 assertions) \ No newline at end of file diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 5e83d922..1fbe0ed3 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -9,6 +9,8 @@ $run = function () { $process->run(); + expect($process->getExitCode())->toBe(0); + return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput()); };