Skip to content

Commit 6512235

Browse files
committed
IBX-11553: Made response taggers more verbose instead of silently failing
1 parent 80ed217 commit 6512235

15 files changed

Lines changed: 133 additions & 82 deletions

phpstan-baseline.neon

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,24 +1122,6 @@ parameters:
11221122
count: 1
11231123
path: src/lib/ResponseTagger/Delegator/ContentValueViewTagger.php
11241124

1125-
-
1126-
message: '#^Method Ibexa\\HttpCache\\ResponseTagger\\Delegator\\DispatcherTagger\:\:__construct\(\) has parameter \$taggers with no value type specified in iterable type array\.$#'
1127-
identifier: missingType.iterableValue
1128-
count: 1
1129-
path: src/lib/ResponseTagger/Delegator/DispatcherTagger.php
1130-
1131-
-
1132-
message: '#^PHPDoc tag @var for property Ibexa\\HttpCache\\ResponseTagger\\Delegator\\DispatcherTagger\:\:\$taggers with type Ibexa\\Contracts\\HttpCache\\ResponseTagger\\ResponseTagger is incompatible with native type array\.$#'
1133-
identifier: property.phpDocType
1134-
count: 1
1135-
path: src/lib/ResponseTagger/Delegator/DispatcherTagger.php
1136-
1137-
-
1138-
message: '#^Property Ibexa\\HttpCache\\ResponseTagger\\Delegator\\DispatcherTagger\:\:\$taggers type has no value type specified in iterable type array\.$#'
1139-
identifier: missingType.iterableValue
1140-
count: 1
1141-
path: src/lib/ResponseTagger/Delegator/DispatcherTagger.php
1142-
11431125
-
11441126
message: '#^Method Ibexa\\HttpCache\\ResponseTagger\\Delegator\\LocationValueViewTagger\:\:tag\(\) has no return type specified\.$#'
11451127
identifier: missingType.return

spec/ResponseTagger/Delegator/ContentValueViewTaggerSpec.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
* @copyright Copyright (C) Ibexa AS. All rights reserved.
55
* @license For full copyright and license information view LICENSE file distributed with this source code.
66
*/
7+
declare(strict_types=1);
78

89
namespace spec\Ibexa\HttpCache\ResponseTagger\Delegator;
910

1011
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
1112
use Ibexa\Contracts\HttpCache\ResponseTagger\ResponseTagger;
1213
use Ibexa\Core\MVC\Symfony\View\ContentValueView;
1314
use Ibexa\Core\Repository\Values\Content\Content;
15+
use Ibexa\Core\Repository\Values\Content\Location;
1416
use Ibexa\Core\Repository\Values\Content\VersionInfo;
1517
use Ibexa\HttpCache\ResponseTagger\Delegator\ContentValueViewTagger;
1618
use PhpSpec\ObjectBehavior;
@@ -27,6 +29,19 @@ public function it_is_initializable(): void
2729
$this->shouldHaveType(ContentValueViewTagger::class);
2830
}
2931

