From 49de462250cf9f65f09e13eaf6dcc0e06865b930 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 10 Jun 2021 19:20:16 +0100 Subject: [PATCH] Adds support for incompleted tests --- src/Factories/TestCaseFactory.php | 8 ++++++-- tests/.snapshots/success.txt | 11 ++++++++++- tests/Features/Incompleted.php | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 tests/Features/Incompleted.php diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index 5285fc9e..4094d411 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -11,9 +11,9 @@ use Pest\Contracts\HasPrintableTestCaseName; use Pest\Datasets; use Pest\Exceptions\ShouldNotHappen; use Pest\Support\HigherOrderMessageCollection; -use Pest\Support\NullClosure; use Pest\Support\Str; use Pest\TestSuite; +use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; use RuntimeException; @@ -113,7 +113,11 @@ final class TestCaseFactory { $this->filename = $filename; $this->description = $description; - $this->test = $closure ?? NullClosure::create(); + $this->test = $closure ?? function (): void { + if (Assert::getCount() === 0) { + self::markTestIncomplete(); // @phpstan-ignore-line + } + }; $this->factoryProxies = new HigherOrderMessageCollection(); $this->proxies = new HigherOrderMessageCollection(); diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index eb3a3532..c8c969ee 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -108,6 +108,15 @@ ✓ it proxies calls to object ✓ it is capable doing multiple assertions + WARN Tests\Features\Incompleted + … it is incompleted + … it is incompleted even with method calls like skip + … it is incompleted even with method calls like group + ✓ it is not incompleted because of expect + ✓ it is not incompleted because of assert + ! it is not incompleted because of test with no assertions → This test did not perform any assertions /Users/nunomaduro/code/pestphp/pest/src/Factories/TestCaseFactory.php(221) : eval()'d code:4 + ✓ it is not incompleted because of test with assertions + PASS Tests\Features\It ✓ it is a test ✓ it is a higher order message test @@ -266,5 +275,5 @@ ✓ it is a test ✓ it uses correct parent class - Tests: 7 skipped, 164 passed + Tests: 1 risked, 3 incompleted, 7 skipped, 167 passed \ No newline at end of file diff --git a/tests/Features/Incompleted.php b/tests/Features/Incompleted.php new file mode 100644 index 00000000..7e57b292 --- /dev/null +++ b/tests/Features/Incompleted.php @@ -0,0 +1,19 @@ +skip(false); + +it('is incompleted even with method calls like group')->group('wtv'); + +it('is not incompleted because of expect')->expect(true)->toBeTrue(); + +it('is not incompleted because of assert')->assertTrue(true); + +it('is not incompleted because of test with no assertions', function () { + // ... +}); + +it('is not incompleted because of test with assertions', function () { + expect(true)->toBeTrue(); +});