8000 minor #24557 Fixed mistake in exception expectation (uuf6429) · symfony/symfony@4650592 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4650592

Browse files
minor #24557 Fixed mistake in exception expectation (uuf6429)
This PR was merged into the 3.3 branch. Discussion ---------- Fixed mistake in exception expectation | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | In some cases, (5 to be exact), the `expectException` is misused while attempting to provide compatibility with the older `setExpectedException` by making use of a non-existent parameter. Firstly, this makes the tests inconsistent (old PHPUnit version test exception message, while newer one doesn't). Secondly, if PHPUnit interface suddenly starts making use of a 2nd parameter in `expectException`, the existing code might break or cause unexpected side-effects. Original report: symfony/process@87bb726#commitcomment-24848315 Commits ------- 03be003 Fixed mistake in exception expectation
2 parents a522f5e + 03be003 commit 4650592

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,11 @@ public function testAssetsCanBeEnabled()
165165
*/
166166
public function testInvalidAssetsConfiguration(array $assetConfig, $expectedMessage)
167167
{
168-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(
169-
InvalidConfigurationException::class,
170-
$expectedMessage
171-
);
172-
if (method_exists($this, 'expectExceptionMessage')) {
168+
if (method_exists($this, 'expectException')) {
169+
$this->expectException(InvalidConfigurationException::class);
173170
$this->expectExceptionMessage($expectedMessage);
171+
} else {
172+
$this->setExpectedException(InvalidConfigurationException::class, $expectedMessage);
174173
}
175174

176175
$processor = new Processor();

src/Symfony/Component/Form/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 <cheprasov.84@ya.ru>
@@ -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
}

src/Symfony/Component/Form/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

src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ public function testProcessFailedExceptionThrowsException()
2929
->method('isSuccessful')
3030
->will($this->returnValue(true));
3131

32-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(
33-
'\InvalidArgumentException',
34-
'Expected a failed process, but the given process was successful.'
35-
);
32+
if (method_exists($this, 'expectException')) {
33+
$this->expectException(\InvalidArgumentException::class);
34+
$this->expectExceptionMessage('Expected a failed process, but the given process was successful.');
35+
} else {
36+
$this->setExpectedException(\InvalidArgumentException::class, 'Expected a failed process, but the given process was successful.');
37+
}
3638

3739
new ProcessFailedException($process);
3840
}

0 commit comments

Comments
 (0)
0