Skip to content

Commit 463bdd9

Browse files
authored
[8.x] Add the Countable interface to AssertableJsonString (#34284)
* [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()); ``` * Apply fixes from StyleCI
1 parent fa7c913 commit 463bdd9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Illuminate/Testing/AssertableJsonString.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
namespace Illuminate\Testing;
44

55
use ArrayAccess;
6+
use Countable;
67
use Illuminate\Contracts\Support\Jsonable;
78
use Illuminate\Support\Arr;
89
use Illuminate\Support\Str;
910
use Illuminate\Testing\Assert as PHPUnit;
1011
use JsonSerializable;
1112

12-
class AssertableJsonString implements ArrayAccess
13+
class AssertableJsonString implements ArrayAccess, Countable
1314
{
1415
/**
1516
* The original encoded json.
@@ -329,6 +330,16 @@ protected function jsonSearchStrings($key, $value)
329330
];
330331
}
331332

333+
/**
334+
* Get the total number of items.
335+
*
336+
* @return int
337+
*/
338+
public function count()
339+
{
340+
return count($this->decoded);
341+
}
342+
332343
/**
333344
* Determine whether an offset exists.
334345
*

0 commit comments

Comments
 (0)