Skip to content

Commit 049e519

Browse files
Merge pull request #73 from mbabker/phpunit-10
Add support for PHPUnit 10; drop legacy PHP, PHPUnit, and Symfony support; CI updates
2 parents 0b78842 + ffc8030 commit 049e519

13 files changed

+75
-125
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,21 @@ jobs:
1111
strategy:
1212
matrix:
1313
php:
14-
- '7.1'
15-
- '7.2'
16-
- '7.3'
17-
- '7.4'
18-
- '8.0'
14+
- '8.1'
15+
- '8.2'
1916
dependency:
2017
- ''
2118
symfony:
22-
- '4.4.*'
23-
- '5.3.*'
19+
- '5.4.*'
20+
- '6.2.*'
2421
include:
25-
- php: '7.1'
26-
symfony: '4.4.*'
22+
- php: '8.1'
23+
symfony: '5.4.*'
2724
dependency: 'lowest'
28-
- php: '8.0'
29-
symfony: '6.0.*'
30-
exclude:
31-
- php: '7.1'
32-
symfony: '5.3.*'
3325
fail-fast: false
3426
steps:
3527
- name: Checkout
36-
uses: actions/checkout@v2
28+
uses: actions/checkout@v3
3729

3830
- name: Setup PHP
3931
uses: shivammathur/setup-php@v2
@@ -42,18 +34,12 @@ jobs:
4234
extensions: pcov
4335
tools: flex
4436

45-
- name: Prefer unstable Composer dependencies for Symfony 6.0
46-
if: matrix.symfony == '6.0.*'
47-
run: |
48-
composer config prefer-stable false
49-
composer config minimum-stability dev
50-
5137
- name: Get Composer Cache Directory
5238
id: composer-cache
5339
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
5440

5541
- name: Cache dependencies
56-
uses: actions/cache@v2
42+
uses: actions/cache@v3
5743
with:
5844
path: ${{ steps.composer-cache.outputs.dir }}
5945
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}

Partial/PartialNode.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,30 +99,20 @@ private static function childNode(ArrayNode $node, $childNodeName)
9999
*/
100100
private static function nodeChildrenProperty()
101101
{
102-
if (!isset(self::$nodeChildrenProperty)) {
103-
self::$nodeChildrenProperty = new \ReflectionProperty(
104-
ArrayNode::class,
105-
'children'
106-
);
107-
self::$nodeChildrenProperty->setAccessible(true);
108-
}
109-
110-
return self::$nodeChildrenProperty;
102+
return self::$nodeChildrenProperty ??= new \ReflectionProperty(
103+
ArrayNode::class,
104+
'children'
105+
);
111106
}
112107

113108
/**
114109
* @return \ReflectionProperty
115110
*/
116111
private static function nodePrototypeProperty()
117112
{
118-
if (!isset(self::$nodePrototypeProperty)) {
119-
self::$nodePrototypeProperty = new \ReflectionProperty(
120-
PrototypedArrayNode::class,
121-
'prototype'
122-
);
123-
self::$nodePrototypeProperty->setAccessible(true);
124-
}
125-
126-
return self::$nodePrototypeProperty;
113+
return self::$nodePrototypeProperty ??= new \ReflectionProperty(
114+
PrototypedArrayNode::class,
115+
'prototype'
116+
);
127117
}
128118
}

PhpUnit/AbstractConfigurationConstraint.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ abstract class AbstractConfigurationConstraint extends Constraint
1313

1414
public function __construct(ConfigurationInterface $configuration, $breadcrumbPath = null)
1515
{
16-
if (is_callable([Constraint::class, '__construct'])) {
17-
parent::__construct();
18-
}
19-
2016
$this->configuration = $configuration;
2117
$this->breadcrumbPath = $breadcrumbPath;
2218
}

PhpUnit/ConfigurationValuesAreInvalidConstraint.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
namespace Matthias\SymfonyConfigTest\PhpUnit;
44

55
use PHPUnit\Framework\Constraint\ExceptionMessage;
6+
use PHPUnit\Framework\Constraint\ExceptionMessageIsOrContains;
7+
use PHPUnit\Framework\Constraint\ExceptionMessageMatchesRegularExpression;
68
use PHPUnit\Framework\Constraint\ExceptionMessageRegularExpression;
9+
use PHPUnit\Framework\Constraint\MessageIsOrContains;
10+
use PHPUnit\Framework\Constraint\MessageMatchesRegularExpression;
711
use Symfony\Component\Config\Definition\ConfigurationInterface;
812
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
913

