|
4 | 4 | * @copyright Copyright (C) Ibexa AS. All rights reserved. |
5 | 5 | * @license For full copyright and license information view LICENSE file distributed with this source code. |
6 | 6 | */ |
| 7 | +declare(strict_types=1); |
7 | 8 |
|
8 | 9 | namespace spec\Ibexa\HttpCache\ResponseTagger\Delegator; |
9 | 10 |
|
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; |
12 | 13 | use Ibexa\HttpCache\ResponseTagger\Delegator\DispatcherTagger; |
| 14 | +use Ibexa\HttpCache\ResponseTagger\Value\ContentInfoTagger; |
| 15 | +use Ibexa\HttpCache\ResponseTagger\Value\LocationTagger; |
13 | 16 | use PhpSpec\ObjectBehavior; |
14 | 17 |
|
15 | | -class DispatcherTaggerSpec extends ObjectBehavior |
| 18 | +final class DispatcherTaggerSpec extends ObjectBehavior |
16 | 19 | { |
17 | | - public function let(ResponseTagger $taggerOne, ResponseTagger $taggerTwo): void |
| 20 | + public function let(ContentInfoTagger $contentInfoTagger, LocationTagger $locationTagger): void |
18 | 21 | { |
19 | | - $this->beConstructedWith([$taggerOne, $taggerTwo]); |
| 22 | + $this->beConstructedWith([$contentInfoTagger, $locationTagger]); |
20 | 23 | } |
21 | 24 |
|
22 | 25 | public function it_is_initializable(): void |
23 | 26 | { |
24 | 27 | $this->shouldHaveType(DispatcherTagger::class); |
25 | 28 | } |
26 | 29 |
|
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 |
31 | 33 | ): void { |
32 | | - $this->tag($value); |
| 34 | + $contentInfo = new ContentInfo(['id' => 1, 'contentTypeId' => 2]); |
33 | 35 |
|
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(); |
36 | 58 | } |
37 | 59 | } |
0 commit comments