adds test to check if pipes can add parameters to an expectation

This commit is contained in:
Fabio Ivona
2021-10-10 01:09:45 +02:00
parent fc53f08e37
commit 0346450a51
2 changed files with 21 additions and 1 deletions

View File

@ -186,6 +186,7 @@
✓ intercept stops the pipeline
✓ interception is called only when filter is met
✓ intercept can be filtered with a closure
✓ intercept can add new parameters to the expectation
PASS Tests\Features\Expect\ray
✓ ray calls do not fail when ray is not installed
@ -730,5 +731,5 @@
✓ it is a test
✓ it uses correct parent class
Tests: 4 incompleted, 9 skipped, 486 passed
Tests: 4 incompleted, 9 skipped, 487 passed

View File

@ -1,8 +1,10 @@
<?php
use function PHPUnit\Framework\assertEquals;
use function PHPUnit\Framework\assertEqualsIgnoringCase;
use function PHPUnit\Framework\assertInstanceOf;
use function PHPUnit\Framework\assertIsNumeric;
use function PHPUnit\Framework\assertSame;
class Number
{
@ -118,6 +120,19 @@ expect()->pipe('toBe', function ($next, $expected) use ($state) {
$next();
});
/*
* Overrides toBe check strings ignoring case
*/
expect()->intercept('toBe', function ($value) {
return is_string($value);
}, function ($expected, $ignoreCase = false) {
if ($ignoreCase) {
assertEqualsIgnoringCase($expected, $this->value);
} else {
assertSame($expected, $this->value);
}
});
test('pipe is applied and can stop pipeline', function () use ($state) {
$letter = new Character('A');
@ -219,3 +234,7 @@ test('intercept can be filtered with a closure', function () use ($state) {
->runCount->toHaveKey('wildcard', 1)
->appliedCount->toHaveKey('wildcard', 1);
});
test('intercept can add new parameters to the expectation', function () {
expect('Foo')->toBe('foo', true);
});