mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
implements decorators pipeline
This commit is contained in:
56
tests/Features/Expect/HigherOrder/decorate.php
Normal file
56
tests/Features/Expect/HigherOrder/decorate.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?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()->decorate('toBe', function ($next, $expected) {
|
||||
if ($this->value instanceof Character) {
|
||||
assertInstanceOf(Character::class, $expected);
|
||||
assertEquals($this->value->value, $expected->value);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$next($expected);
|
||||
});
|
||||
|
||||
expect()->decorate('toBe', function ($next, $expected) {
|
||||
if ($this->value instanceof Number) {
|
||||
assertInstanceOf(Number::class, $expected);
|
||||
assertEquals($this->value->value, $expected->value);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$next($expected);
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
Reference in New Issue
Block a user