Skip to content

Commit 1916731

Browse files
alongoszadamwojs
andauthored
IBX-8471: Upgraded codebase to Symfony 7 (#59)
* [Composer] Bumped Symfony packages requirements to ^7.2 * [Composer] Bumped 3rd party packages compatible with for Symfony 7 * Removed fos_http_cache.tags.annotations.enabled parameter from prepended configuration * Added missing return statement to Ibexa\Bundle\HttpCache\IbexaHttpCacheBundle::getContainerExtension * Fixed incompatible Ibexa\HttpCache\ProxyClient\Varnish::queueRequest method declaration * Fixed incompatible Ibexa\HttpCache\Handler\TagHandler::tagSymfonyResponse method declaration * [Composer] Switch to friendsofsymfony/http-cache-bundle fork * [Composer] Added guzzlehttp/psr7 as a development dependency * [Tests] Updated specs after upgrade --------- Co-authored-by: Adam Wójs <[email protected]>
1 parent a7eee2c commit 1916731

File tree

11 files changed

+73
-45
lines changed

11 files changed

+73
-45
lines changed

composer.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,30 @@
1414
],
1515
"require": {
1616
"php": " >=8.3",
17-
"friendsofsymfony/http-cache": "^2.9",
18-
"friendsofsymfony/http-cache-bundle": "^2.8",
17+
"friendsofsymfony/http-cache": "^3.1",
18+
"ibexa/fos-http-cache-bundle": "^3.0",
1919
"ibexa/core": "~5.0.x-dev",
2020
"ibexa/rest": "~5.0.x-dev",
2121
"php-http/curl-client": "^2.1",
2222
"psr/http-client": "^1.0",
23-
"symfony/config": "^6.4",
24-
"symfony/dependency-injection": "^6.4",
25-
"symfony/event-dispatcher": "^6.4",
26-
"symfony/http-foundation": "^6.4",
27-
"symfony/http-kernel": "^6.4",
28-
"symfony/routing": "^6.4",
29-
"symfony/yaml": "^6.4",
23+
"symfony/config": "^7.2",
24+
"symfony/dependency-injection": "^7.2",
25+
"symfony/event-dispatcher": "^7.2",
26+
"symfony/http-foundation": "^7.2",
27+
"symfony/http-kernel": "^7.2",
28+
"symfony/routing": "^7.2",
29+
"symfony/yaml": "^7.2",
3030
"toflar/psr6-symfony-http-cache-store": "^4.2"
3131
},
3232
"require-dev": {
33+
"guzzlehttp/psr7": "^2.7",
3334
"ibexa/code-style": "~2.0.0",
3435
"ibexa/doctrine-schema": "~5.0.x-dev",
3536
"ibexa/rector": "~5.0.x-dev",
36-
"matthiasnoback/symfony-dependency-injection-test": "^4.3",
37+
"matthiasnoback/symfony-dependency-injection-test": "^5.0",
3738
"phpspec/phpspec": "^7.1",
3839
"phpunit/phpunit": "^9.6",
39-
"symfony/phpunit-bridge": "^6.4"
40+
"symfony/phpunit-bridge": "^7.2"
4041
},
4142
"autoload": {
4243
"psr-4": {

spec/EventSubscriber/RestKernelViewSubscriberSpec.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function it_writes_tags_on_section(
9090
$request->isMethodCacheable()->willReturn(true);
9191
$attributes->get('is_rest_request')->willReturn(true);
9292

93-
$tagHandler->addTags(['s5'])->shouldBeCalled();
93+
$tagHandler->addTags(['s5'])->shouldBeCalled()->willReturn($tagHandler);
9494

9595
$event = new ViewEvent(
9696
$kernel->getWrappedObject(),
@@ -142,7 +142,7 @@ public function it_writes_tags_on_content_type_defined(
142142
$request->isMethodCacheable()->willReturn(true);
143143
$attributes->get('is_rest_request')->willReturn(true);
144144

145-
$tagHandler->addTags(['t4'])->shouldBeCalled();
145+
$tagHandler->addTags(['t4'])->shouldBeCalled()->willReturn($tagHandler);
146146

147147
$event = new ViewEvent(
148148
$kernel->getWrappedObject(),
@@ -197,7 +197,7 @@ public function it_writes_tags_on_rest_content_type_defined(
197197
$request->isMethodCacheable()->willReturn(true);
198198
$attributes->get('is_rest_request')->willReturn(true);
199199

200-
$tagHandler->addTags(['t4'])->shouldBeCalled();
200+
$tagHandler->addTags(['t4'])->shouldBeCalled()->willReturn($tagHandler);
201201

202202
$event = new ViewEvent(
203203
$kernel->getWrappedObject(),
@@ -258,7 +258,7 @@ public function it_writes_tags_on_rest_content_type_group_ref_defined(
258258
$request->isMethodCacheable()->willReturn(true);
259259
$attributes->get('is_rest_request')->willReturn(true);
260260

261-
$tagHandler->addTags(['t4', 'tg2'])->shouldBeCalled();
261+
$tagHandler->addTags(['t4', 'tg2'])->shouldBeCalled()->willReturn($tagHandler);
262262

263263
$event = new ViewEvent(
264264
$kernel->getWrappedObject(),
@@ -287,7 +287,7 @@ public function it_writes_tags_on_rest_content_type_group_list(
287287
$request->isMethodCacheable()->willReturn(true);
288288
$attributes->get('is_rest_request')->willReturn(true);
289289

290-
$tagHandler->addTags(['tg2'])->shouldBeCalled();
290+
$tagHandler->addTags(['tg2'])->shouldBeCalled()->willReturn($tagHandler);
291291

292292
$event = new ViewEvent(
293293
$kernel->getWrappedObject(),
@@ -318,7 +318,7 @@ public function it_writes_tags_on_rest_version_list(
318318
$request->isMethodCacheable()->willReturn(true);
319319
$attributes->get('is_rest_request')->willReturn(true);
320320

321-
$tagHandler->addTags(['c33', 'cv33'])->shouldBeCalled();
321+
$tagHandler->addTags(['c33', 'cv33'])->shouldBeCalled()->willReturn($tagHandler);
322322

323323
$event = new ViewEvent(
324324
$kernel->getWrappedObject(),

spec/EventSubscriber/UserContextSubscriberSpec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function it_tags_response_with_no_prefix(
111111
$response->isCacheable()->willReturn(true);
112112
$responseHeaders->get(Argument::exact('Content-Type'))->willReturn('application/vnd.fos.user-context-hash');
113113
$response->getTtl()->willReturn(100);
114-
$responseHeaders->set(Argument::exact('xkey'), Argument::exact('ez-user-context-hash'))->willReturn(null);
114+
$responseHeaders->set(Argument::exact('xkey'), Argument::exact('ez-user-context-hash'));
115115

116116
$prefixService->getRepositoryPrefix()->willReturn('');
117117

@@ -137,7 +137,7 @@ public function it_tags_response_with_a_prefix(
137137
$response->getTtl()->willReturn(100);
138138

139139
$prefixService->getRepositoryPrefix()->willReturn('1');
140-
$responseHeaders->set(Argument::exact('xkey'), Argument::exact('1ez-user-context-hash'))->willReturn(null);
140+
$responseHeaders->set(Argument::exact('xkey'), Argument::exact('1ez-user-context-hash'));
141141

142142
$event = new ResponseEvent(
143143
$kernel->getWrappedObject(),

spec/EventSubscriber/XLocationIdResponseSubscriberSpec.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function it_rewrite_header_with_location_info(
7272
])
7373
);
7474

75-
$tagHandler->addTags([
75+
$tags = [
7676
'l123',
7777
'pl2',
7878
'p1',
@@ -81,7 +81,9 @@ public function it_rewrite_header_with_location_info(
8181
'c101',
8282
'ct3',
8383
'l120',
84-
])->shouldBecalled();
84+
];
85+
86+
$tagHandler->addTags($tags)->shouldBecalled()->willReturn($tagHandler);
8587
$responseHeaders->remove('X-Location-Id')->shouldBecalled();
8688

8789
$event = new ResponseEvent(
@@ -109,7 +111,7 @@ public function it_rewrite_header_on_not_found_location(
109111

110112
$repository->sudo(new AnyValueToken())->willThrow(new NotFoundException('id', 123));
111113

112-
$tagHandler->addTags(['l123', 'p123'])->shouldBecalled();
114+
$tagHandler->addTags(['l123', 'p123'])->shouldBecalled()->willReturn($tagHandler);
113115
$responseHeaders->remove('X-Location-Id')->shouldBecalled();
114116

115117
$event = new ResponseEvent(
@@ -137,7 +139,7 @@ public function it_rewrite_header_also_in_unofficial_plural_form_and_merges_exis
137139

138140
$repository->sudo(new AnyValueToken())->willThrow(new NotFoundException('id', 123));
139141

140-
$tagHandler->addTags(['l123', 'p123', 'l34', 'p34'])->shouldBeCalled();
142+
$tagHandler->addTags(['l123', 'p123', 'l34', 'p34'])->shouldBeCalled()->willReturn($tagHandler);
141143
$responseHeaders->remove('X-Location-Id')->shouldBeCalled();
142144

143145
$event = new ResponseEvent(

spec/ProxyClient/VarnishSpec.php

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
namespace spec\Ibexa\HttpCache\ProxyClient;
99

1010
use FOS\HttpCache\ProxyClient\Dispatcher;
11-
use Http\Message\RequestFactory;
1211
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
1312
use PhpSpec\ObjectBehavior;
1413
use Prophecy\Argument;
14+
use Psr\Http\Message\RequestFactoryInterface;
1515
use Psr\Http\Message\RequestInterface;
1616

1717
class VarnishSpec extends ObjectBehavior
@@ -24,7 +24,7 @@ class VarnishSpec extends ObjectBehavior
2424
public function let(
2525
ConfigResolverInterface $configResolver,
2626
Dispatcher $httpDispatcher,
27-
RequestFactory $messageFactory,
27+
RequestFactoryInterface $messageFactory,
2828
RequestInterface $request
2929
): void {
3030
$messageFactory->createRequest(
@@ -34,12 +34,18 @@ public function let(
3434
Argument::any()
3535
)->willReturn($request);
3636

37+
$request->withHeader(
38+
Argument::any(),
39+
Argument::any()
40+
)->willReturn($request);
41+
3742
$this->beConstructedWith($configResolver, $httpDispatcher, [], $messageFactory);
3843
}
3944

4045
public function it_should_purge_with_additional_token_header_when_configuration_key_with_token_is_not_null(
4146
ConfigResolverInterface $configResolver,
42-
RequestFactory $messageFactory
47+
RequestFactoryInterface $messageFactory,
48+
RequestInterface $request
4349
): void {
4450
$configResolver->hasParameter('http_cache.varnish_invalidate_token')->willReturn(true);
4551
$configResolver->getParameter('http_cache.varnish_invalidate_token')->willReturn('__TOKEN__');
@@ -48,27 +54,31 @@ public function it_should_purge_with_additional_token_header_when_configuration_
4854

4955
$this->requestShouldHaveBeenCreatedWithHeaders(
5056
array_merge(self::REQUEST_HEADERS, ['X-Invalidate-Token' => '__TOKEN__']),
51-
$messageFactory
57+
$messageFactory,
58+
$request
5259
);
5360
}
5461

5562
public function it_should_purge_without_additional_token_header_when_configuration_key_with_token_do_not_exist_in_configuration(
5663
ConfigResolverInterface $configResolver,
57-
RequestFactory $messageFactory
64+
RequestFactoryInterface $messageFactory,
65+
RequestInterface $request
5866
): void {
5967
$configResolver->hasParameter('http_cache.varnish_invalidate_token')->willReturn(false);
6068

6169
$this->purge(self::URI, self::REQUEST_HEADERS);
6270

6371
$this->requestShouldHaveBeenCreatedWithHeaders(
6472
self::REQUEST_HEADERS,
65-
$messageFactory
73+
$messageFactory,
74+
$request
6675
);
6776
}
6877

6978
public function it_should_purge_without_additional_token_header_when_configuration_key_with_token_exists_but_is_null(
7079
ConfigResolverInterface $configResolver,
71-
RequestFactory $messageFactory
80+
RequestFactoryInterface $messageFactory,
81+
RequestInterface $request
7282
): void {
7383
$configResolver->hasParameter('http_cache.varnish_invalidate_token')->willReturn(true);
7484
$configResolver->getParameter('http_cache.varnish_invalidate_token')->willReturn(null);
@@ -77,17 +87,23 @@ public function it_should_purge_without_additional_token_header_when_configurati
7787

7888
$this->requestShouldHaveBeenCreatedWithHeaders(
7989
self::REQUEST_HEADERS,
80-
$messageFactory
90+
$messageFactory,
91+
$request
8192
);
8293
}
8394

84-
private function requestShouldHaveBeenCreatedWithHeaders(array $headers, RequestFactory $messageFactory): void
85-
{
95+
private function requestShouldHaveBeenCreatedWithHeaders(
96+
array $headers,
97+
RequestFactoryInterface $messageFactory,
98+
RequestInterface $request
99+
): void {
86100
$messageFactory->createRequest(
87101
'PURGE',
88102
self::URI,
89-
$headers,
90-
Argument::any()
91103
)->shouldHaveBeenCalled();
104+
105+
foreach ($headers as $name => $value) {
106+
$request->withHeader($name, $value)->shouldHaveBeenCalled();
107+
}
92108
}
93109
}

spec/ResponseTagger/Value/ContentInfoTaggerSpec.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
1212
use Ibexa\HttpCache\ResponseTagger\Value\ContentInfoTagger;
1313
use PhpSpec\ObjectBehavior;
14+
use Prophecy\Argument;
1415

1516
class ContentInfoTaggerSpec extends ObjectBehavior
1617
{
1718
public function let(ResponseTagger $tagHandler): void
1819
{
1920
$this->beConstructedWith($tagHandler);
21+
22+
$tagHandler->addTags(Argument::any())->willReturn($tagHandler);
2023
}
2124

2225
public function it_is_initializable(): void

spec/ResponseTagger/Value/LocationTaggerSpec.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class LocationTaggerSpec extends ObjectBehavior
1919
public function let(ResponseTagger $tagHandler): void
2020
{
2121
$this->beConstructedWith($tagHandler);
22+
23+
$tagHandler->addTags(Argument::any())->willReturn($tagHandler);
2224
}
2325

2426
public function it_is_initializable(): void

src/bundle/IbexaHttpCacheBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public function getContainerExtension(): ?ExtensionInterface
5454
if ($this->extension) {
5555
return $this->extension;
5656
}
57+
58+
return null;
5759
}
5860

5961
public function registerConfigParser(ContainerBuilder $container): void

src/bundle/Resources/config/prepend/fos_http_cache.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,3 @@ user_context:
1010
hash_cache_ttl: 600
1111
# NOTE: These are also defined/used in AppCache, in Varnish VCL, and Fastly VCL
1212
session_name_prefix: IBX_SESSION_ID
13-
14-
tags:
15-
annotations:
16-
enabled: false

src/lib/Handler/TagHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(
5555
$this->addTags(['ez-all']);
5656
}
5757

58-
public function tagSymfonyResponse(Response $response, $replace = false)
58+
public function tagSymfonyResponse(Response $response, bool $replace = false): static
5959
{
6060
$tags = [];
6161
if (!$replace && $response->headers->has($this->getTagsHeaderName())) {

0 commit comments

Comments
 (0)