mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
fix: pipes not allowing to modify original value
This commit is contained in:
@ -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<int, Closure>
|
||||
*/
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -0,0 +1 @@
|
||||
<input type="hidden" name="_token" value="1" />
|
||||
@ -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)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 20 skipped, 995 passed (2391 assertions)
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
|
||||
test('passes arrays', function () {
|
||||
expect([1, 2, 42])->toContainEqual('42');
|
||||
});
|
||||
|
||||
@ -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('<input type="hidden" name="_token" value="'.random_int(1, 999).'" />')
|
||||
->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pass with `__toString`', function () {
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user