Skip to content

Commit 004004e

Browse files
Merge branch '4.3' into 4.4
* 4.3: Fix tests Fix deprecated phpunit annotation
2 parents aaaa8af + e053544 commit 004004e

23 files changed

+129
-163
lines changed

Tests/ConfigCacheFactoryTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212
namespace Symfony\Component\Config\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Config\ConfigCacheFactory;
1617

1718
class ConfigCacheFactoryTest extends TestCase
1819
{
19-
/**
20-
* @expectedException \InvalidArgumentException
21-
* @expectedExceptionMessage Invalid type for callback argument. Expected callable, but got "object".
22-
*/
20+
use ForwardCompatTestTrait;
21+
2322
public function testCacheWithInvalidCallback()
2423
{
24+
$this->expectException('InvalidArgumentException');
25+
$this->expectExceptionMessage('Invalid type for callback argument. Expected callable, but got "object".');
2526
$cacheFactory = new ConfigCacheFactory(true);
2627

2728
$cacheFactory->cache('file', new \stdClass());

Tests/Definition/ArrayNodeTest.php

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,36 @@ class ArrayNodeTest extends TestCase
2121
{
2222
use ForwardCompatTestTrait;
2323

24-
/**
25-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException
26-
*/
2724
public function testNormalizeThrowsExceptionWhenFalseIsNotAllowed()
2825
{
26+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
2927
$node = new ArrayNode('root');
3028
$node->normalize(false);
3129
}
3230

33-
/**
34-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
35-
* @expectedExceptionMessage Unrecognized option "foo" under "root"
36-
*/
3731
public function testExceptionThrownOnUnrecognizedChild()
3832
{
33+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException');
34+
$this->expectExceptionMessage('Unrecognized option "foo" under "root"');
3935
$node = new ArrayNode('root');
4036
$node->normalize(['foo' => 'bar']);
4137
}
4238

43-
/**
44-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
45-
* @expectedExceptionMessage Did you mean "alpha1", "alpha2"?
46-
*/
4739
public function testNormalizeWithProposals()
4840
{
41+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException');
42+
$this->expectExceptionMessage('Did you mean "alpha1", "alpha2"?');
4943
$node = new ArrayNode('root');
5044
$node->addChild(new ArrayNode('alpha1'));
5145
$node->addChild(new ArrayNode('alpha2'));
5246
$node->addChild(new ArrayNode('beta'));
5347
$node->normalize(['alpha3' => 'foo']);
5448
}
5549

56-
/**
57-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
58-
* @expectedExceptionMessage Available options are "alpha1", "alpha2".
59-
*/
6050
public function testNormalizeWithoutProposals()
6151
{
52+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException');
53+
$this->expectExceptionMessage('Available options are "alpha1", "alpha2".');
6254
$node = new ArrayNode('root');
6355
$node->addChild(new ArrayNode('alpha1'));
6456
$node->addChild(new ArrayNode('alpha2'));
@@ -204,24 +196,20 @@ public function getPreNormalizedNormalizedOrderedData()
204196
];
205197
}
206198

207-
/**
208-
* @expectedException \InvalidArgumentException
209-
* @expectedExceptionMessage Child nodes must be named.
210-
*/
211199
public function testAddChildEmptyName()
212200
{
201+
$this->expectException('InvalidArgumentException');
202+
$this->expectExceptionMessage('Child nodes must be named.');
213203
$node = new ArrayNode('root');
214204

215205
$childNode = new ArrayNode('');
216206
$node->addChild($childNode);
217207
}
218208

219-
/**
220-
* @expectedException \InvalidArgumentException
221-
* @expectedExceptionMessage A child node named "foo" already exists.
222-
*/
223209
public function testAddChildNameAlreadyExists()
224210
{
211+
$this->expectException('InvalidArgumentException');
212+
$this->expectExceptionMessage('A child node named "foo" already exists.');
225213
$node = new ArrayNode('root');
226214

227215
$childNode = new ArrayNode('foo');
@@ -231,12 +219,10 @@ public function testAddChildNameAlreadyExists()
231219
$node->addChild($childNodeWithSameName);
232220
}
233221

234-
/**
235-
* @expectedException \RuntimeException
236-
* @expectedExceptionMessage The node at path "foo" has no default value.
237-
*/
238222
public function testGetDefaultValueWithoutDefaultValue()
239223
{
224+
$this->expectException('RuntimeException');
225+
$this->expectExceptionMessage('The node at path "foo" has no default value.');
240226
$node = new ArrayNode('foo');
241227
$node->getDefaultValue();
242228
}

Tests/Definition/BaseNodeTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ public function testGetPathForChildNode($expected, array $params)
2626
$constructorArgs[] = $params[0];
2727

2828
if (isset($params[1])) {
29-
// Handle old PHPUnit version for PHP 5.5
30-
$parent = method_exists($this, 'createMock')
31-
? $this->createMock(NodeInterface::class)
32-
: $this->getMock(NodeInterface::class);
29+
$parent = $this->createMock(NodeInterface::class);
3330
$parent->method('getPath')->willReturn($params[1]);
3431

3532
$constructorArgs[] = $parent;

Tests/Definition/BooleanNodeTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
namespace Symfony\Component\Config\Tests\Definition;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Config\Definition\BooleanNode;
1617

1718
class BooleanNodeTest extends TestCase
1819
{
20+
use ForwardCompatTestTrait;
21+
1922
/**
2023
* @dataProvider getValidValues
2124
*/
@@ -48,10 +51,10 @@ public function getValidValues()
4851

4952
/**
5053
* @dataProvider getInvalidValues
51-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException
5254
*/
5355
public function testNormalizeThrowsExceptionOnInvalidValues($value)
5456
{
57+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
5558
$node = new BooleanNode('test');
5659
$node->normalize($value);
5760
}

Tests/Definition/Builder/ArrayNodeDefinitionTest.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Config\Tests\Definition\Builder;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1617
use Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition;
1718
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
@@ -21,6 +22,8 @@
2122

2223
class ArrayNodeDefinitionTest extends TestCase
2324
{
25+
use ForwardCompatTestTrait;
26+
2427
public function testAppendingSomeNode()
2528
{
2629
$parent = new ArrayNodeDefinition('root');
@@ -38,11 +41,11 @@ public function testAppendingSomeNode()
3841
}
3942

4043
/**
41-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
4244
* @dataProvider providePrototypeNodeSpecificCalls
4345
*/
4446
public function testPrototypeNodeSpecificOption($method, $args)
4547
{
48+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidDefinitionException');
4649
$node = new ArrayNodeDefinition('root');
4750

4851
$node->{$method}(...$args);
@@ -61,11 +64,9 @@ public function providePrototypeNodeSpecificCalls()
6164
];
6265
}
6366

64-
/**
65-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
66-
*/
6767
public function testConcreteNodeSpecificOption()
6868
{
69+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidDefinitionException');
6970
$node = new ArrayNodeDefinition('root');
7071
$node
7172
->addDefaultsIfNotSet()
@@ -74,11 +75,9 @@ public function testConcreteNodeSpecificOption()
7475
$node->getNode();
7576
}
7677

77-
/**
78-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
79-
*/
8078
public function testPrototypeNodesCantHaveADefaultValueWhenUsingDefaultChildren()
8179
{
80+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidDefinitionException');
8281
$node = new ArrayNodeDefinition('root');
8382
$node
8483
->defaultValue([])
@@ -319,12 +318,10 @@ public function testRequiresAtLeastOneElement()
319318
$this->addToAssertionCount(1);
320319
}
321320

322-
/**
323-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
324-
* @expectedExceptionMessage The path "root" should have at least 1 element(s) defined.
325-
*/
326321
public function testCannotBeEmpty()
327322
{
323+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException');
324+
$this->expectExceptionMessage('The path "root" should have at least 1 element(s) defined.');
328325
$node = new ArrayNodeDefinition('root');
329326
$node
330327
->cannotBeEmpty()
@@ -347,12 +344,10 @@ public function testSetDeprecated()
347344
$this->assertSame('The "root.foo" node is deprecated.', $deprecatedNode->getDeprecationMessage($deprecatedNode->getName(), $deprecatedNode->getPath()));
348345
}
349346

350-
/**
351-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
352-
* @expectedExceptionMessage ->cannotBeEmpty() is not applicable to concrete nodes at path "root"
353-
*/
354347
public function testCannotBeEmptyOnConcreteNode()
355348
{
349+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidDefinitionException');
350+
$this->expectExceptionMessage('->cannotBeEmpty() is not applicable to concrete nodes at path "root"');
356351
$node = new ArrayNodeDefinition('root');
357352
$node->cannotBeEmpty();
358353

Tests/Definition/Builder/BooleanNodeDefinitionTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212
namespace Symfony\Component\Config\Tests\Definition\Builder;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition;
1617

1718
class BooleanNodeDefinitionTest extends TestCase
1819
{
19-
/**
20-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
21-
* @expectedExceptionMessage ->cannotBeEmpty() is not applicable to BooleanNodeDefinition.
22-
*/
20+
use ForwardCompatTestTrait;
21+
2322
public function testCannotBeEmptyThrowsAnException()
2423
{
24+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidDefinitionException');
25+
$this->expectExceptionMessage('->cannotBeEmpty() is not applicable to BooleanNodeDefinition.');
2526
$def = new BooleanNodeDefinition('foo');
2627
$def->cannotBeEmpty();
2728
}

Tests/Definition/Builder/EnumNodeDefinitionTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
namespace Symfony\Component\Config\Tests\Definition\Builder;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Config\Definition\Builder\EnumNodeDefinition;
1617

1718
class EnumNodeDefinitionTest extends TestCase
1819
{
20+
use ForwardCompatTestTrait;
21+
1922
public function testWithOneValue()
2023
{
2124
$def = new EnumNodeDefinition('foo');
@@ -34,22 +37,18 @@ public function testWithOneDistinctValue()
3437
$this->assertEquals(['foo'], $node->getValues());
3538
}
3639

37-
/**
38-
* @expectedException \RuntimeException
39-
* @expectedExceptionMessage You must call ->values() on enum nodes.
40-
*/
4140
public function testNoValuesPassed()
4241
{
42+
$this->expectException('RuntimeException');
43+
$this->expectExceptionMessage('You must call ->values() on enum nodes.');
4344
$def = new EnumNodeDefinition('foo');
4445
$def->getNode();
4546
}
4647

47-
/**
48-
* @expectedException \InvalidArgumentException
49-
* @expectedExceptionMessage ->values() must be called with at least one value.
50-
*/
5148
public function testWithNoValues()
5249
{
50+
$this->expectException('InvalidArgumentException');
51+
$this->expectExceptionMessage('->values() must be called with at least one value.');
5352
$def = new EnumNodeDefinition('foo');
5453
$def->values([]);
5554
}

Tests/Definition/Builder/ExprBuilderTest.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
namespace Symfony\Component\Config\Tests\Definition\Builder;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1617

1718
class ExprBuilderTest extends TestCase
1819
{
20+
use ForwardCompatTestTrait;
21+
1922
public function testAlwaysExpression()
2023
{
2124
$test = $this->getTestBuilder()
@@ -164,11 +167,9 @@ public function castToArrayValues()
164167
yield [['value'], ['value']];
165168
}
166169

167-
/**
168-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
169-
*/
170170
public function testThenInvalid()
171171
{
172+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException');
172173
$test = $this->getTestBuilder()
173174
->ifString()
174175
->thenInvalid('Invalid value')
@@ -185,21 +186,17 @@ public function testThenUnsetExpression()
185186
$this->assertEquals([], $this->finalizeTestBuilder($test));
186187
}
187188

188-
/**
189-
* @expectedException \RuntimeException
190-
* @expectedExceptionMessage You must specify an if part.
191-
*/
192189
public function testEndIfPartNotSpecified()
193190
{
191+
$this->expectException('RuntimeException');
192+
$this->expectExceptionMessage('You must specify an if part.');
194193
$this->getTestBuilder()->end();
195194
}
196195

197-
/**
198-
* @expectedException \RuntimeException
199-
* @expectedExceptionMessage You must specify a then part.
200-
*/
201196
public function testEndThenPartNotSpecified()
202197
{
198+
$this->expectException('RuntimeException');
199+
$this->expectExceptionMessage('You must specify a then part.');
203200
$builder = $this->getTestBuilder();
204201
$builder->ifPart = 'test';
205202
$builder->end();

Tests/Definition/Builder/NodeBuilderTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,24 @@
1212
namespace Symfony\Component\Config\Tests\Definition\Builder;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Config\Definition\Builder\NodeBuilder as BaseNodeBuilder;
1617
use Symfony\Component\Config\Definition\Builder\VariableNodeDefinition as BaseVariableNodeDefinition;
1718

1819
class NodeBuilderTest extends TestCase
1920
{
20-
/**
21-
* @expectedException \RuntimeException
22-
*/
21+
use ForwardCompatTestTrait;
22+
2323
public function testThrowsAnExceptionWhenTryingToCreateANonRegisteredNodeType()
2424
{
25+
$this->expectException('RuntimeException');
2526
$builder = new BaseNodeBuilder();
2627
$builder->node('', 'foobar');
2728
}
2829

29-
/**
30-
* @expectedException \RuntimeException
31-
*/
3230
public function testThrowsAnExceptionWhenTheNodeClassIsNotFound()
3331
{
32+
$this->expectException('RuntimeException');
3433
$builder = new BaseNodeBuilder();
3534
$builder
3635
->setNodeClass('noclasstype', '\\foo\\bar\\noclass')

0 commit comments

Comments
 (0)