-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from oleg-andreyev/rewind-issue
after calling CacheEntry::__sleep we need to rewind
- Loading branch information
Showing
3 changed files
with
60 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Kevinrob\GuzzleCache\Tests; | ||
|
||
use GuzzleHttp\Psr7\Request; | ||
use GuzzleHttp\Psr7\Response; | ||
use GuzzleHttp\Psr7\Utils; | ||
use Kevinrob\GuzzleCache\CacheMiddleware as BaseCacheMiddleware; | ||
use Kevinrob\GuzzleCache\Storage\Psr6CacheStorage; | ||
use Kevinrob\GuzzleCache\Strategy\CacheStrategyInterface; | ||
use Kevinrob\GuzzleCache\Strategy\PrivateCacheStrategy; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Symfony\Component\Cache\Adapter\FilesystemAdapter; | ||
|
||
class CacheMiddlewareTest extends TestCase | ||
{ | ||
public function testRewindAfterReadingStream() | ||
{ | ||
$stream = Utils::streamFor('seekable stream'); | ||
$strategy = new PrivateCacheStrategy( | ||
new Psr6CacheStorage( | ||
new FilesystemAdapter('', -1, sys_get_temp_dir()) | ||
) | ||
); | ||
$request = new Request('GET', '/uri'); | ||
$response = (new Response())->withBody($stream)->withHeader('Cache-Control', 'max-age=3600'); | ||
|
||
CacheMiddleware::addToCache( | ||
$strategy, | ||
$request, | ||
$response | ||
); | ||
|
||
$this->assertEquals('seekable stream', $response->getBody()->getContents()); | ||
} | ||
} | ||
|
||
class CacheMiddleware extends BaseCacheMiddleware | ||
{ | ||
public static function addToCache(CacheStrategyInterface $cache, RequestInterface $request, ResponseInterface $response, $update = false) | ||
{ | ||
return parent::addToCache($cache, $request, $response, $update); | ||
} | ||
} |