Skip to content

Commit 8596b19

Browse files
minor symfony#22398 Enhancing integration test to show that "override" tags show up first (weaverryan)
This PR was merged into the 3.3-dev branch. Discussion ---------- Enhancing integration test to show that "override" tags show up first | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | not needed Relates a bit to symfony#22396, in that I'm clarifying and emphasizing the following types of situations: ```yml services: _instanceof: Symfony\Component\Security\Core\Authorization\Voter\VoterInterface: tags: # you probably shouldn't set priority here, but let's pretend we did - { name: security.voter, priority: 100 } AppBundle\Security\CoolPersonVoter: tags: - { name: security.voter, priority: 50 } ``` In the final `Definition`, the tags will appear in this order: * security.voter, priority 50 * security.voter, priority 100 It works the same for parent-child definitions. tl;dr; If a service has the same tag multiple times, the one that should be used should appear *earlier* in the Definition. The code already works that way - this test emphasizes it. Commits ------- e9b96e5 Enhancing integration test to show that "override" tags always show up first
2 parents 8e4e741 + e9b96e5 commit 8596b19

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function testInstanceofDefaultsAndParentDefinitionResolution()
135135
// all tags are kept
136136
$this->assertEquals(
137137
array(
138-
'foo_tag' => array(array('priority' => 100), array()),
138+
'foo_tag' => array(array('tag_option' => 'from_service'), array('tag_option' => 'from_instanceof')),
139139
'bar_tag' => array(array()),
140140
),
141141
$simpleService->getTags()
@@ -169,10 +169,10 @@ public function testInstanceofDefaultsAndParentDefinitionResolution()
169169
// tags inherit like normal
170170
$this->assertEquals(
171171
array(
172-
'foo_tag' => array(array('priority' => 100), array()),
172+
'foo_tag' => array(array('tag_option' => 'from_child_def'), array('tag_option' => 'from_parent_def'), array('tag_option' => 'from_instanceof')),
173173
'bar_tag' => array(array()),
174174
),
175-
$simpleService->getTags()
175+
$childDef2->getTags()
176176
);
177177
}
178178
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services_defaults_instanceof_parent.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
autowire: false
99
shared: false
1010
tags:
11-
- { name: foo_tag }
11+
- { name: foo_tag, tag_option: from_instanceof }
1212
calls:
1313
- [setSunshine, [bright]]
1414

@@ -20,8 +20,8 @@ services:
2020
service_simple:
2121
class: Symfony\Component\DependencyInjection\Tests\Compiler\IntegrationTestStub
2222
tags:
23-
- { name: foo_tag, priority: 100 }
24-
# calls from instanceof are kept, but this comes later
23+
- { name: foo_tag, tag_option: from_service }
24+
# calls from instanceof are kept, but this comes later
2525
calls:
2626
- [enableSummer, [true]]
2727
- [setSunshine, [warm]]
@@ -43,7 +43,12 @@ services:
4343
parent_service_with_class:
4444
abstract: true
4545
class: Symfony\Component\DependencyInjection\Tests\Compiler\IntegrationTestStub
46+
tags:
47+
- { name: foo_tag, tag_option: from_parent_def }
4648

4749
child_service_with_parent_instanceof:
4850
parent: parent_service_with_class
4951
shared: true
52+
inherit_tags: true
53+
tags:
54+
- { name: foo_tag, tag_option: from_child_def }

0 commit comments

Comments
 (0)