diff --git a/src/HigherOrderExpectation.php b/src/HigherOrderExpectation.php index 6e2ed23f..e436da0c 100644 --- a/src/HigherOrderExpectation.php +++ b/src/HigherOrderExpectation.php @@ -63,6 +63,20 @@ final class HigherOrderExpectation return $this; } + /** + * Creates a new expectation. + * + * @template TValue + * + * @param TValue $value + * + * @return Expectation + */ + public function and($value): Expectation + { + return $this->expect($value); + } + /** * Dynamically calls methods on the class with the given arguments. * diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index e7ecc1a0..9b0a5c44 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -116,6 +116,7 @@ PASS Tests\Features\Expect\HigherOrder\methodsAndProperties ✓ it can access 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 ✓ it allows properties to be accessed from the value @@ -578,5 +579,5 @@ ✓ it is a test ✓ it uses correct parent class - Tests: 4 incompleted, 7 skipped, 362 passed + Tests: 4 incompleted, 7 skipped, 363 passed \ No newline at end of file diff --git a/tests/Features/Expect/HigherOrder/methodsAndProperties.php b/tests/Features/Expect/HigherOrder/methodsAndProperties.php index f75f698a..08c4a3bc 100644 --- a/tests/Features/Expect/HigherOrder/methodsAndProperties.php +++ b/tests/Features/Expect/HigherOrder/methodsAndProperties.php @@ -22,6 +22,17 @@ it('can handle nested methods and properties', function () { ->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 { public $name = 'Has Methods and Properties';