diff --git a/src/Illuminate/Foundation/Testing/TestResponse.php b/src/Illuminate/Foundation/Testing/TestResponse.php index e7cae94b204a..544febdd4909 100644 --- a/src/Illuminate/Foundation/Testing/TestResponse.php +++ b/src/Illuminate/Foundation/Testing/TestResponse.php @@ -2,6 +2,7 @@ namespace Illuminate\Foundation\Testing; +use ArrayAccess; use Closure; use Illuminate\Contracts\View\View; use Illuminate\Database\Eloquent\Model; @@ -12,12 +13,13 @@ use Illuminate\Support\Str; use Illuminate\Support\Traits\Macroable; use Illuminate\Support\Traits\Tappable; +use LogicException; use Symfony\Component\HttpFoundation\StreamedResponse; /** * @mixin \Illuminate\Http\Response */ -class TestResponse +class TestResponse implements ArrayAccess { use Tappable, Macroable { __call as macroCall; @@ -1210,6 +1212,51 @@ public function __isset($key) return isset($this->baseResponse->{$key}); } + /** + * Determine if the given offset exists. + * + * @param string $offset + * @return bool + */ + public function offsetExists($offset) + { + return isset($this->json()[$offset]); + } + + /** + * Get the value for a given offset. + * + * @param string $offset + * @return mixed + */ + public function offsetGet($offset) + { + return $this->json()[$offset]; + } + + /** + * Set the value at the given offset. + * + * @param string $offset + * @param mixed $value + * @return void + */ + public function offsetSet($offset, $value) + { + throw new LogicException('Response data may not be mutated using array access.'); + } + + /** + * Unset the value at the given offset. + * + * @param string $offset + * @return void + */ + public function offsetUnset($offset) + { + throw new LogicException('Response data may not be mutated using array access.'); + } + /** * Handle dynamic calls into macros or pass missing methods to the base response. *