fix: pipes not allowing to modify original value

This commit is contained in:
Nuno Maduro
2024-01-25 16:10:16 +00:00
parent 887bed3d45
commit 95cd550524
7 changed files with 40 additions and 6 deletions

View File

@ -0,0 +1 @@
<input type="hidden" name="_token" value="1" />

View File

@ -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)

View File

@ -2,7 +2,6 @@
use PHPUnit\Framework\ExpectationFailedException;
test('passes arrays', function () {
expect([1, 2, 42])->toContainEqual('42');
});

View File

@ -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);

View File

@ -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();