From 2831629f1be38f4f7509933238d01f1923a29a11 Mon Sep 17 00:00:00 2001 From: Luke Downing Date: Fri, 21 Jan 2022 16:35:21 +0000 Subject: [PATCH 1/2] Fixes bug with `json` method call in Higher Order Expectations. --- src/HigherOrderExpectation.php | 5 +++++ tests/.snapshots/success.txt | 3 ++- tests/Features/Expect/HigherOrder/methods.php | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/HigherOrderExpectation.php b/src/HigherOrderExpectation.php index e436da0c..1e7155c7 100644 --- a/src/HigherOrderExpectation.php +++ b/src/HigherOrderExpectation.php @@ -77,6 +77,11 @@ final class HigherOrderExpectation return $this->expect($value); } + public function json(): HigherOrderExpectation + { + return new self($this->original, $this->expectation->json()->value); + } + /** * Dynamically calls methods on the class with the given arguments. * diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 0c6a57ab..03ffdd4d 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -124,6 +124,7 @@ ✓ it can compose complex expectations ✓ it can handle nested method calls ✓ it works with higher order tests + ✓ it can call the json method in higher order expectations PASS Tests\Features\Expect\HigherOrder\methodsAndProperties ✓ it can access methods and properties @@ -720,5 +721,5 @@ ✓ it is a test ✓ it uses correct parent class - Tests: 4 incompleted, 9 skipped, 478 passed + Tests: 4 incompleted, 9 skipped, 479 passed \ No newline at end of file diff --git a/tests/Features/Expect/HigherOrder/methods.php b/tests/Features/Expect/HigherOrder/methods.php index d6da636b..a1b729a9 100644 --- a/tests/Features/Expect/HigherOrder/methods.php +++ b/tests/Features/Expect/HigherOrder/methods.php @@ -74,8 +74,19 @@ it('works with higher order tests') ->name()->toEqual('Has Methods') ->books()->each->toBeArray; +it('can call the json method in higher order expectations', function () { + expect(new HasMethods()) + ->getJsonContent()->json()->id->toBe(1)->toBeGreaterThan(0) + ->getJsonContent()->json()->email->toBe('amenophis@leherpeur.net'); +}); + class HasMethods { + public function getJsonContent(): string + { + return '{"id":1,"username":"amenophis","email":"amenophis@leherpeur.net"}'; + } + public function name() { return 'Has Methods'; From 2218a0c1377bd04eee4c55a88973cb2347885782 Mon Sep 17 00:00:00 2001 From: Luke Downing Date: Fri, 21 Jan 2022 16:39:10 +0000 Subject: [PATCH 2/2] Tweaks --- tests/Features/Expect/HigherOrder/methods.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Features/Expect/HigherOrder/methods.php b/tests/Features/Expect/HigherOrder/methods.php index a1b729a9..c85917b5 100644 --- a/tests/Features/Expect/HigherOrder/methods.php +++ b/tests/Features/Expect/HigherOrder/methods.php @@ -77,14 +77,14 @@ it('works with higher order tests') it('can call the json method in higher order expectations', function () { expect(new HasMethods()) ->getJsonContent()->json()->id->toBe(1)->toBeGreaterThan(0) - ->getJsonContent()->json()->email->toBe('amenophis@leherpeur.net'); + ->getJsonContent()->json()->email->toBe('foo@bar.com'); }); class HasMethods { public function getJsonContent(): string { - return '{"id":1,"username":"amenophis","email":"amenophis@leherpeur.net"}'; + return '{"id":1,"username":"dan","email":"foo@bar.com"}'; } public function name()