Skip to content

Commit

Permalink
Adds support for incompleted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Jun 10, 2021
1 parent 95e8add commit 49de462
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Factories/TestCaseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
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;

Expand Down Expand Up @@ -113,7 +113,11 @@ public function __construct(string $filename, string $description = null, Closur
{
$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();
Expand Down
11 changes: 10 additions & 1 deletion tests/.snapshots/success.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

19 changes: 19 additions & 0 deletions tests/Features/Incompleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

it('is incompleted');

it('is incompleted even with method calls like skip')->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();
});

0 comments on commit 49de462

Please sign in to comment.