Skip to content

Commit

Permalink
[8.x] Add the Countable interface to AssertableJsonString (#34284)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
cbl authored Sep 11, 2020
1 parent fa7c913 commit 463bdd9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Illuminate/Testing/AssertableJsonString.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -329,6 +330,16 @@ protected function jsonSearchStrings($key, $value)
];
}

/**
* Get the total number of items.
*
* @return int
*/
public function count()
{
return count($this->decoded);
}

/**
* Determine whether an offset exists.
*
Expand Down

0 comments on commit 463bdd9

Please sign in to comment.