Skip to content

Commit 31c7b18

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

File tree

14 files changed

+163
-102
lines changed

14 files changed

+163
-102
lines changed

phpstan-baseline.neon

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,13 @@ parameters:
609609
-
610610
message: '#^Call to an undefined method Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Content\:\:willReturn\(\)\.$#'
611611
identifier: method.notFound
612-
count: 1
612+
count: 2
613+
path: spec/ResponseTagger/Delegator/ContentValueViewTaggerSpec.php
614+
615+
-
616+
message: '#^Call to an undefined method spec\\Ibexa\\HttpCache\\ResponseTagger\\Delegator\\ContentValueViewTaggerSpec\:\:supports\(\)\.$#'
617+
identifier: method.notFound
618+
count: 2
613619
path: spec/ResponseTagger/Delegator/ContentValueViewTaggerSpec.php
614620

615621
-
@@ -627,7 +633,13 @@ parameters:
627633
-
628634
message: '#^Call to an undefined method spec\\Ibexa\\HttpCache\\ResponseTagger\\Delegator\\DispatcherTaggerSpec\:\:tag\(\)\.$#'
629635
identifier: method.notFound
630-
count: 1
636+
count: 2
637+
path: spec/ResponseTagger/Delegator/DispatcherTaggerSpec.php
638+
639+
-
640+
message: '#^Cannot call method willReturn\(\) on bool\.$#'
641+
identifier: method.nonObject
642+
count: 4
631643
path: spec/ResponseTagger/Delegator/DispatcherTaggerSpec.php
632644

633645
-
@@ -642,6 +654,12 @@ parameters:
642654
count: 1
643655
path: spec/ResponseTagger/Delegator/LocationValueViewTaggerSpec.php
644656

657+
-
658+
message: '#^Call to an undefined method spec\\Ibexa\\HttpCache\\ResponseTagger\\Delegator\\LocationValueViewTaggerSpec\:\:supports\(\)\.$#'
659+
identifier: method.notFound
660+
count: 1
661+
path: spec/ResponseTagger/Delegator/LocationValueViewTaggerSpec.php
662+
645663
-
646664
message: '#^Call to an undefined method spec\\Ibexa\\HttpCache\\ResponseTagger\\Delegator\\LocationValueViewTaggerSpec\:\:tag\(\)\.$#'
647665
identifier: method.notFound
@@ -661,21 +679,21 @@ parameters:
661679
path: spec/ResponseTagger/Value/ContentInfoTaggerSpec.php
662680

663681
-
664-
message: '#^Call to an undefined method FOS\\HttpCache\\ResponseTagger\:\:shouldNotHaveBeenCalled\(\)\.$#'
682+
message: '#^Call to an undefined method FOS\\HttpCache\\ResponseTagger\:\:willReturn\(\)\.$#'
665683
identifier: method.notFound
666684
count: 1
667685
path: spec/ResponseTagger/Value/ContentInfoTaggerSpec.php
668686

669687
-
670-
message: '#^Call to an undefined method FOS\\HttpCache\\ResponseTagger\:\:willReturn\(\)\.$#'
688+
message: '#^Call to an undefined method spec\\Ibexa\\HttpCache\\ResponseTagger\\Value\\ContentInfoTaggerSpec\:\:supports\(\)\.$#'
671689
identifier: method.notFound
672-
count: 1
690+
count: 2
673691
path: spec/ResponseTagger/Value/ContentInfoTaggerSpec.php
674692

675693
-
676694
message: '#^Call to an undefined method spec\\Ibexa\\HttpCache\\ResponseTagger\\Value\\ContentInfoTaggerSpec\:\:tag\(\)\.$#'
677695
identifier: method.notFound
678-
count: 3
696+
count: 2
679697
path: spec/ResponseTagger/Value/ContentInfoTaggerSpec.php
680698

681699
-
@@ -684,12 +702,6 @@ parameters:
684702
count: 1
685703
path: spec/ResponseTagger/Value/ContentInfoTaggerSpec.php
686704

687-
-
688-
message: '#^Method FOS\\HttpCache\\ResponseTagger\:\:addTags\(\) invoked with 0 parameters, 1 required\.$#'
689-
identifier: arguments.count
690-
count: 1
691-
path: spec/ResponseTagger/Value/ContentInfoTaggerSpec.php
692-
693705
-
694706
message: '#^Parameter \#1 \$tags of method FOS\\HttpCache\\ResponseTagger\:\:addTags\(\) expects array\<string\>, Prophecy\\Argument\\Token\\AnyValueToken given\.$#'
695707
identifier: argument.type
@@ -703,21 +715,21 @@ parameters:
703715
path: spec/ResponseTagger/Value/LocationTaggerSpec.php
704716

