Skip to content

Commit 879d153

Browse files
committed
Added phpspec test
1 parent 3a56658 commit 879d153

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

spec/CachePluginSpec.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,54 @@ function it_serves_and_resaved_expired_response(CacheItemPoolInterface $pool, Ca
351351
$this->handleRequest($request, $next, function () {});
352352
}
353353

354+
function it_caches_private_responses_when_allowed(
355+
CacheItemPoolInterface $pool,
356+
CacheItemInterface $item,
357+
RequestInterface $request,
358+
ResponseInterface $response,
359+
StreamFactory $streamFactory,
360+
StreamInterface $stream
361+
) {
362+
$this->beConstructedThrough('clientCache', [$pool, $streamFactory, [
363+
'default_ttl' => 60,
364+
'cache_lifetime' => 1000,
365+
]]);
366+
367+
$httpBody = 'body';
368+
$stream->__toString()->willReturn($httpBody);
369+
$stream->isSeekable()->willReturn(true);
370+
$stream->rewind()->shouldBeCalled();
371+
372+
$request->getMethod()->willReturn('GET');
373+
$request->getUri()->willReturn('/');
374+
$request->getBody()->shouldBeCalled();
375+
376+
$response->getStatusCode()->willReturn(200);
377+
$response->getBody()->willReturn($stream);
378+
$response->getHeader('Cache-Control')->willReturn(['private'])->shouldBeCalled();
379+
$response->getHeader('Expires')->willReturn(array())->shouldBeCalled();
380+
$response->getHeader('ETag')->willReturn(array())->shouldBeCalled();
381+
382+
$pool->getItem('d20f64acc6e70b6079845f2fe357732929550ae1')->shouldBeCalled()->willReturn($item);
383+
$item->isHit()->willReturn(false);
384+
$item->expiresAfter(1060)->willReturn($item)->shouldBeCalled();
385+
386+
$item->set($this->getCacheItemMatcher([
387+
'response' => $response->getWrappedObject(),
388+
'body' => $httpBody,
389+
'expiresAt' => 0,
390+
'createdAt' => 0,
391+
'etag' => []
392+
]))->willReturn($item)->shouldBeCalled();
393+
$pool->save(Argument::any())->shouldBeCalled();
394+
395+
$next = function (RequestInterface $request) use ($response) {
396+
return new FulfilledPromise($response->getWrappedObject());
397+
};
398+
399+
$this->handleRequest($request, $next, function () {});
400+
}
401+
354402

355403
/**
356404
* Private function to match cache item data.

0 commit comments

Comments
 (0)