mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Adds nested Higher Order Expectations.
This commit is contained in:
@ -111,9 +111,11 @@
|
||||
✓ it works inside of each
|
||||
✓ it works with sequence
|
||||
✓ it can compose complex expectations
|
||||
✓ it can handle nested method calls
|
||||
|
||||
PASS Tests\Features\Expect\HigherOrder\methodsAndProperties
|
||||
✓ it can access methods and properties
|
||||
✓ it can handle nested methods and properties
|
||||
|
||||
PASS Tests\Features\Expect\HigherOrder\properties
|
||||
✓ it allows properties to be accessed from the value
|
||||
@ -124,6 +126,7 @@
|
||||
✓ it works with sequence
|
||||
✓ it can compose complex expectations
|
||||
✓ it works with objects
|
||||
✓ it works with nested properties
|
||||
|
||||
PASS Tests\Features\Expect\each
|
||||
✓ an exception is thrown if the the type is not iterable
|
||||
@ -554,5 +557,5 @@
|
||||
✓ it is a test
|
||||
✓ it uses correct parent class
|
||||
|
||||
Tests: 4 incompleted, 7 skipped, 340 passed
|
||||
Tests: 4 incompleted, 7 skipped, 343 passed
|
||||
|
||||
@ -59,6 +59,14 @@ it('can compose complex expectations', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('can handle nested method calls', function () {
|
||||
expect(new HasMethods())
|
||||
->newInstance()->newInstance()->name()->toEqual('Has Methods')->toBeString()
|
||||
->newInstance()->name()->toEqual('Has Methods')->not->toBeInt
|
||||
->name()->toEqual('Has Methods')
|
||||
->books()->each->toBeArray();
|
||||
});
|
||||
|
||||
class HasMethods
|
||||
{
|
||||
public function name()
|
||||
@ -97,4 +105,9 @@ class HasMethods
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function newInstance()
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,10 +14,20 @@ it('can access methods and properties', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('can handle nested methods and properties', function () {
|
||||
expect(new HasMethodsAndProperties())
|
||||
->meta->foo->bar->toBeString()->toEqual('baz')->not->toBeInt
|
||||
->newInstance()->meta->foo->toBeArray()
|
||||
->newInstance()->multiply(2, 2)->toEqual(4)->not->toEqual(5)
|
||||
->newInstance()->books()->toBeArray();
|
||||
});
|
||||
|
||||
class HasMethodsAndProperties
|
||||
{
|
||||
public $name = 'Has Methods and Properties';
|
||||
|
||||
public $meta = ['foo' => ['bar' => 'baz']];
|
||||
|
||||
public $posts = [
|
||||
[
|
||||
'is_published' => true,
|
||||
@ -47,4 +57,9 @@ class HasMethodsAndProperties
|
||||
{
|
||||
return $x * $y;
|
||||
}
|
||||
|
||||
public function newInstance()
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,6 +58,12 @@ it('works with objects', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('works with nested properties', function () {
|
||||
expect(new HasProperties())
|
||||
->nested->foo->bar->toBeString()->toEqual('baz')
|
||||
->posts->toBeArray()->toHaveCount(2);
|
||||
});
|
||||
|
||||
class HasProperties
|
||||
{
|
||||
public $name = 'foo';
|
||||
@ -72,4 +78,8 @@ class HasProperties
|
||||
'title' => 'Bar',
|
||||
],
|
||||
];
|
||||
|
||||
public $nested = [
|
||||
'foo' => ['bar' => 'baz'],
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user