diff --git a/stubs/init/Pest.php.stub b/stubs/init/Pest.php.stub index d4ffffba..55c848c6 100644 --- a/stubs/init/Pest.php.stub +++ b/stubs/init/Pest.php.stub @@ -13,6 +13,10 @@ use Tests\TestCase; | */ +if (! class_exists(TestCase::class)) { + require_once __DIR__.'/TestCase.php'; +} + pest()->extend(TestCase::class)->in('Feature'); /* diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 3c496883..98066c4a 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -1302,7 +1302,7 @@ … a "describe" group of tests → it is incompleted PASS Tests\Features\Init - ✓ init creates a suite when the tests directory is missing + ✓ init creates a runnable suite when the tests directory is missing ✓ init creates a suite when --init is not the first argument ✓ init creates a suite when --init is passed with a value ✓ a missing tests directory does not crash while resolving tia state @@ -2523,4 +2523,4 @@ ✓ pass with dataset with ('my-datas-set-value') ✓ within describe → pass with dataset with ('my-datas-set-value') - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 38 skipped, 1831 passed (4150 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 38 skipped, 1831 passed (4152 assertions) \ No newline at end of file diff --git a/tests/Features/Init.php b/tests/Features/Init.php index 4344449b..6222fa26 100644 --- a/tests/Features/Init.php +++ b/tests/Features/Init.php @@ -4,7 +4,7 @@ declare(strict_types=1); use Symfony\Component\Process\Process; -test('init creates a suite when the tests directory is missing', function (): void { +test('init creates a runnable suite when the tests directory is missing', function (): void { $root = makeInitProject(); try { @@ -17,6 +17,11 @@ test('init creates a suite when the tests directory is missing', function (): vo ->and($root.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Pest.php')->toBeFile() ->and($root.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'TestCase.php')->toBeFile() ->and($root.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Unit'.DIRECTORY_SEPARATOR.'ExampleTest.php')->toBeFile(); + + $suite = runInitProject($root, '--colors=never'); + + expect($suite->getExitCode())->toBe(0) + ->and($suite->getOutput())->toContain('2 passed (2 assertions)'); } finally { removeInitProject($root); } @@ -85,6 +90,11 @@ function makeInitProject(): string true, ); + file_put_contents( + $root.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'autoload.php', + "toContain("Tests: {$expected}")