diff --git a/composer.json b/composer.json index 4f78b19c..9feafffc 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "require": { "php": "^8.1.0", "brianium/paratest": "^7.1.1", - "nunomaduro/collision": "^7.1.1", + "nunomaduro/collision": "^7.1.2", "nunomaduro/termwind": "^1.15.1", "pestphp/pest-plugin": "^2.0.0", "pestphp/pest-plugin-arch": "^2.0.0", diff --git a/src/Support/HigherOrderCallables.php b/src/Support/HigherOrderCallables.php index 3b7a74f8..f0248939 100644 --- a/src/Support/HigherOrderCallables.php +++ b/src/Support/HigherOrderCallables.php @@ -49,6 +49,16 @@ final class HigherOrderCallables return $this->expect($value); } + /** + * Execute the given callable after the test has executed the setup method. + * + * @deprecated This method is deprecated. Please use `defer` instead. + */ + public function tap(callable $callable): object + { + return $this->defer($callable); + } + /** * Execute the given callable after the test has executed the setup method. */ diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index bde61d13..5ae5f950 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -668,8 +668,10 @@ ✓ it resolves expect callables correctly ✓ does not treat method names as callables ✓ it can defer a method until after test setup + ✓ it can tap a method until after test setup ✓ it can pass datasets into the expect callables with (1, 2, 3) ✓ it can pass datasets into the defer callable with (1, 2, 3) + ✓ it can pass datasets into the tap callable with (1, 2, 3) ✓ it can pass shared datasets into callables with (1) ✓ it can pass shared datasets into callables with (2) @@ -936,4 +938,4 @@ PASS Tests\Visual\Version ✓ visual snapshot of help command output - Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 18 skipped, 639 passed (1572 assertions) \ No newline at end of file + Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 18 skipped, 641 passed (1581 assertions) \ No newline at end of file diff --git a/tests/Features/HigherOrderTests.php b/tests/Features/HigherOrderTests.php index a1bef96d..f3058fcc 100644 --- a/tests/Features/HigherOrderTests.php +++ b/tests/Features/HigherOrderTests.php @@ -31,6 +31,14 @@ it('can defer a method until after test setup') ->toBe('foo') ->and('hello world')->toBeString(); +it('can tap a method until after test setup') + ->expect('foo')->toBeString() + ->tap(function () { + expect($this)->toBeInstanceOf(TestCase::class); + }) + ->toBe('foo') + ->and('hello world')->toBeString(); + it('can pass datasets into the expect callables') ->with([[1, 2, 3]]) ->expect(function (...$numbers) { @@ -46,6 +54,12 @@ it('can pass datasets into the defer callable') expect($numbers)->toBe([1, 2, 3]); }); +it('can pass datasets into the tap callable') + ->with([[1, 2, 3]]) + ->tap(function (...$numbers) { + expect($numbers)->toBe([1, 2, 3]); + }); + it('can pass shared datasets into callables') ->with('numbers.closure.wrapped') ->expect(function ($value) { diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 9b0c468a..fd2fb38d 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -15,6 +15,6 @@ $run = function () { }; test('parallel', function () use ($run) { - expect($run())->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 15 skipped, 630 passed (1559 assertions)') + expect($run())->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 15 skipped, 632 passed (1568 assertions)') ->toContain('Parallel: 3 processes'); });