|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
4
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace spec\eZ\Bundle\EzPublishCoreBundle\EventSubscriber; |
|
7
|
|
|
|
|
8
|
|
|
use eZ\Publish\Core\MVC\Symfony\Cache\Http\ResponseConfigurator\ResponseCacheConfigurator; |
|
9
|
|
|
use eZ\Publish\Core\MVC\Symfony\Cache\Http\ResponseTagger\ResponseTagger; |
|
10
|
|
|
use eZ\Publish\Core\MVC\Symfony\View\CachableView; |
|
11
|
|
|
use eZ\Publish\Core\MVC\Symfony\View\View; |
|
12
|
|
|
use PhpSpec\ObjectBehavior; |
|
13
|
|
|
use Prophecy\Argument; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
17
|
|
|
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; |
|
18
|
|
|
|
|
19
|
|
|
class HttpCacheResponseSubscriberSpec extends ObjectBehavior |
|
20
|
|
|
{ |
|
21
|
|
|
public function let( |
|
22
|
|
|
FilterResponseEvent $event, |
|
23
|
|
|
Request $request, |
|
24
|
|
|
Response $response, |
|
25
|
|
|
ParameterBag $requestAttributes, |
|
26
|
|
|
ResponseCacheConfigurator $configurator, |
|
27
|
|
|
ResponseTagger $dispatcherTagger |
|
28
|
|
|
) { |
|
29
|
|
|
$request->attributes = $requestAttributes; |
|
|
|
|
|
|
30
|
|
|
$event->getRequest()->willReturn($request); |
|
31
|
|
|
$event->getResponse()->willReturn($response); |
|
32
|
|
|
|
|
33
|
|
|
$this->beConstructedWith($configurator, $dispatcherTagger); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function it_does_not_enable_cache_if_the_view_is_not_a_cachableview( |
|
37
|
|
|
FilterResponseEvent $event, |
|
38
|
|
|
ResponseCacheConfigurator $configurator, |
|
39
|
|
|
ParameterBag $requestAttributes, |
|
40
|
|
|
View $nonCachableView |
|
41
|
|
|
) { |
|
42
|
|
|
$requestAttributes->get('view')->willReturn($nonCachableView); |
|
43
|
|
|
$configurator->enableCache()->shouldNotBecalled(); |
|
44
|
|
|
|
|
45
|
|
|
$this->configureCache($event); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function it_does_not_enable_cache_if_it_is_disabled_in_the_view( |
|
49
|
|
|
FilterResponseEvent $event, |
|
50
|
|
|
ResponseCacheConfigurator $configurator, |
|
51
|
|
|
CachableView $view, |
|
52
|
|
|
ParameterBag $requestAttributes |
|
53
|
|
|
) { |
|
54
|
|
|
$requestAttributes->get('view')->willReturn($view); |
|
55
|
|
|
$view->isCacheEnabled()->willReturn(false); |
|
56
|
|
|
$configurator->enableCache()->shouldNotBecalled(); |
|
57
|
|
|
|
|
58
|
|
|
$this->configureCache($event); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function it_enables_cache( |
|
62
|
|
|
FilterResponseEvent $event, |
|
63
|
|
|
ResponseCacheConfigurator $configurator, |
|
64
|
|
|
CachableView $view, |
|
65
|
|
|
ParameterBag $requestAttributes, |
|
66
|
|
|
ResponseTagger $dispatcherTagger |
|
67
|
|
|
) { |
|
68
|
|
|
$requestAttributes->get('view')->willReturn($view); |
|
69
|
|
|
$view->isCacheEnabled()->willReturn(true); |
|
70
|
|
|
|
|
71
|
|
|
$this->configureCache($event); |
|
72
|
|
|
|
|
73
|
|
|
$configurator->enableCache(Argument::type(Response::class))->shouldHaveBeenCalled(); |
|
74
|
|
|
$configurator->setSharedMaxAge(Argument::type(Response::class))->shouldHaveBeenCalled(); |
|
75
|
|
|
$dispatcherTagger->tag($configurator, Argument::type(Response::class), $view)->shouldHaveBeenCalled(); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..