Adds nested Higher Order Expectations.

This commit is contained in:
luke
2021-06-16 20:48:23 +01:00
parent 729638a3bb
commit 7ff64540a6
8 changed files with 128 additions and 53 deletions

View File

@ -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

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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'],
];
}