1
- # SymfonyConfigTest
1
+ # Symfony Config Test
2
2
3
3
* By Matthias Noback and contributors*
4
4
@@ -12,7 +12,7 @@ validity of the resulting config node tree, this library provides a PHPUnit test
12
12
13
13
Using Composer:
14
14
15
- php composer.phar require --dev matthiasnoback/symfony-config-test
15
+ $ composer require --dev matthiasnoback/symfony-config-test
16
16
17
17
## Usage
18
18
@@ -22,11 +22,15 @@ Then implement ``getConfiguration()``:
22
22
``` php
23
23
<?php
24
24
25
- class ConfigurationTest extends \PHPUnit_Framework_TestCase
25
+ use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
26
+ use PHPUnit\Framework\TestCase;
27
+ use App\Configuration;
28
+
29
+ class ConfigurationTest extends TestCase
26
30
{
27
31
use ConfigurationTestCaseTrait;
28
32
29
- protected function getConfiguration()
33
+ protected function getConfiguration(): Configuration
30
34
{
31
35
return new Configuration();
32
36
}
@@ -45,7 +49,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
45
49
46
50
class ConfigurationWithRequiredValue implements ConfigurationInterface
47
51
{
48
- public function getConfigTreeBuilder()
52
+ public function getConfigTreeBuilder(): TreeBuilder
49
53
{
50
54
$treeBuilder = new TreeBuilder();
51
55
@@ -70,16 +74,22 @@ When you provide an empty array as the value for this configuration, you would e
70
74
``` php
71
75
<?php
72
76
73
- class ConfigurationTest extends \PHPUnit_Framework_TestCase
77
+ use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
78
+ use PHPUnit\Framework\TestCase;
79
+
80
+ class ConfigurationTest extends TestCase
74
81
{
75
82
use ConfigurationTestCaseTrait;
76
83
77
- public function testValuesAreInvalidIfRequiredValueIsNotProvided()
84
+ /**
85
+ * @test
86
+ */
87
+ public function values_are_invalid_if_required_value_is_not_provided(): void
78
88
{
79
89
$this->assertConfigurationIsInvalid(
80
- array(
81
- array() // no values at all
82
- ) ,
90
+ [
91
+ [] // no values at all
92
+ ] ,
83
93
'required_value' // (part of) the expected exception message - optional
84
94
);
85
95
}
@@ -93,18 +103,24 @@ You may also want to verify that after processing an array of configuration valu
93
103
``` php
94
104
<?php
95
105
96
- class ConfigurationTest extends \PHPUnit_Framework_TestCase
106
+ use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
107
+ use PHPUnit\Framework\TestCase;
108
+
109
+ class ConfigurationTest extends TestCase
97
110
{
98
111
use ConfigurationTestCaseTrait;
99
112
100
- public function testProcessedValueContainsRequiredValue()
113
+ /**
114
+ * @test
115
+ */
116
+ public function processed_value_contains_required_value(): void
101
117
{
102
- $this->assertProcessedConfigurationEquals(array(
103
- array( 'required_value' => 'first value') ,
104
- array( 'required_value' => 'last value')
105
- ), array(
118
+ $this->assertProcessedConfigurationEquals([
119
+ [ 'required_value' => 'first value'] ,
120
+ [ 'required_value' => 'last value']
121
+ ], [
106
122
'required_value'=> 'last value'
107
- ) );
123
+ ] );
108
124
}
109
125
}
110
126
```
@@ -127,7 +143,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
127
143
128
144
class ConfigurationWithTwoBranches implements ConfigurationInterface
129
145
{
130
- public function getConfigTreeBuilder()
146
+ public function getConfigTreeBuilder(): TreeBuilder
131
147
{
132
148
$treeBuilder = new TreeBuilder();
133
149
@@ -164,18 +180,18 @@ provide `array_node_1` as the argument for the `$breadcrumbPath` parameter of th
164
180
/**
165
181
* @test
166
182
*/
167
- public function processed_configuration_for_array_node_1()
183
+ public function processed_configuration_for_array_node_1(): void
168
184
{
169
185
$this->assertProcessedConfigurationEquals(
170
186
array(
171
- array( 'array_node_1' => array( 'required_value_1' => 'original value')) ,
172
- array( 'array_node_1' => array( 'required_value_1' => 'final value'))
187
+ [ 'array_node_1' => [ 'required_value_1' => 'original value']] ,
188
+ [ 'array_node_1' => [ 'required_value_1' => 'final value']]
173
189
),
174
- array(
175
- 'array_node_1' => array(
190
+ [
191
+ 'array_node_1' => [
176
192
'required_value_1' => 'final value'
177
- )
178
- ) ,
193
+ ]
194
+ ] ,
179
195
// the path of the nodes you want to focus on in this test:
180
196
'array_node_1'
181
197
);
@@ -201,7 +217,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
201
217
202
218
class PrototypedConfiguration implements ConfigurationInterface
203
219
{
204
- public function getConfigTreeBuilder()
220
+ public function getConfigTreeBuilder(): TreeBuilder
205
221
{
206
222
$treeBuilder = new TreeBuilder();
207
223
@@ -231,19 +247,19 @@ requirements on `required_value` node, you can define its path as `array_node.*.
231
247
/**
232
248
* @test
233
249
*/
234
- public function processed_configuration_for_array_node_1()
250
+ public function processed_configuration_for_array_node_1(): void
235
251
{
236
252
$this->assertProcessedConfigurationEquals(
237
- array(
238
- array( 'array_node' => array( 'prototype_name' => null)) ,
239
- ) ,
240
- array(
241
- 'array_node' => array(
242
- 'prototype_name' => array(
253
+ [
254
+ [ 'array_node' => [ 'prototype_name' => null]] ,
255
+ ] ,
256
+ [
257
+ 'array_node' => [
258
+ 'prototype_name' => [
243
259
'default_value' => 'foobar'
244
- )
245
- )
246
- ) ,
260
+ ]
261
+ ]
262
+ ] ,
247
263
// the path of the nodes you want to focus on in this test:
248
264
'array_node.*.default_value'
249
265
);
0 commit comments