Merge pull request #330 from pestphp/higher-order-expectation-and

Allows `and` in Higher Order Expectations.
This commit is contained in:
Nuno Maduro
2021-06-24 21:42:22 +01:00
committed by GitHub
3 changed files with 27 additions and 1 deletions

View File

@ -63,6 +63,20 @@ final class HigherOrderExpectation
return $this; return $this;
} }
/**
* Creates a new expectation.
*
* @template TValue
*
* @param TValue $value
*
* @return Expectation<TValue>
*/
public function and($value): Expectation
{
return $this->expect($value);
}
/** /**
* Dynamically calls methods on the class with the given arguments. * Dynamically calls methods on the class with the given arguments.
* *

View File

@ -116,6 +116,7 @@
PASS Tests\Features\Expect\HigherOrder\methodsAndProperties PASS Tests\Features\Expect\HigherOrder\methodsAndProperties
✓ it can access methods and properties ✓ it can access methods and properties
✓ it can handle nested methods and properties ✓ it can handle nested methods and properties
✓ it can start a new higher order expectation using the and syntax
PASS Tests\Features\Expect\HigherOrder\properties PASS Tests\Features\Expect\HigherOrder\properties
✓ it allows properties to be accessed from the value ✓ it allows properties to be accessed from the value
@ -578,5 +579,5 @@
✓ it is a test ✓ it is a test
✓ it uses correct parent class ✓ it uses correct parent class
Tests: 4 incompleted, 7 skipped, 362 passed Tests: 4 incompleted, 7 skipped, 363 passed

View File

@ -22,6 +22,17 @@ it('can handle nested methods and properties', function () {
->newInstance()->books()->toBeArray(); ->newInstance()->books()->toBeArray();
}); });
it('can start a new higher order expectation using the and syntax', function () {
expect(new HasMethodsAndProperties())
->toBeInstanceOf(HasMethodsAndProperties::class)
->meta->toBeArray
->and(['foo' => 'bar'])
->toBeArray()
->foo->toEqual('bar');
expect(static::getCount())->toEqual(4);
});
class HasMethodsAndProperties class HasMethodsAndProperties
{ {
public $name = 'Has Methods and Properties'; public $name = 'Has Methods and Properties';