Skip to content

Commit 74c10d8

Browse files
peterrehmnicolas-grekas
authored andcommitted
Further refactorings to PHPUnit namespaces
1 parent fdee9a5 commit 74c10d8

10 files changed

+32
-18
lines changed

Test/DeprecationErrorHandler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ public static function handle($errorNumber, $message, $file, $line, $context)
2424
return true;
2525
}
2626

27-
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
27+
if (class_exists('PHPUnit_Util_ErrorHandler')) {
28+
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
29+
}
30+
31+
return \PHPUnit\Util\ErrorHandler::handleError($errorNumber, $message, $file, $line);
2832
}
2933

3034
public static function handleBC($errorNumber, $message, $file, $line, $context)

Tests/ButtonBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getInvalidNames()
5353
*/
5454
public function testInvalidNames($name)
5555
{
56-
$this->setExpectedException(
56+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(
5757
'\Symfony\Component\Form\Exception\InvalidArgumentException',
5858
'Buttons cannot have empty names.'
5959
);

Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function testTransformWrapsIntlErrors()
190190

191191
// HOW TO REPRODUCE?
192192
193-
//$this->setExpectedException('Symfony\Component\Form\Extension\Core\DataTransformer\TransformationFailedException');
193+
//$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Extension\Core\DataTransformer\TransformationFailedException');
194194

195195
//$transformer->transform(1.5);
196196
}

Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function testTransformExpectsDateTime()
112112
{
113113
$transformer = new DateTimeToStringTransformer();
114114

115-
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
115+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
116116

117117
$transformer->transform('1234');
118118
}
@@ -163,7 +163,7 @@ public function testReverseTransformExpectsString()
163163
{
164164
$reverseTransformer = new DateTimeToStringTransformer();
165165

166-
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
166+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
167167

168168
$reverseTransformer->reverseTransform(1234);
169169
}
@@ -172,7 +172,7 @@ public function testReverseTransformExpectsValidDateString()
172172
{
173173
$reverseTransformer = new DateTimeToStringTransformer();
174174

175-
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
175+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
176176

177177
$reverseTransformer->reverseTransform('2010-2010-2010');
178178
}
@@ -181,7 +181,7 @@ public function testReverseTransformWithNonExistingDate()
181181
{
182182
$reverseTransformer = new DateTimeToStringTransformer();
183183

184-
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
184+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
185185

186186
$reverseTransformer->reverseTransform('2010-04-31');
187187
}

Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testTransformExpectsDateTime()
7474
{
7575
$transformer = new DateTimeToTimestampTransformer();
7676

77-
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
77+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
7878

7979
$transformer->transform('1234');
8080
}
@@ -111,7 +111,7 @@ public function testReverseTransformExpectsValidTimestamp()
111111
{
112112
$reverseTransformer = new DateTimeToTimestampTransformer();
113113

114-
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
114+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
115115

116116
$reverseTransformer->reverseTransform('2010-2010-2010');
117117
}

Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testTransformExpectsNumeric()
3333
{
3434
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
3535

36-
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
36+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
3737

3838
$transformer->transform('abcd');
3939
}
@@ -61,7 +61,7 @@ public function testReverseTransformExpectsString()
6161
{
6262
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
6363

64-
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
64+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
6565

6666
$transformer->reverseTransform(12345);
6767
}

Tests/Extension/Core/DataTransformer/PercentToLocalizedStringTransformerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function testTransformExpectsNumeric()
106106
{
107107
$transformer = new PercentToLocalizedStringTransformer();
108108

109-
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
109+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
110110

111111
$transformer->transform('foo');
112112
}
@@ -115,7 +115,7 @@ public function testReverseTransformExpectsString()
115115
{
116116
$transformer = new PercentToLocalizedStringTransformer();
117117

118-
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
118+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
119119

120120
$transformer->reverseTransform(1);
121121
}

Tests/Extension/Core/Type/CollectionTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function testThrowsExceptionIfObjectIsNotTraversable()
5959
$form = $this->factory->create('collection', null, array(
6060
'type' => 'text',
6161
));
62-
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
62+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\UnexpectedTypeException');
6363
$form->setData(new \stdClass());
6464
}
6565

Tests/FormBuilderTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ public function testNoSetName()
4949

5050
public function testAddNameNoStringAndNoInteger()
5151
{
52-
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
52+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\UnexpectedTypeException');
5353
$this->builder->add(true);
5454
}
5555

5656
public function testAddTypeNoString()
5757
{
58-
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
58+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\UnexpectedTypeException');
5959
$this->builder->add('foo', 1234);
6060
}
6161

@@ -165,7 +165,13 @@ public function testAddButton()
165165

166166
public function testGetUnknown()
167167
{
168-
$this->setExpectedException('Symfony\Component\Form\Exception\InvalidArgumentException', 'The child with the name "foo" does not exist.');
168+
if (method_exists($this, 'expectException')) {
169+
$this->expectException('Symfony\Component\Form\Exception\InvalidArgumentException');
170+
$this->expectExceptionMessage('The child with the name "foo" does not exist.');
171+
} else {
172+
$this->setExpectedException('Symfony\Component\Form\Exception\InvalidArgumentException', 'The child with the name "foo" does not exist.');
173+
}
174+
169175
$this->builder->get('foo');
170176
}
171177

Tests/Resources/TranslationFilesTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ class TranslationFilesTest extends TestCase
2020
*/
2121
public function testTranslationFileIsValid($filePath)
2222
{
23-
\PHPUnit_Util_XML::loadfile($filePath, false, false, true);
23+
if (class_exists('PHPUnit_Util_XML')) {
24+
\PHPUnit_Util_XML::loadfile($filePath, false, false, true);
25+
} else {
26+
\PHPUnit\Util\XML::loadfile($filePath, false, false, true);
27+
}
2428
}
2529

2630
public function provideTranslationFiles()

0 commit comments

Comments
 (0)