|
2 | 2 |
|
3 | 3 | namespace Kevinrob\GuzzleCache\Tests;
|
4 | 4 |
|
| 5 | +use GuzzleHttp\Psr7\Request; |
| 6 | +use GuzzleHttp\Psr7\Response; |
5 | 7 | use Kevinrob\GuzzleCache\CacheEntry;
|
6 | 8 | use PHPUnit\Framework\TestCase;
|
7 | 9 | use Psr\Http\Message\RequestInterface;
|
@@ -81,6 +83,34 @@ public function testTtlUsesMaximumPossibleLifetime()
|
81 | 83 | $this->assertEquals(70, $cacheEntry->getTTL());
|
82 | 84 | }
|
83 | 85 |
|
| 86 | + public function testCacheEntryShouldBeSerializableWithIgBinaryWithoutWarning() |
| 87 | + { |
| 88 | + $request = new Request( |
| 89 | + 'GET', |
| 90 | + 'test.local', |
| 91 | + [], |
| 92 | + 'Sample body' // Always include a body in the request to be sure there is a stream in it |
| 93 | + ); |
| 94 | + $response = new Response( |
| 95 | + 200, [ |
| 96 | + 'Cache-Control' => 'max-age=60', |
| 97 | + ], |
| 98 | + 'Test content' |
| 99 | + ); |
| 100 | + $cacheEntry = new CacheEntry($request, $response, $this->makeDateTimeOffset(10)); |
| 101 | + |
| 102 | + if(extension_loaded('igbinary')) { |
| 103 | + /** |
| 104 | + * @var CacheEntry $cacheEntryPostDeserialization |
| 105 | + */ |
| 106 | + $cacheEntryPostDeserialization = igbinary_unserialize(igbinary_serialize($cacheEntry)); |
| 107 | + $this->assertEquals((string)$cacheEntry->getOriginalRequest()->getBody(), (string)$cacheEntryPostDeserialization->getOriginalRequest()->getBody()); |
| 108 | + $this->assertEquals((string)$cacheEntry->getOriginalResponse()->getBody(), (string)$cacheEntryPostDeserialization->getOriginalResponse()->getBody()); |
| 109 | + } else { |
| 110 | + $this->addWarning('Extension igbinary not loaded, not asserting serialization.'); |
| 111 | + } |
| 112 | + } |
| 113 | + |
84 | 114 | private function setResponseHeader($name, $value)
|
85 | 115 | {
|
86 | 116 | $this->responseHeaders[$name] = [$value];
|
|
0 commit comments