Skip to content

Commit

Permalink
Add test for JSON responses
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephSilber committed Jul 19, 2020
1 parent 7a9c0fb commit dfad052
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;

class CacheTest extends TestCase
{
Expand Down Expand Up @@ -140,6 +141,23 @@ public function testCachesRootToSpecialFilename()
$this->cache->cache(Request::create('/', 'GET'), Response::create('content'));
}

public function testCachesJsonResponsesWithJsonExtension()
{
$content = ['this' => 'is', 'json' => [1, 2, 3]];

$this->files->shouldReceive('makeDirectory')->once()
->with('page-cache', 0775, true, true);

$this->files->shouldReceive('put')->once()
->with('page-cache/get-json.json', json_encode($content), true);

$this->cache->setCachePath('page-cache');
$this->cache->cache(
Request::create('get-json', 'GET'),
JsonResponse::create($content)
);
}

/**
* Assert that the given request/response pair are cached.
*
Expand Down

0 comments on commit dfad052

Please sign in to comment.