diff --git a/src/Concerns/Pipeable.php b/src/Concerns/Pipeable.php index 6d889f16..63ab0b7d 100644 --- a/src/Concerns/Pipeable.php +++ b/src/Concerns/Pipeable.php @@ -60,7 +60,7 @@ trait Pipeable } /** - * Get th list of pipes by the given name. + * Get the list of pipes by the given name. * * @return array */ diff --git a/src/Expectation.php b/src/Expectation.php index 4f524692..ff41ee22 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -347,9 +347,15 @@ final class Expectation return new HigherOrderExpectation($this, call_user_func_array($this->value->$method(...), $parameters)); } - ExpectationPipeline::for($this->getExpectationClosure($method)) + $closure = $this->getExpectationClosure($method); + $reflectionClosure = new \ReflectionFunction($closure); + $expectation = $reflectionClosure->getClosureThis(); + + assert(is_object($expectation)); + + ExpectationPipeline::for($closure) ->send(...$parameters) - ->through($this->pipes($method, $this, Expectation::class)) + ->through($this->pipes($method, $expectation, Expectation::class)) ->run(); return $this; diff --git a/tests/.pest/snapshots/Features/Expect/toMatchSnapshot/pass_using_pipes.snap b/tests/.pest/snapshots/Features/Expect/toMatchSnapshot/pass_using_pipes.snap new file mode 100644 index 00000000..a7233b4e --- /dev/null +++ b/tests/.pest/snapshots/Features/Expect/toMatchSnapshot/pass_using_pipes.snap @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 98754f5e..cd53e6fd 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -641,6 +641,16 @@ ✓ failures with multiple needles (some failing) ✓ not failures ✓ not failures with multiple needles (all failing) + ✓ not failures with multiple needles (some failing) + + PASS Tests\Features\Expect\toContainEqual + ✓ passes arrays + ✓ passes arrays with multiple needles + ✓ failures + ✓ failures with multiple needles (all failing) + ✓ failures with multiple needles (some failing) + ✓ not failures + ✓ not failures with multiple needles (all failing) ✓ not failures with multiple needles (some failing) PASS Tests\Features\Expect\toContainOnlyInstancesOf @@ -834,6 +844,7 @@ PASS Tests\Features\Expect\toMatchSnapshot ✓ pass + ✓ pass using pipes ✓ pass with __toString ✓ pass with toString ✓ pass with dataset with ('my-datas-set-value') @@ -1389,4 +1400,4 @@ WARN Tests\Visual\Version - visual snapshot of help command output - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 20 skipped, 986 passed (2372 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 20 skipped, 995 passed (2391 assertions) \ No newline at end of file diff --git a/tests/Features/Expect/toContainEqual.php b/tests/Features/Expect/toContainEqual.php index efe74920..796dadd7 100644 --- a/tests/Features/Expect/toContainEqual.php +++ b/tests/Features/Expect/toContainEqual.php @@ -2,7 +2,6 @@ use PHPUnit\Framework\ExpectationFailedException; - test('passes arrays', function () { expect([1, 2, 42])->toContainEqual('42'); }); diff --git a/tests/Features/Expect/toMatchSnapshot.php b/tests/Features/Expect/toMatchSnapshot.php index 8196cc0b..6dc3e83e 100644 --- a/tests/Features/Expect/toMatchSnapshot.php +++ b/tests/Features/Expect/toMatchSnapshot.php @@ -21,6 +21,23 @@ test('pass', function () { expect($this->snapshotable)->toMatchSnapshot(); }); +expect()->pipe('toMatchSnapshot', function (Closure $next) { + if (is_string($this->value)) { + $this->value = preg_replace( + '/name="_token" value=".*"/', + 'name="_token" value="1"', + $this->value + ); + } + + return $next(); +}); + +test('pass using pipes', function () { + expect('') + ->toMatchSnapshot(); +}); + test('pass with `__toString`', function () { TestSuite::getInstance()->snapshots->save($this->snapshotable); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 8fc30265..9708303b 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -16,7 +16,7 @@ $run = function () { test('parallel', function () use ($run) { expect($run('--exclude-group=integration')) - ->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 16 skipped, 973 passed (2353 assertions)') + ->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 16 skipped, 982 passed (2372 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows();