Skip to content

Commit 765d0d8

Browse files
committed
simplified PHPUnit exception expectations
1 parent 5446796 commit 765d0d8

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\InvalidOptionsException');
38+
$this->expectException('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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\InvalidOptionsException');
49+
$this->expectException('Symfony\Component\Validator\Exception\InvalidOptionsException');
5050

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

5454
public function testInvalidAndRequiredOptionsPassed()
5555
{
56-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\InvalidOptionsException');
56+
$this->expectException('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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
104+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
105105

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

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

113113
new ConstraintC();
114114
}

Tests/Mapping/ClassMetadataTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ protected function tearDown()
4040

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

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

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

5252
$this->metadata->addConstraint(new PropertyConstraint());
5353
}

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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ValidatorException');
24+
$this->expectException('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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\Symfony\Component\Validator\Exception\MappingException');
117+
$this->expectException('\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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\Symfony\Component\Validator\Exception\MappingException');
132+
$this->expectException('\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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\InvalidArgumentException');
72+
$this->expectException('\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
@@ -38,7 +38,7 @@ protected function tearDown()
3838

3939
public function testAddConstraintRequiresClassConstraints()
4040
{
41-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
41+
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
4242

4343
$this->metadata->addConstraint(new ClassConstraint());
4444
}

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

0 commit comments

Comments
 (0)