From ff527baa1d00fa9857985553c480143e0ba42143 Mon Sep 17 00:00:00 2001 From: luke Date: Thu, 24 Jun 2021 21:31:12 +0100 Subject: [PATCH] Allows `and` in Higher Order Expectations. --- src/HigherOrderExpectation.php | 10 ++++++++++ .../Expect/HigherOrder/methodsAndProperties.php | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/HigherOrderExpectation.php b/src/HigherOrderExpectation.php index 6e2ed23f..4cb6fc49 100644 --- a/src/HigherOrderExpectation.php +++ b/src/HigherOrderExpectation.php @@ -63,6 +63,16 @@ final class HigherOrderExpectation return $this; } + /** + * Creates a new expectation. + * + * @param mixed $value + */ + public function and($value): HigherOrderExpectation + { + return new self($this->expect($value), $value); + } + /** * Dynamically calls methods on the class with the given arguments. * 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';