@@ -67,9 +71,31 @@ private function evaluateException(\Exception $exception, $description, $returnR
6771
private function createPhpUnitConstraint()
6872
{
6973
if ($this->useRegExp) {
74+
// Available since PHPUnit 10.0.15
75+
if (class_exists(ExceptionMessageMatchesRegularExpression::class)) {
76+
return new ExceptionMessageMatchesRegularExpression($this->expectedMessage);
77+
}
78+
79+
// Available between PHPUnit 10.0.0 and 10.0.14 (inclusive)
80+
if (class_exists(MessageMatchesRegularExpression::class)) {
81+
return new MessageMatchesRegularExpression('exception', $this->expectedMessage);
82+
}
83+
84+
// Available in PHPUnit 9.6
7085
return new ExceptionMessageRegularExpression($this->expectedMessage);
7186
}
7287

88+
// Available since PHPUnit 10.0.15
89+
if (class_exists(ExceptionMessageIsOrContains::class)) {
90+
return new ExceptionMessageIsOrContains($this->expectedMessage);
91+
}
92+
93+
// Available between PHPUnit 10.0.0 and 10.0.14 (inclusive)
94+
if (class_exists(MessageIsOrContains::class)) {
95+
return new MessageIsOrContains('exception', $this->expectedMessage);
96+
}
97+
98+
// Available in PHPUnit 9.6
7399
return new ExceptionMessage($this->expectedMessage);
74100
}
75101
}

