Skip to content

Commit 2d31393

Browse files
committed
simplified PHPUnit exception expectations
1 parent 419de74 commit 2d31393

9 files changed

+20
-20
lines changed

Tests/Extension/Core/DataTransformer/DateIntervalToArrayTransformerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@ public function testReverseTransformRequiresDateTime()
176176
{
177177
$transformer = new DateIntervalToArrayTransformer();
178178
$this->assertNull($transformer->reverseTransform(null));
179-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(UnexpectedTypeException::class);
179+
$this->expectException(UnexpectedTypeException::class);
180180
$transformer->reverseTransform('12345');
181181
}
182182

183183
public function testReverseTransformWithUnsetFields()
184184
{
185185
$transformer = new DateIntervalToArrayTransformer();
186186
$input = array('years' => '1');
187-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class);
187+
$this->expectException(TransformationFailedException::class);
188188
$transformer->reverseTransform($input);
189189
}
190190

Tests/Extension/Core/DataTransformer/DateIntervalToStringTransformerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testTransformEmpty()
7575
public function testTransformExpectsDateTime()
7676
{
7777
$transformer = new DateIntervalToStringTransformer();
78-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(UnexpectedTypeException::class);
78+
$this->expectException(UnexpectedTypeException::class);
7979
$transformer->transform('1234');
8080
}
8181

@@ -96,7 +96,7 @@ public function testReverseTransformDateString($format, $input, $output)
9696
{
9797
$reverseTransformer = new DateIntervalToStringTransformer($format, true);
9898
$interval = new \DateInterval($output);
99-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class);
99+
$this->expectException(TransformationFailedException::class);
100100
$this->assertDateIntervalEquals($interval, $reverseTransformer->reverseTransform($input));
101101
}
102102

@@ -109,14 +109,14 @@ public function testReverseTransformEmpty()
109109
public function testReverseTransformExpectsString()
110110
{
111111
$reverseTransformer = new DateIntervalToStringTransformer();
112-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(UnexpectedTypeException::class);
112+
$this->expectException(UnexpectedTypeException::class);
113113
$reverseTransformer->reverseTransform(1234);
114114
}
115115

116116
public function testReverseTransformExpectsValidIntervalString()
117117
{
118118
$reverseTransformer = new DateIntervalToStringTransformer();
119-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class);
119+
$this->expectException(TransformationFailedException::class);
120120
$reverseTransformer->reverseTransform('10Y');
121121
}
122122
}

Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php

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

197197
// HOW TO REPRODUCE?
198198
199-
//$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Extension\Core\DataTransformer\TransformationFailedException');
199+
//$this->expectException('Symfony\Component\Form\Extension\Core\DataTransformer\TransformationFailedException');
200200

201201
//$transformer->transform(1.5);
202202
}

Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php

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

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

116116
$transformer->transform('1234');
117117
}
@@ -150,7 +150,7 @@ public function testReverseTransformExpectsString()
150150
{
151151
$reverseTransformer = new DateTimeToStringTransformer();
152152

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

155155
$reverseTransformer->reverseTransform(1234);
156156
}
@@ -159,7 +159,7 @@ public function testReverseTransformExpectsValidDateString()
159159
{
160160
$reverseTransformer = new DateTimeToStringTransformer();
161161

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

164164
$reverseTransformer->reverseTransform('2010-2010-2010');
165165
}
@@ -168,7 +168,7 @@ public function testReverseTransformWithNonExistingDate()
168168
{
169169
$reverseTransformer = new DateTimeToStringTransformer();
170170

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

173173
$reverseTransformer->reverseTransform('2010-04-31');
174174
}

Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php

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

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

7777
$transformer->transform('1234');
7878
}
@@ -109,7 +109,7 @@ public function testReverseTransformExpectsValidTimestamp()
109109
{
110110
$reverseTransformer = new DateTimeToTimestampTransformer();
111111

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

114114
$reverseTransformer->reverseTransform('2010-2010-2010');
115115
}

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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
36+
$this->expectException('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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
64+
$this->expectException('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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
109+
$this->expectException('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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException');
118+
$this->expectException('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
@@ -61,7 +61,7 @@ public function testThrowsExceptionIfObjectIsNotTraversable()
6161
$form = $this->factory->create(static::TESTED_TYPE, null, array(
6262
'entry_type' => TextTypeTest::TESTED_TYPE,
6363
));
64-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\UnexpectedTypeException');
64+
$this->expectException('Symfony\Component\Form\Exception\UnexpectedTypeException');
6565
$form->setData(new \stdClass());
6666
}
6767

Tests/FormBuilderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ public function testNoSetName()
5151

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

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

0 commit comments

Comments
 (0)