@@ 190-200 (lines=11) @@ | ||
187 | * @test |
|
188 | * @covers ::filter |
|
189 | */ |
|
190 | public function chainFail() |
|
191 | { |
|
192 | $result = Filterer::filter( |
|
193 | ['fieldOne' => [['trim'], ['\TraderInteractive\FiltererTest::failingFilter']]], |
|
194 | ['fieldOne' => 'the value'] |
|
195 | ); |
|
196 | $this->assertSame( |
|
197 | [false, null, "Field 'fieldOne' with value 'the value' failed filtering, message 'i failed'", []], |
|
198 | $result |
|
199 | ); |
|
200 | } |
|
201 | ||
202 | /** |
|
203 | * @test |
|
@@ 403-418 (lines=16) @@ | ||
400 | * |
|
401 | * @return void |
|
402 | */ |
|
403 | public function filterWithCustomError() |
|
404 | { |
|
405 | $result = Filterer::filter( |
|
406 | [ |
|
407 | 'fieldOne' => [ |
|
408 | 'error' => 'My custom error message', |
|
409 | ['\TraderInteractive\FiltererTest::failingFilter'], |
|
410 | ], |
|
411 | ], |
|
412 | ['fieldOne' => 'valueOne'] |
|
413 | ); |
|
414 | $this->assertSame( |
|
415 | [false, null, 'My custom error message', []], |
|
416 | $result |
|
417 | ); |
|
418 | } |
|
419 | ||
420 | /** |
|
421 | * @test |
|
@@ 424-439 (lines=16) @@ | ||
421 | * @test |
|
422 | * @covers ::filter |
|
423 | */ |
|
424 | public function filterWithCustomErrorContainingValuePlaceholder() |
|
425 | { |
|
426 | $result = Filterer::filter( |
|
427 | [ |
|
428 | 'fieldOne' => [ |
|
429 | 'error' => "The value '{value}' is invalid.", |
|
430 | ['uint'], |
|
431 | ], |
|
432 | ], |
|
433 | ['fieldOne' => 'abc'] |
|
434 | ); |
|
435 | $this->assertSame( |
|
436 | [false, null, "The value 'abc' is invalid.", []], |
|
437 | $result |
|
438 | ); |
|
439 | } |
|
440 | /** |
|
441 | * Verify behavior of filter() when 'error' is not a string value. |
|
442 | * |
|
@@ 655-662 (lines=8) @@ | ||
652 | * @tests |
|
653 | * @covers ::filter |
|
654 | */ |
|
655 | public function arrayizeAliasIsCalledProperly() |
|
656 | { |
|
657 | $result = Filterer::filter(['field' => [['arrayize']]], ['field' => 'a string value']); |
|
658 | $this->assertSame( |
|
659 | [true, ['field' => ['a string value']], null, []], |
|
660 | $result |
|
661 | ); |
|
662 | } |
|
663 | } |
|
664 |