Tests/Partial/Fixtures/ConfigurationStub.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ class ConfigurationStub implements ConfigurationInterface
1010
public function getConfigTreeBuilder()
1111
{
1212
$treeBuilder = new TreeBuilder('root');
13-
if (method_exists($treeBuilder, 'getRootNode')) {
14-
$root = $treeBuilder->getRootNode();
15-
} else {
16-
$root = $treeBuilder->root('root');
17-
}
13+
$root = $treeBuilder->getRootNode();
1814
$root
1915
->children()
2016
->arrayNode('only_test_this_node')

Tests/Partial/PartialNodeTest.php

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ class PartialNodeTest extends TestCase
1818
public function it_strips_children_that_are_not_in_the_given_path_with_one_name()
1919
{
2020
$treeBuilder = new TreeBuilder('root');
21-
if (method_exists($treeBuilder, 'getRootNode')) {
22-
$root = $treeBuilder->getRootNode();
23-
} else {
24-
$root = $treeBuilder->root('root');
25-
}
21+
$root = $treeBuilder->getRootNode();
2622
$root
2723
->children()
2824
->arrayNode('node_1')
@@ -49,11 +45,7 @@ public function it_strips_children_that_are_not_in_the_given_path_with_one_name(
4945
public function it_strips_children_that_are_not_in_the_given_path_with_several_names()
5046
{
5147
$treeBuilder = new TreeBuilder('root');
52-
if (method_exists($treeBuilder, 'getRootNode')) {
53-
$root = $treeBuilder->getRootNode();
54-
} else {
55-
$root = $treeBuilder->root('root');
56-
}
48+
$root = $treeBuilder->getRootNode();
5749
$root
5850
->children()
5951
->arrayNode('node_1')
@@ -91,11 +83,7 @@ public function it_strips_children_that_are_not_in_the_given_path_with_several_n
9183
public function it_strips_children_when_leaf_node_is_not_an_array()
9284
{
9385
$treeBuilder = new TreeBuilder('root');
94-
if (method_exists($treeBuilder, 'getRootNode')) {
95-
$root = $treeBuilder->getRootNode();
96-
} else {
97-
$root = $treeBuilder->root('root');
98-
}
86+
$root = $treeBuilder->getRootNode();
9987
$root
10088
->children()
10189
->arrayNode('node_1')
@@ -122,11 +110,7 @@ public function it_strips_children_when_leaf_node_is_not_an_array()
122110
public function it_does_not_crash_on_prototypes()
123111
{
124112
$treeBuilder = new TreeBuilder('root');
125-
if (method_exists($treeBuilder, 'getRootNode')) {
126-
$root = $treeBuilder->getRootNode();
127-
} else {
128-
$root = $treeBuilder->root('root');
129-
}
113+
$root = $treeBuilder->getRootNode();
130114
$root
131115
->prototype('array')
132116
->children()
@@ -156,11 +140,7 @@ public function it_does_not_crash_on_prototypes()
156140
public function it_fails_when_a_requested_child_node_does_not_exist()
157141
{
158142
$treeBuilder = new TreeBuilder('root');
159-
if (method_exists($treeBuilder, 'getRootNode')) {
160-
$root = $treeBuilder->getRootNode();
161-
} else {
162-
$root = $treeBuilder->root('root');
163-
}
143+
$root = $treeBuilder->getRootNode();
164144
$root
165145
->children()
166146
->arrayNode('sub_node')
@@ -181,11 +161,7 @@ public function it_fails_when_a_requested_child_node_does_not_exist()
181161
public function it_fails_when_a_requested_child_node_is_no_array_node_itself_and_path_not_empty()
182162
{
183163
$treeBuilder = new TreeBuilder('root');
184-
if (method_exists($treeBuilder, 'getRootNode')) {
185-
$root = $treeBuilder->getRootNode();
186-
} else {
187-
$root = $treeBuilder->root('root');
188-
}
164+
$root = $treeBuilder->getRootNode();
189165
$root
190166
->children()
191167
->arrayNode('sub_node')
@@ -203,7 +179,6 @@ public function it_fails_when_a_requested_child_node_is_no_array_node_itself_and
203179
private function nodeOnlyHasChild(ArrayNode $node, $nodeName)
204180
{
205181
$property = new \ReflectionProperty($node, 'children');
206-
$property->setAccessible(true);
207182
$children = $property->getValue($node);
208183

209184
$this->assertCount(1, $children);

Tests/Partial/PartialProcessorTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ class PartialProcessorTest extends TestCase
1515
public function it_processes_only_the_values_in_the_breadcrumb_path_for_a_given_node()
1616
{
1717
$treeBuilder = new TreeBuilder('root');
18-
if (method_exists($treeBuilder, 'getRootNode')) {
19-
$root = $treeBuilder->getRootNode();
20-
} else {
21-
$root = $treeBuilder->root('root');
22-
}
18+
$root = $treeBuilder->getRootNode();
2319
$root
2420
->children()
2521
->arrayNode('only_test_this_node')
@@ -55,7 +51,8 @@ public function it_processes_only_the_values_in_the_breadcrumb_path_for_a_given_
5551
'only_test_this_node' => [
5652
'scalar_node' => 'yes',
5753
],
58-
], $processedConfig
54+
],
55+
$processedConfig
5956
);
6057
}
6158

@@ -83,7 +80,8 @@ public function it_processes_only_the_values_in_the_given_breadcrumb_path_for_a_
8380
'only_test_this_node' => [
8481
'scalar_node' => 'yes',
8582
],
86-
], $processedConfig
83+
],
84+
$processedConfig
8785
);
8886
}
8987
}

Tests/PhpUnit/ConfigurationTestCaseTraitTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ public function it_fails_when_a_configuration_is_invalid_when_it_should_have_bee
6363
{
6464
$this->expectException(ExpectationFailedException::class);
6565

66-
if (method_exists($this, 'expectExceptionMessageMatches')) {
67-
$this->expectExceptionMessageMatches('/^The child (config|node) "required_value" (at path|under) "root" must be configured/');
68-
} else {
69-
$this->expectExceptionMessageRegExp('/^The child (config|node) "required_value" (at path|under) "root" must be configured/');
70-
}
66+
$this->expectExceptionMessageMatches('/^The child (config|node) "required_value" (at path|under) "root" must be configured/');
7167

7268
$this->assertConfigurationIsValid(
7369
[

Tests/PhpUnit/Fixtures/AlwaysValidConfiguration.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ class AlwaysValidConfiguration implements ConfigurationInterface
99
{
1010
public function getConfigTreeBuilder()
1111
{
12-
$treeBuilder = new TreeBuilder('root');
13-
if (!method_exists($treeBuilder, 'getRootNode')) {
14-
$treeBuilder->root('root');
15-
}
16-
17-
return $treeBuilder;
12+
return new TreeBuilder('root');
1813
}
1914
}

Tests/PhpUnit/Fixtures/ConfigurationWithMultipleArrayKeys.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ class ConfigurationWithMultipleArrayKeys implements ConfigurationInterface
1010
public function getConfigTreeBuilder()
1111
{
1212
$treeBuilder = new TreeBuilder('root');
13-
if (method_exists($treeBuilder, 'getRootNode')) {
14-
$root = $treeBuilder->getRootNode();
15-
} else {
16-
$root = $treeBuilder->root('root');
17-
}
13+
$root = $treeBuilder->getRootNode();
1814
$root
1915
->children()
2016
->arrayNode('array_node_1')

0 commit comments

Comments
 (0)