705717
-
706-
message: '#^Call to an undefined method FOS\\HttpCache\\ResponseTagger\:\:shouldNotHaveBeenCalled\(\)\.$#'
718+
message: '#^Call to an undefined method FOS\\HttpCache\\ResponseTagger\:\:willReturn\(\)\.$#'
707719
identifier: method.notFound
708720
count: 1
709721
path: spec/ResponseTagger/Value/LocationTaggerSpec.php
710722

711723
-
712-
message: '#^Call to an undefined method FOS\\HttpCache\\ResponseTagger\:\:willReturn\(\)\.$#'
724+
message: '#^Call to an undefined method spec\\Ibexa\\HttpCache\\ResponseTagger\\Value\\LocationTaggerSpec\:\:supports\(\)\.$#'
713725
identifier: method.notFound
714-
count: 1
726+
count: 2
715727
path: spec/ResponseTagger/Value/LocationTaggerSpec.php
716728

717729
-
718730
message: '#^Call to an undefined method spec\\Ibexa\\HttpCache\\ResponseTagger\\Value\\LocationTaggerSpec\:\:tag\(\)\.$#'
719731
identifier: method.notFound
720-
count: 4
732+
count: 3
721733
path: spec/ResponseTagger/Value/LocationTaggerSpec.php
722734

723735
-
@@ -729,7 +741,7 @@ parameters:
729741
-
730742
message: '#^Parameter \#1 \$tags of method FOS\\HttpCache\\ResponseTagger\:\:addTags\(\) expects array\<string\>, Prophecy\\Argument\\Token\\AnyValueToken given\.$#'
731743
identifier: argument.type
732-
count: 2
744+
count: 1
733745
path: spec/ResponseTagger/Value/LocationTaggerSpec.php
734746

735747
-
@@ -1122,24 +1134,6 @@ parameters:
11221134
count: 1
11231135
path: src/lib/ResponseTagger/Delegator/ContentValueViewTagger.php
11241136

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-
11431137
-
11441138
message: '#^Method Ibexa\\HttpCache\\ResponseTagger\\Delegator\\LocationValueViewTagger\:\:tag\(\) has no return type specified\.$#'
11451139
identifier: missingType.return

spec/ResponseTagger/Delegator/ContentValueViewTaggerSpec.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
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;
1719

18-
class ContentValueViewTaggerSpec extends ObjectBehavior
20+
final class ContentValueViewTaggerSpec extends ObjectBehavior
1921
{
2022
public function let(ResponseTagger $contentInfoTagger): void
2123
{
@@ -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: 9 additions & 4 deletions
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\Value;
910

1011
use FOS\HttpCache\ResponseTagger;
1112
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
13+
use Ibexa\Core\Repository\Values\Content\Location;
1214
use Ibexa\HttpCache\ResponseTagger\Value\ContentInfoTagger;
1315
use PhpSpec\ObjectBehavior;
1416
use Prophecy\Argument;
1517

16-
class ContentInfoTaggerSpec extends ObjectBehavior
18+
final class ContentInfoTaggerSpec extends ObjectBehavior
1719
{
1820
public function let(ResponseTagger $tagHandler): void
1921
{
@@ -27,11 +29,14 @@ public function it_is_initializable(): void
2729
$this->shouldHaveType(ContentInfoTagger::class);
2830
}
2931

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

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

3742
public function it_tags_with_content_and_content_type_id(ResponseTagger $tagHandler): void

spec/ResponseTagger/Value/LocationTaggerSpec.php

Lines changed: 8 additions & 4 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 spec\Ibexa\HttpCache\ResponseTagger\Value;
910

@@ -14,7 +15,7 @@
1415
use PhpSpec\ObjectBehavior;
1516
use Prophecy\Argument;
1617

17-
class LocationTaggerSpec extends ObjectBehavior
18+
final class LocationTaggerSpec extends ObjectBehavior
1819
{
1920
public function let(ResponseTagger $tagHandler): void
2021
{
@@ -28,11 +29,14 @@ public function it_is_initializable(): void
2829
$this->shouldHaveType(LocationTagger::class);
2930
}
3031

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

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

3842
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/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
}

0 commit comments

Comments
 (0)