Skip to content

Commit af5aa5c

Browse files
committed
Fixed mistake in exception expectation
1 parent bd88624 commit af5aa5c

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

Tests/ButtonBuilderTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Form\ButtonBuilder;
16+
use Symfony\Component\Form\Exception\InvalidArgumentException;
1617

1718
/**
1819
* @author Alexander Cheprasov <[email protected]>
@@ -53,10 +54,12 @@ public function getInvalidNames()
5354
*/
5455
public function testInvalidNames($name)
5556
{
56-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(
57-
'\Symfony\Component\Form\Exception\InvalidArgumentException',
58-
'Buttons cannot have empty names.'
59-
);
57+
if (method_exists($this, 'expectException')) {
58+
$this->expectException(InvalidArgumentException::class);
59+
$this->expectExceptionMessage('Buttons cannot have empty names.');
60+
} else {
61+
$this->setExpectedException(InvalidArgumentException::class, 'Buttons cannot have empty names.');
62+
}
6063
new ButtonBuilder($name);
6164
}
6265
}

Tests/Extension/Core/DataTransformer/DateIntervalToArrayTransformerTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ public function testReverseTransformWithEmptyFields()
181181
'minutes' => '',
182182
'seconds' => '6',
183183
);
184-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class, 'This amount of "minutes" is invalid');
184+
if (method_exists($this, 'expectException')) {
185+
$this->expectException(TransformationFailedException::class);
186+
$this->expectExceptionMessage('This amount of "minutes" is invalid');
187+
} else {
188+
$this->setExpectedException(TransformationFailedException::class, 'This amount of "minutes" is invalid');
189+
}
185190
$transformer->reverseTransform($input);
186191
}
187192

@@ -191,7 +196,12 @@ public function testReverseTransformWithWrongInvertType()
191196
$input = array(
192197
'invert' => '1',
193198
);
194-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class, 'The value of "invert" must be boolean');
199+
if (method_exists($this, 'expectException')) {
200+
$this->expectException(TransformationFailedException::class);
201+
$this->expectExceptionMessage('The value of "invert" must be boolean');
202+
} else {
203+
$this->setExpectedException(TransformationFailedException::class, 'The value of "invert" must be boolean');
204+
}
195205
$transformer->reverseTransform($input);
196206
}
197207

0 commit comments

Comments
 (0)