feat: re-adds tap to avoid BC

This commit is contained in:
Nuno Maduro
2023-03-14 19:09:46 +00:00
parent fccb90c8ea
commit d71af91360
5 changed files with 29 additions and 3 deletions

View File

@ -19,7 +19,7 @@
"require": { "require": {
"php": "^8.1.0", "php": "^8.1.0",
"brianium/paratest": "^7.1.1", "brianium/paratest": "^7.1.1",
"nunomaduro/collision": "^7.1.1", "nunomaduro/collision": "^7.1.2",
"nunomaduro/termwind": "^1.15.1", "nunomaduro/termwind": "^1.15.1",
"pestphp/pest-plugin": "^2.0.0", "pestphp/pest-plugin": "^2.0.0",
"pestphp/pest-plugin-arch": "^2.0.0", "pestphp/pest-plugin-arch": "^2.0.0",

View File

@ -49,6 +49,16 @@ final class HigherOrderCallables
return $this->expect($value); 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. * Execute the given callable after the test has executed the setup method.
*/ */

View File

@ -668,8 +668,10 @@
✓ it resolves expect callables correctly ✓ it resolves expect callables correctly
✓ does not treat method names as callables ✓ does not treat method names as callables
✓ it can defer a method until after test setup ✓ 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 expect callables with (1, 2, 3)
✓ it can pass datasets into the defer callable 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 (1)
✓ it can pass shared datasets into callables with (2) ✓ it can pass shared datasets into callables with (2)
@ -936,4 +938,4 @@
PASS Tests\Visual\Version PASS Tests\Visual\Version
✓ visual snapshot of help command output ✓ visual snapshot of help command output
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 18 skipped, 639 passed (1572 assertions) Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 18 skipped, 641 passed (1581 assertions)

View File

@ -31,6 +31,14 @@ it('can defer a method until after test setup')
->toBe('foo') ->toBe('foo')
->and('hello world')->toBeString(); ->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') it('can pass datasets into the expect callables')
->with([[1, 2, 3]]) ->with([[1, 2, 3]])
->expect(function (...$numbers) { ->expect(function (...$numbers) {
@ -46,6 +54,12 @@ it('can pass datasets into the defer callable')
expect($numbers)->toBe([1, 2, 3]); 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') it('can pass shared datasets into callables')
->with('numbers.closure.wrapped') ->with('numbers.closure.wrapped')
->expect(function ($value) { ->expect(function ($value) {

View File

@ -15,6 +15,6 @@ $run = function () {
}; };
test('parallel', function () use ($run) { 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'); ->toContain('Parallel: 3 processes');
}); });