Skip to content

Commit 174a1b6

Browse files
committed
Replace calls to setExpectedException by Pollyfill
1 parent 00986c0 commit 174a1b6

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

Tests/Definition/ArrayNodeTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
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\ArrayNode;
1617
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1718
use Symfony\Component\Config\Definition\ScalarNode;
1819

1920
class ArrayNodeTest extends TestCase
2021
{
22+
use ForwardCompatTestTrait;
23+
2124
/**
2225
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException
2326
*/
@@ -55,12 +58,8 @@ public function ignoreAndRemoveMatrixProvider()
5558
public function testIgnoreAndRemoveBehaviors($ignore, $remove, $expected, $message = '')
5659
{
5760
if ($expected instanceof \Exception) {
58-
if (method_exists($this, 'expectException')) {
59-
$this->expectException(\get_class($expected));
60-
$this->expectExceptionMessage($expected->getMessage());
61-
} else {
62-
$this->setExpectedException(\get_class($expected), $expected->getMessage());
63-
}
61+
$this->expectException(\get_class($expected));
62+
$this->expectExceptionMessage($expected->getMessage());
6463
}
6564
$node = new ArrayNode('root');
6665
$node->setIgnoreExtraKeys($ignore, $remove);

Tests/Definition/ScalarNodeTest.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
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\ArrayNode;
1617
use Symfony\Component\Config\Definition\ScalarNode;
1718

1819
class ScalarNodeTest extends TestCase
1920
{
21+
use ForwardCompatTestTrait;
22+
2023
/**
2124
* @dataProvider getValidValues
2225
*/
@@ -95,12 +98,8 @@ public function testNormalizeThrowsExceptionWithoutHint()
9598
{
9699
$node = new ScalarNode('test');
97100

98-
if (method_exists($this, 'expectException')) {
99-
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
100-
$this->expectExceptionMessage('Invalid type for path "test". Expected scalar, but got array.');
101-
} else {
102-
$this->setExpectedException('Symfony\Component\Config\Definition\Exception\InvalidTypeException', 'Invalid type for path "test". Expected scalar, but got array.');
103-
}
101+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
102+
$this->expectExceptionMessage('Invalid type for path "test". Expected scalar, but got array.');
104103

105104
$node->normalize([]);
106105
}
@@ -110,12 +109,8 @@ public function testNormalizeThrowsExceptionWithErrorMessage()
110109
$node = new ScalarNode('test');
111110
$node->setInfo('"the test value"');
112111

113-
if (method_exists($this, 'expectException')) {
114-
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
115-
$this->expectExceptionMessage("Invalid type for path \"test\". Expected scalar, but got array.\nHint: \"the test value\"");
116-
} else {
117-
$this->setExpectedException('Symfony\Component\Config\Definition\Exception\InvalidTypeException', "Invalid type for path \"test\". Expected scalar, but got array.\nHint: \"the test value\"");
118-
}
112+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
113+
$this->expectExceptionMessage("Invalid type for path \"test\". Expected scalar, but got array.\nHint: \"the test value\"");
119114

120115
$node->normalize([]);
121116
}

Tests/Util/XmlUtilsTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
namespace Symfony\Component\Config\Tests\Util;
1313

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

1718
class XmlUtilsTest extends TestCase
1819
{
20+
use ForwardCompatTestTrait;
21+
1922
public function testLoadFile()
2023
{
2124
$fixtures = __DIR__.'/../Fixtures/Util/';
@@ -166,12 +169,8 @@ public function testLoadEmptyXmlFile()
166169
{
167170
$file = __DIR__.'/../Fixtures/foo.xml';
168171

169-
if (method_exists($this, 'expectException')) {
170-
$this->expectException('InvalidArgumentException');
171-
$this->expectExceptionMessage(sprintf('File %s does not contain valid XML, it is empty.', $file));
172-
} else {
173-
$this->setExpectedException('InvalidArgumentException', sprintf('File %s does not contain valid XML, it is empty.', $file));
174-
}
172+
$this->expectException('InvalidArgumentException');
173+
$this->expectExceptionMessage(sprintf('File %s does not contain valid XML, it is empty.', $file));
175174

176175
XmlUtils::loadFile($file);
177176
}

0 commit comments

Comments
 (0)