Skip to content

Commit f82135d

Browse files
peterrehmnicolas-grekas
authored andcommitted
Further refactorings to PHPUnit namespaces
1 parent dd45322 commit f82135d

File tree

8 files changed

+21
-17
lines changed

8 files changed

+21
-17
lines changed

Tests/ConstraintTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testSetProperties()
3535

3636
public function testSetNotExistingPropertyThrowsException()
3737
{
38-
$this->setExpectedException('Symfony\Component\Validator\Exception\InvalidOptionsException');
38+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\InvalidOptionsException');
3939

4040
new ConstraintA(array(
4141
'foo' => 'bar',
@@ -46,14 +46,14 @@ public function testMagicPropertiesAreNotAllowed()
4646
{
4747
$constraint = new ConstraintA();
4848

49-
$this->setExpectedException('Symfony\Component\Validator\Exception\InvalidOptionsException');
49+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\InvalidOptionsException');
5050

5151
$constraint->foo = 'bar';
5252
}
5353

5454
public function testInvalidAndRequiredOptionsPassed()
5555
{
56-
$this->setExpectedException('Symfony\Component\Validator\Exception\InvalidOptionsException');
56+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\InvalidOptionsException');
5757

5858
new ConstraintC(array(
5959
'option1' => 'default',
@@ -101,14 +101,14 @@ public function testDontSetDefaultPropertyIfValuePropertyExists()
101101

102102
public function testSetUndefinedDefaultProperty()
103103
{
104-
$this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
104+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
105105

106106
new ConstraintB('foo');
107107
}
108108

109109
public function testRequiredOptionsMustBeDefined()
110110
{
111-
$this->setExpectedException('Symfony\Component\Validator\Exception\MissingOptionsException');
111+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\MissingOptionsException');
112112

113113
new ConstraintC();
114114
}

Tests/Mapping/ClassMetadataTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ protected function tearDown()
3939

4040
public function testAddConstraintDoesNotAcceptValid()
4141
{
42-
$this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
42+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
4343

4444
$this->metadata->addConstraint(new Valid());
4545
}
4646

4747
public function testAddConstraintRequiresClassConstraints()
4848
{
49-
$this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
49+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
5050

5151
$this->metadata->addConstraint(new PropertyConstraint());
5252
}
@@ -249,14 +249,14 @@ public function testGroupSequencesWorkIfContainingDefaultGroup()
249249

250250
public function testGroupSequencesFailIfNotContainingDefaultGroup()
251251
{
252-
$this->setExpectedException('Symfony\Component\Validator\Exception\GroupDefinitionException');
252+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\GroupDefinitionException');
253253

254254
$this->metadata->setGroupSequence(array('Foo', 'Bar'));
255255
}
256256

257257
public function testGroupSequencesFailIfContainingDefault()
258258
{
259-
$this->setExpectedException('Symfony\Component\Validator\Exception\GroupDefinitionException');
259+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\GroupDefinitionException');
260260

261261
$this->metadata->setGroupSequence(array('Foo', $this->metadata->getDefaultGroup(), Constraint::DEFAULT_GROUP));
262262
}

Tests/Mapping/GetterMetadataTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class GetterMetadataTest extends TestCase
2121

2222
public function testInvalidPropertyName()
2323
{
24-
$this->setExpectedException('Symfony\Component\Validator\Exception\ValidatorException');
24+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException');
2525

2626
new GetterMetadata(self::CLASSNAME, 'foobar');
2727
}

Tests/Mapping/Loader/XmlFileLoaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function testThrowExceptionIfDocTypeIsSet()
114114
$loader = new XmlFileLoader(__DIR__.'/withdoctype.xml');
115115
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
116116

117-
$this->setExpectedException('\Symfony\Component\Validator\Exception\MappingException');
117+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\Symfony\Component\Validator\Exception\MappingException');
118118
$loader->loadClassMetadata($metadata);
119119
}
120120

@@ -129,7 +129,7 @@ public function testDoNotModifyStateIfExceptionIsThrown()
129129
try {
130130
$loader->loadClassMetadata($metadata);
131131
} catch (MappingException $e) {
132-
$this->setExpectedException('\Symfony\Component\Validator\Exception\MappingException');
132+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\Symfony\Component\Validator\Exception\MappingException');
133133
$loader->loadClassMetadata($metadata);
134134
}
135135
}

Tests/Mapping/Loader/YamlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testDoNotModifyStateIfExceptionIsThrown()
6969
$loader->loadClassMetadata($metadata);
7070
} catch (\InvalidArgumentException $e) {
7171
// Call again. Again an exception should be thrown
72-
$this->setExpectedException('\InvalidArgumentException');
72+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\InvalidArgumentException');
7373
$loader->loadClassMetadata($metadata);
7474
}
7575
}

Tests/Mapping/MemberMetadataTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testLegacyAddOtherConstraintDoesNotSetMemberToCascaded()
6262

6363
public function testAddConstraintRequiresClassConstraints()
6464
{
65-
$this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
65+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
6666

6767
$this->metadata->addConstraint(new ClassConstraint());
6868
}

Tests/Mapping/PropertyMetadataTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class PropertyMetadataTest extends TestCase
2222

2323
public function testInvalidPropertyName()
2424
{
25-
$this->setExpectedException('Symfony\Component\Validator\Exception\ValidatorException');
25+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException');
2626

2727
new PropertyMetadata(self::CLASSNAME, 'foobar');
2828
}
@@ -50,7 +50,7 @@ public function testGetPropertyValueFromRemovedProperty()
5050
$metadata = new PropertyMetadata(self::CLASSNAME, 'internal');
5151
$metadata->name = 'test';
5252

53-
$this->setExpectedException('Symfony\Component\Validator\Exception\ValidatorException');
53+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException');
5454
$metadata->getPropertyValue($entity);
5555
}
5656
}

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)