From e228d565af29e270485f4c6040fda7fa0c1a740e Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 10 Jan 2023 20:21:33 +0000 Subject: [PATCH] feat: allows to chain `todo` --- src/Functions.php | 11 ++++++----- src/PendingCalls/TestCall.php | 10 ++++++++++ src/Support/ExceptionTrace.php | 2 +- src/Support/HigherOrderTapProxy.php | 4 ++++ tests/.snapshots/success.txt | 4 +++- tests/Features/Todo.php | 6 ++++++ 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/Functions.php b/src/Functions.php index 8d033694..ba9856c0 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -87,7 +87,7 @@ if (! function_exists('test')) { * is the test description; the second argument is * a closure that contains the test expectations. * - * @return TestCall|TestCase|mixed + * @return HigherOrderTapProxy|TestCall */ function test(string $description = null, Closure $closure = null): HigherOrderTapProxy|TestCall { @@ -130,10 +130,11 @@ if (! function_exists('todo')) { */ function todo(string $description): TestCall { - /* @phpstan-ignore-next-line */ - return test($description, fn () => self::markTestSkipped( - '__TODO__', - )); + $test = test($description); + + assert($test instanceof TestCall); + + return $test->skip('__TODO__'); } } diff --git a/src/PendingCalls/TestCall.php b/src/PendingCalls/TestCall.php index d24c593b..3cd8cee6 100644 --- a/src/PendingCalls/TestCall.php +++ b/src/PendingCalls/TestCall.php @@ -170,6 +170,16 @@ final class TestCall return $this; } + /** + * Sets the test as "todo". + */ + public function todo(): self + { + $this->skip('__TODO__'); + + return $this; + } + /** * Sets the covered classes or methods. */ diff --git a/src/Support/ExceptionTrace.php b/src/Support/ExceptionTrace.php index 0e175677..faa5080b 100644 --- a/src/Support/ExceptionTrace.php +++ b/src/Support/ExceptionTrace.php @@ -44,7 +44,7 @@ final class ExceptionTrace */ public static function removePestReferences(Throwable $t): void { - if (! property_exists($t, 'serializableTrace')) { // @phpstan-ignore-line + if (! property_exists($t, 'serializableTrace')) { return; } diff --git a/src/Support/HigherOrderTapProxy.php b/src/Support/HigherOrderTapProxy.php index 1b5f12cf..6a4f8ecd 100644 --- a/src/Support/HigherOrderTapProxy.php +++ b/src/Support/HigherOrderTapProxy.php @@ -10,6 +10,10 @@ use Throwable; /** * @internal + * + * @template TProxy + * + * @mixin TProxy */ final class HigherOrderTapProxy { diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 789c001e..e91aae32 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -734,6 +734,8 @@ PASS Tests\Features\Todo ↓ something todo later + ↓ something todo later chained + ↓ something todo later chained and with function body ✓ it does something within a file with a todo PASS Tests\Fixtures\DirectoryWithTests\ExampleTest @@ -896,4 +898,4 @@ PASS Tests\Visual\Version ✓ visual snapshot of help command output - Tests: 4 incomplete, 2 todos, 17 skipped, 624 passed (1511 assertions) \ No newline at end of file + Tests: 4 incomplete, 4 todos, 17 skipped, 624 passed (1511 assertions) \ No newline at end of file diff --git a/tests/Features/Todo.php b/tests/Features/Todo.php index f9cb4cc8..6086b77c 100644 --- a/tests/Features/Todo.php +++ b/tests/Features/Todo.php @@ -2,6 +2,12 @@ todo('something todo later'); +test('something todo later chained')->todo(); + +test('something todo later chained and with function body', function () { + expect(true)->toBeFalse(); +})->todo(); + it('does something within a file with a todo', function () { expect(true)->toBeTrue(); });