moved decorate implementation to dedicated intercept and pipe calls

This commit is contained in:
Fabio Ivona
2021-10-09 10:22:24 +02:00
parent 8835502074
commit 55376d32e5
5 changed files with 54 additions and 23 deletions

View File

@ -0,0 +1,49 @@
<?php
use function PHPUnit\Framework\assertEquals;
use function PHPUnit\Framework\assertInstanceOf;
class Number
{
public $value;
public function __construct($value)
{
$this->value = $value;
}
}
class Character
{
public $value;
public function __construct($value)
{
$this->value = $value;
}
}
expect()->pipe('toBe', function ($expected, $next) {
if ($this->value instanceof Character) {
assertInstanceOf(Character::class, $expected);
assertEquals($this->value->value, $expected->value);
return;
}
$next($expected);
});
expect()->intercept('toBe', Number::class, function ($expected) {
assertEquals($this->value->value, $expected->value);
});
test('pass', function () {
$number = new Number(1);
$letter = new Character('A');
expect($number)->toBe(new Number(1));
expect($letter)->toBe(new Character('A'));
expect(3)->toBe(3);
});