From 6fe3c1320cdd2552955d6e2990253b130b8b91d6 Mon Sep 17 00:00:00 2001 From: Lennart Carstens-Behrens Date: Fri, 11 Sep 2020 11:53:09 +0200 Subject: [PATCH 1/2] [8.x] Add the Countable interface to AssertableJsonString This pr adds the Countable interface to the new `Illuminate\Testing\AssertableJsonString`. This adds downgrade compatibility to tests counting the decoded json response: ```php $this->assertCount(1, $response->decodeJsonResponse()); ``` --- src/Illuminate/Testing/AssertableJsonString.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Testing/AssertableJsonString.php b/src/Illuminate/Testing/AssertableJsonString.php index 5040be137cb4..940e75d32222 100644 --- a/src/Illuminate/Testing/AssertableJsonString.php +++ b/src/Illuminate/Testing/AssertableJsonString.php @@ -3,13 +3,14 @@ namespace Illuminate\Testing; use ArrayAccess; +use Countable; use Illuminate\Contracts\Support\Jsonable; use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Testing\Assert as PHPUnit; use JsonSerializable; -class AssertableJsonString implements ArrayAccess +class AssertableJsonString implements ArrayAccess, Countable { /** * The original encoded json. @@ -328,6 +329,16 @@ protected function jsonSearchStrings($key, $value) $needle.',', ]; } + + /** + * Get the total number of items. + * + * @return int + */ + public function count() + { + return count($this->decoded); + } /** * Determine whether an offset exists. From 7165836adde3da4f7b4ca29a453a746e0606fa8b Mon Sep 17 00:00:00 2001 From: Lennart Carstens-Behrens Date: Fri, 11 Sep 2020 11:54:47 +0200 Subject: [PATCH 2/2] Apply fixes from StyleCI --- src/Illuminate/Testing/AssertableJsonString.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Testing/AssertableJsonString.php b/src/Illuminate/Testing/AssertableJsonString.php index 940e75d32222..0c14d116832e 100644 --- a/src/Illuminate/Testing/AssertableJsonString.php +++ b/src/Illuminate/Testing/AssertableJsonString.php @@ -329,7 +329,7 @@ protected function jsonSearchStrings($key, $value) $needle.',', ]; } - + /** * Get the total number of items. *