Skip to content

Commit 4877914

Browse files
GwendolenLynchNyholm
authored andcommitted
Updates to allow Symfony 5 (#63)
- Update symfony/config to allow ^5.0" - Update deprecated use of TreeBuilder
1 parent 3087216 commit 4877914

File tree

7 files changed

+67
-29
lines changed

7 files changed

+67
-29
lines changed

Tests/Partial/Fixtures/ConfigurationStub.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ class ConfigurationStub implements ConfigurationInterface
99
{
1010
public function getConfigTreeBuilder()
1111
{
12-
$treeBuilder = new TreeBuilder();
13-
$root = $treeBuilder->root('root');
12+
$treeBuilder = new TreeBuilder('root');
13+
if (method_exists($treeBuilder, 'getRootNode')) {
14+
$root = $treeBuilder->getRootNode();
15+
} else {
16+
$root = $treeBuilder->root('root');
17+
}
1418
$root
1519
->children()
1620
->arrayNode('only_test_this_node')

Tests/Partial/PartialNodeTest.php

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Matthias\SymfonyConfigTest\Partial\PartialNode;
88
use PHPUnit\Framework\TestCase;
99
use Symfony\Component\Config\Definition\ArrayNode;
10-
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1110
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1211
use Symfony\Component\Config\Definition\PrototypedArrayNode;
1312

@@ -18,8 +17,12 @@ class PartialNodeTest extends TestCase
1817
*/
1918
public function it_strips_children_that_are_not_in_the_given_path_with_one_name()
2019
{
21-
$treeBuilder = new TreeBuilder();
22-
$root = $treeBuilder->root('root');
20+
$treeBuilder = new TreeBuilder('root');
21+
if (method_exists($treeBuilder, 'getRootNode')) {
22+
$root = $treeBuilder->getRootNode();
23+
} else {
24+
$root = $treeBuilder->root('root');
25+
}
2326
$root
2427
->children()
2528
->arrayNode('node_1')
@@ -45,8 +48,12 @@ public function it_strips_children_that_are_not_in_the_given_path_with_one_name(
4548
*/
4649
public function it_strips_children_that_are_not_in_the_given_path_with_several_names()
4750
{
48-
$treeBuilder = new TreeBuilder();
49-
$root = $treeBuilder->root('root');
51+
$treeBuilder = new TreeBuilder('root');
52+
if (method_exists($treeBuilder, 'getRootNode')) {
53+
$root = $treeBuilder->getRootNode();
54+
} else {
55+
$root = $treeBuilder->root('root');
56+
}
5057
$root
5158
->children()
5259
->arrayNode('node_1')
@@ -83,8 +90,12 @@ public function it_strips_children_that_are_not_in_the_given_path_with_several_n
8390
*/
8491
public function it_strips_children_when_leaf_node_is_not_an_array()
8592
{
86-
$treeBuilder = new TreeBuilder();
87-
$root = $treeBuilder->root('root');
93+
$treeBuilder = new TreeBuilder('root');
94+
if (method_exists($treeBuilder, 'getRootNode')) {
95+
$root = $treeBuilder->getRootNode();
96+
} else {
97+
$root = $treeBuilder->root('root');
98+
}
8899
$root
89100
->children()
90101
->arrayNode('node_1')
@@ -110,9 +121,12 @@ public function it_strips_children_when_leaf_node_is_not_an_array()
110121
*/
111122
public function it_does_not_crash_on_prototypes()
112123
{
113-
$treeBuilder = new TreeBuilder();
114-
/** @var ArrayNodeDefinition $root */
115-
$root = $treeBuilder->root('root');
124+
$treeBuilder = new TreeBuilder('root');
125+
if (method_exists($treeBuilder, 'getRootNode')) {
126+
$root = $treeBuilder->getRootNode();
127+
} else {
128+
$root = $treeBuilder->root('root');
129+
}
116130
$root
117131
->prototype('array')
118132
->children()
@@ -141,8 +155,12 @@ public function it_does_not_crash_on_prototypes()
141155
*/
142156
public function it_fails_when_a_requested_child_node_does_not_exist()
143157
{
144-
$treeBuilder = new TreeBuilder();
145-
$root = $treeBuilder->root('root');
158+
$treeBuilder = new TreeBuilder('root');
159+
if (method_exists($treeBuilder, 'getRootNode')) {
160+
$root = $treeBuilder->getRootNode();
161+
} else {
162+
$root = $treeBuilder->root('root');
163+
}
146164
$root
147165
->children()
148166
->arrayNode('sub_node')
@@ -162,8 +180,12 @@ public function it_fails_when_a_requested_child_node_does_not_exist()
162180
*/
163181
public function it_fails_when_a_requested_child_node_is_no_array_node_itself_and_path_not_empty()
164182
{
165-
$treeBuilder = new TreeBuilder();
166-
$root = $treeBuilder->root('root');
183+
$treeBuilder = new TreeBuilder('root');
184+
if (method_exists($treeBuilder, 'getRootNode')) {
185+
$root = $treeBuilder->getRootNode();
186+
} else {
187+
$root = $treeBuilder->root('root');
188+
}
167189
$root
168190
->children()
169191
->arrayNode('sub_node')

Tests/Partial/PartialProcessorTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ class PartialProcessorTest extends TestCase
1414
*/
1515
public function it_processes_only_the_values_in_the_breadcrumb_path_for_a_given_node()
1616
{
17-
$treeBuilder = new TreeBuilder();
18-
$root = $treeBuilder->root('root');
17+
$treeBuilder = new TreeBuilder('root');
18+
if (method_exists($treeBuilder, 'getRootNode')) {
19+
$root = $treeBuilder->getRootNode();
20+
} else {
21+
$root = $treeBuilder->root('root');
22+
}
1923
$root
2024
->children()
2125
->arrayNode('only_test_this_node')

Tests/PhpUnit/Fixtures/AlwaysValidConfiguration.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ class AlwaysValidConfiguration implements ConfigurationInterface
99
{
1010
public function getConfigTreeBuilder()
1111
{
12-
$treeBuilder = new TreeBuilder();
13-
14-
$treeBuilder->root('root');
12+
$treeBuilder = new TreeBuilder('root');
13+
if (!method_exists($treeBuilder, 'getRootNode')) {
14+
$treeBuilder->root('root');
15+
}
1516

1617
return $treeBuilder;
1718
}

Tests/PhpUnit/Fixtures/ConfigurationWithMultipleArrayKeys.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ class ConfigurationWithMultipleArrayKeys implements ConfigurationInterface
99
{
1010
public function getConfigTreeBuilder()
1111
{
12-
$treeBuilder = new TreeBuilder();
13-
$rootNode = $treeBuilder->root('root');
14-
$rootNode
12+
$treeBuilder = new TreeBuilder('root');
13+
if (method_exists($treeBuilder, 'getRootNode')) {
14+
$root = $treeBuilder->getRootNode();
15+
} else {
16+
$root = $treeBuilder->root('root');
17+
}
18+
$root
1519
->children()
1620
->arrayNode('array_node_1')
1721
->isRequired()

Tests/PhpUnit/Fixtures/ConfigurationWithRequiredValue.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ class ConfigurationWithRequiredValue implements ConfigurationInterface
99
{
1010
public function getConfigTreeBuilder()
1111
{
12-
$treeBuilder = new TreeBuilder();
13-
14-
$rootNode = $treeBuilder->root('root');
15-
$rootNode
12+
$treeBuilder = new TreeBuilder('root');
13+
if (method_exists($treeBuilder, 'getRootNode')) {
14+
$root = $treeBuilder->getRootNode();
15+
} else {
16+
$root = $treeBuilder->root('root');
17+
}
18+
$root
1619
->isRequired()
1720
->children()
1821
->scalarNode('required_value')

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
],
1515
"require": {
1616
"php": "^7.1",
17-
"symfony/config": "^2.7 || ^3.4 || ^4.0"
17+
"symfony/config": "^2.7 || ^3.4 || ^4.0 || ^5.0"
1818
},
1919
"require-dev": {
2020
"phpunit/phpunit": "^7.0 || ^8.0"

0 commit comments

Comments
 (0)