Skip to content

Commit 3e34f29

Browse files
committed
fix sorting bug
Fixed incorrect assumption that the minimum priority is zero leading to an unsorted list of negative priorities.
1 parent dcff1d3 commit 3e34f29

File tree

6 files changed

+50
-1
lines changed

6 files changed

+50
-1
lines changed

Console/Descriptor/Descriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ protected function sortTaggedServicesByPriority(array $services): array
261261
{
262262
$maxPriority = [];
263263
foreach ($services as $service => $tags) {
264-
$maxPriority[$service] = 0;
264+
$maxPriority[$service] = \PHP_INT_MIN;
265265
foreach ($tags as $tag) {
266266
$currentPriority = $tag['priority'] ?? 0;
267267
if ($maxPriority[$service] < $currentPriority) {

Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public static function getContainerDefinitionsWithPriorityTags()
171171
$definition1 = new Definition('Full\\Qualified\\Class1');
172172
$definition2 = new Definition('Full\\Qualified\\Class2');
173173
$definition3 = new Definition('Full\\Qualified\\Class3');
174+
$definition4 = new Definition('Full\\Qualified\\Class4');
174175

175176
return [
176177
'definition_1' => $definition1
@@ -199,6 +200,13 @@ public static function getContainerDefinitionsWithPriorityTags()
199200
->setAbstract(false)
200201
->addTag('tag1', ['attr1' => 'val1', 'attr2' => 'val2', 'priority' => 0])
201202
->addTag('tag1', ['attr3' => 'val3', 'priority' => 40]),
203+
'definition_4' => $definition4
204+
->setPublic(true)
205+
->setSynthetic(true)
206+
->setFile('/path/to/file')
207+
->setLazy(false)
208+
->setAbstract(false)
209+
->addTag('tag1', ['priority' => 0]),
202210
];
203211
}
204212

Tests/Fixtures/Descriptor/builder_priority_tag.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@
6363
}
6464
]
6565
},
66+
"definition_4": {
67+
"class": "Full\\Qualified\\Class4",
68+
"public": true,
69+
"synthetic": true,
70+
"lazy": false,
71+
"shared": true,
72+
"abstract": false,
73+
"autowire": false,
74+
"autoconfigure": false,
75+
"file": "\/path\/to\/file",
76+
"tags": [
77+
{
78+
"name": "tag1",
79+
"parameters": {
80+
"priority": 0
81+
}
82+
}
83+
]
84+
},
6685
"definition_2": {
6786
"class": "Full\\Qualified\\Class2",
6887
"public": true,

Tests/Fixtures/Descriptor/builder_priority_tag.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ Definitions
4444
- Attr2: val2
4545
- Tag: `tag2`
4646

47+
### definition_4
48+
49+
- Class: `Full\Qualified\Class4`
50+
- Public: yes
51+
- Synthetic: yes
52+
- Lazy: no
53+
- Shared: yes
54+
- Abstract: no
55+
- Autowired: no
56+
- Autoconfigured: no
57+
- File: `/path/to/file`
58+
- Tag: `tag1`
59+
- Priority: 0
60+
4761
### definition_2
4862

4963
- Class: `Full\Qualified\Class2`

Tests/Fixtures/Descriptor/builder_priority_tag.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
" val1 val2 0
1010
definition_1 val1 30 Full\Qualified\Class1
1111
" val2
12+
definition_4 0 Full\Qualified\Class4
1213
definition_2 val1 val2 -20 Full\Qualified\Class2
1314
-------------- ------- ------- ---------- ------- -----------------------
1415

Tests/Fixtures/Descriptor/builder_priority_tag.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
<tag name="tag2"/>
3030
</tags>
3131
</definition>
32+
<definition id="definition_4" class="Full\Qualified\Class4" public="true" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="/path/to/file">
33+
<tags>
34+
<tag name="tag1">
35+
<parameter name="priority">0</parameter>
36+
</tag>
37+
</tags>
38+
</definition>
3239
<definition id="definition_2" class="Full\Qualified\Class2" public="true" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="/path/to/file">
3340
<tags>
3441
<tag name="tag1">

0 commit comments

Comments
 (0)