32+
public function it_supports_content_value_view_with_content(ContentValueView $view): void
33+
{
34+
$content = new Content(['versionInfo' => new VersionInfo(['contentInfo' => new ContentInfo()])]);
35+
$view->getContent()->willReturn($content);
36+
37+
$this->supports($view)->shouldReturn(true);
38+
}
39+
40+
public function it_does_not_support_non_content_value_view(): void
41+
{
42+
$this->supports(new Location())->shouldReturn(false);
43+
}
44+
3045
public function it_delegates_tagging_of_the_content_info(
3146
ResponseTagger $contentInfoTagger,
3247
ContentValueView $view

spec/ResponseTagger/Delegator/DispatcherTaggerSpec.php

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,56 @@
44
* @copyright Copyright (C) Ibexa AS. All rights reserved.
55
* @license For full copyright and license information view LICENSE file distributed with this source code.
66
*/
7+
declare(strict_types=1);
78

89
namespace spec\Ibexa\HttpCache\ResponseTagger\Delegator;
910

10-
use Ibexa\Contracts\Core\Repository\Values\ValueObject;
11-
use Ibexa\Contracts\HttpCache\ResponseTagger\ResponseTagger;
11+
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
12+
use Ibexa\Core\Repository\Values\Content\Location;
1213
use Ibexa\HttpCache\ResponseTagger\Delegator\DispatcherTagger;
14+
use Ibexa\HttpCache\ResponseTagger\Value\ContentInfoTagger;
15+
use Ibexa\HttpCache\ResponseTagger\Value\LocationTagger;
1316
use PhpSpec\ObjectBehavior;
1417

15-
class DispatcherTaggerSpec extends ObjectBehavior
18+
final class DispatcherTaggerSpec extends ObjectBehavior
1619
{
17-
public function let(ResponseTagger $taggerOne, ResponseTagger $taggerTwo): void
20+
public function let(ContentInfoTagger $contentInfoTagger, LocationTagger $locationTagger): void
1821
{
19-
$this->beConstructedWith([$taggerOne, $taggerTwo]);
22+
$this->beConstructedWith([$contentInfoTagger, $locationTagger]);
2023
}
2124

2225
public function it_is_initializable(): void
2326
{
2427
$this->shouldHaveType(DispatcherTagger::class);
2528
}
2629

27-
public function it_calls_tag_on_every_tagger(
28-
ResponseTagger $taggerOne,
29-
ResponseTagger $taggerTwo,
30-
ValueObject $value
30+
public function it_calls_tag_only_on_taggers_that_support_the_value(
31+
ContentInfoTagger $contentInfoTagger,
32+
LocationTagger $locationTagger
3133
): void {
32-
$this->tag($value);
34+
$contentInfo = new ContentInfo(['id' => 1, 'contentTypeId' => 2]);
3335

34-
$taggerOne->tag($value)->shouldHaveBeenCalled();
35-
$taggerTwo->tag($value)->shouldHaveBeenCalled();
36+
$contentInfoTagger->supports($contentInfo)->willReturn(true);
37+
$locationTagger->supports($contentInfo)->willReturn(false);
38+
39+
$this->tag($contentInfo);
40+
41+
$contentInfoTagger->tag($contentInfo)->shouldHaveBeenCalled();
42+
$locationTagger->tag($contentInfo)->shouldNotHaveBeenCalled();
43+
}
44+
45+
public function it_does_not_call_tag_when_no_tagger_supports_the_value(
46+
ContentInfoTagger $contentInfoTagger,
47+
LocationTagger $locationTagger
48+
): void {
49+
$location = new Location(['id' => 1]);
50+
51+
$contentInfoTagger->supports($location)->willReturn(false);
52+
$locationTagger->supports($location)->willReturn(false);
53+
54+
$this->tag($location);
55+
56+
$contentInfoTagger->tag($location)->shouldNotHaveBeenCalled();
57+
$locationTagger->tag($location)->shouldNotHaveBeenCalled();
3658
}
3759
}

spec/ResponseTagger/Delegator/LocationValueViewTaggerSpec.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
* @copyright Copyright (C) Ibexa AS. All rights reserved.
55
* @license For full copyright and license information view LICENSE file distributed with this source code.
66
*/
7+
declare(strict_types=1);
78

89
namespace spec\Ibexa\HttpCache\ResponseTagger\Delegator;
910

11+
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
1012
use Ibexa\Contracts\HttpCache\ResponseTagger\ResponseTagger;
1113
use Ibexa\Core\MVC\Symfony\View\LocationValueView;
1214
use Ibexa\Core\Repository\Values\Content\Location;
1315
use Ibexa\HttpCache\ResponseTagger\Delegator\LocationValueViewTagger;
1416
use PhpSpec\ObjectBehavior;
1517

16-
class LocationValueViewTaggerSpec extends ObjectBehavior
18+
final class LocationValueViewTaggerSpec extends ObjectBehavior
1719
{
1820
public function let(ResponseTagger $locationTagger): void
1921
{
@@ -25,6 +27,11 @@ public function it_is_initializable(): void
2527
$this->shouldHaveType(LocationValueViewTagger::class);
2628
}
2729

30+
public function it_does_not_support_non_location_value_view(): void
31+
{
32+
$this->supports(new ContentInfo())->shouldReturn(false);
33+
}
34+
2835
public function it_delegates_tagging_of_the_location(
2936
ResponseTagger $locationTagger,
3037
LocationValueView $view

spec/ResponseTagger/Value/ContentInfoTaggerSpec.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use FOS\HttpCache\ResponseTagger;
1111
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
12+
use Ibexa\Core\Repository\Values\Content\Location;
1213
use Ibexa\HttpCache\ResponseTagger\Value\ContentInfoTagger;
1314
use PhpSpec\ObjectBehavior;
1415
use Prophecy\Argument;
@@ -27,11 +28,14 @@ public function it_is_initializable(): void
2728
$this->shouldHaveType(ContentInfoTagger::class);
2829
}
2930

30-
public function it_ignores_non_content_info(ResponseTagger $tagHandler): void
31+
public function it_supports_content_info(): void
3132
{
32-
$this->tag(null);
33+
$this->supports(new ContentInfo())->shouldReturn(true);
34+
}
3335

34-
$tagHandler->addTags()->shouldNotHaveBeenCalled();
36+
public function it_does_not_support_non_content_info(): void
37+
{
38+
$this->supports(new Location())->shouldReturn(false);
3539
}
3640

3741
public function it_tags_with_content_and_content_type_id(ResponseTagger $tagHandler): void

spec/ResponseTagger/Value/LocationTaggerSpec.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ public function it_is_initializable(): void
2828
$this->shouldHaveType(LocationTagger::class);
2929
}
3030

31-
public function it_ignores_non_location(ResponseTagger $tagHandler): void
31+
public function it_supports_location(): void
3232
{
33-
$this->tag(null);
33+
$this->supports(new Location())->shouldReturn(true);
34+
}
3435

35-
$tagHandler->addTags(Argument::any())->shouldNotHaveBeenCalled();
36+
public function it_does_not_support_non_location(): void
37+
{
38+
$this->supports(new ContentInfo())->shouldReturn(false);
3639
}
3740

3841
public function it_tags_with_location_id_if_not_main_location(ResponseTagger $tagHandler): void

src/bundle/DependencyInjection/Compiler/ResponseTaggersPass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @copyright Copyright (C) Ibexa AS. All rights reserved.
55
* @license For full copyright and license information view LICENSE file distributed with this source code.
66
*/
7+
declare(strict_types=1);
78

89
namespace Ibexa\Bundle\HttpCache\DependencyInjection\Compiler;
910

@@ -15,7 +16,7 @@
1516
/**
1617
* Injects services tagged as "ibexa.cache.http.response.tagger" into the dispatcher.
1718
*/
18-
class ResponseTaggersPass implements CompilerPassInterface
19+
final readonly class ResponseTaggersPass implements CompilerPassInterface
1920
{
2021
public function process(ContainerBuilder $container): void
2122
{

src/bundle/Resources/config/view_cache.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,16 @@ services:
8383
Ibexa\HttpCache\ResponseTagger\Value\ContentInfoTagger:
8484
class: Ibexa\HttpCache\ResponseTagger\Value\ContentInfoTagger
8585
parent: ibexa.http_cache.view_cache.response_tagger.abstract_value
86+
arguments:
87+
$debug: '%kernel.debug%'
8688
tags:
8789
- {name: ibexa.cache.http.response.tagger}
8890

8991
Ibexa\HttpCache\ResponseTagger\Value\LocationTagger:
9092
class: Ibexa\HttpCache\ResponseTagger\Value\LocationTagger
9193
parent: ibexa.http_cache.view_cache.response_tagger.abstract_value
94+
arguments:
95+
$debug: '%kernel.debug%'
9296
tags:
9397
- {name: ibexa.cache.http.response.tagger}
9498

src/contracts/ResponseTagger/ResponseTagger.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @copyright Copyright (C) Ibexa AS. All rights reserved.
55
* @license For full copyright and license information view LICENSE file distributed with this source code.
66
*/
7+
declare(strict_types=1);
78

89
namespace Ibexa\Contracts\HttpCache\ResponseTagger;
910

@@ -14,8 +15,6 @@ interface ResponseTagger
1415
{
1516
/**
1617
* Extracts tags from a value.
17-
*
18-
* @param mixed $value
1918
*/
20-
public function tag($value);
19+
public function tag(mixed $value);
2120
}

src/lib/ResponseTagger/Delegator/ContentValueViewTagger.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,30 @@
44
* @copyright Copyright (C) Ibexa AS. All rights reserved.
55
* @license For full copyright and license information view LICENSE file distributed with this source code.
66
*/
7+
declare(strict_types=1);
78

89
namespace Ibexa\HttpCache\ResponseTagger\Delegator;
910

1011
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
1112
use Ibexa\Contracts\HttpCache\ResponseTagger\ResponseTagger;
1213
use Ibexa\Core\MVC\Symfony\View\ContentValueView;
14+
use Ibexa\HttpCache\ResponseTagger\Value\AbstractValueTagger;
1315

14-
class ContentValueViewTagger implements ResponseTagger
16+
class ContentValueViewTagger extends AbstractValueTagger
1517
{
16-
private ResponseTagger $contentInfoTagger;
18+
public function __construct(private readonly ResponseTagger $contentInfoTagger)
19+
{
20+
}
1721

18-
public function __construct(ResponseTagger $contentInfoTagger)
22+
public function supports(mixed $value): bool
1923
{
20-
$this->contentInfoTagger = $contentInfoTagger;
24+
return $value instanceof ContentValueView && $value->getContent() instanceof Content;
2125
}
2226

23-
public function tag($view)
27+
public function tag(mixed $value)
2428
{
25-
if (!$view instanceof ContentValueView || !($content = $view->getContent()) instanceof Content) {
26-
return $this;
27-
}
29+
/** @var \Ibexa\Core\MVC\Symfony\View\ContentValueView $value */
30+
$content = $value->getContent();
2831

2932
$contentInfo = $content->getVersionInfo()->getContentInfo();
3033
$this->contentInfoTagger->tag($contentInfo);

0 commit comments

Comments
 (0)