
php_unit_no_expectation_annotation
¶Usages of @expectedException*
annotations MUST be replaced by
->setExpectedException*
methods.
Warning
Using this rule is risky.
Risky when PHPUnit classes are overridden or not accessible, or when project has PHPUnit incompatibilities.
Default configuration.
--- Original
+++ New
@@ -2,12 +2,11 @@
final class MyTest extends \PHPUnit_Framework_TestCase
{
/**
- * @expectedException FooException
- * @expectedExceptionMessageRegExp /foo.*$/
- * @expectedExceptionCode 123
*/
function testAaa()
{
+ $this->setExpectedExceptionRegExp(\FooException::class, '/foo.*$/', 123);
+
aaa();
}
}
With configuration: ['target' => '3.2']
.
--- Original
+++ New
@@ -2,11 +2,11 @@
final class MyTest extends \PHPUnit_Framework_TestCase
{
/**
- * @expectedException FooException
- * @expectedExceptionCode 123
*/
function testBbb()
{
+ $this->setExpectedException(\FooException::class, null, 123);
+
bbb();
}
The rule is part of the following rule sets:
Using the @PHPUnit32Migration:risky rule set will enable the php_unit_no_expectation_annotation
rule with the config below:
['target' => '3.2']
Using the @PHPUnit35Migration:risky rule set will enable the php_unit_no_expectation_annotation
rule with the config below:
['target' => '3.2']
Using the @PHPUnit43Migration:risky rule set will enable the php_unit_no_expectation_annotation
rule with the config below:
['target' => '4.3']
Using the @PHPUnit48Migration:risky rule set will enable the php_unit_no_expectation_annotation
rule with the config below:
['target' => '4.3']
Using the @PHPUnit50Migration:risky rule set will enable the php_unit_no_expectation_annotation
rule with the config below:
['target' => '4.3']
Using the @PHPUnit52Migration:risky rule set will enable the php_unit_no_expectation_annotation
rule with the config below:
['target' => '4.3']
Using the @PHPUnit54Migration:risky rule set will enable the php_unit_no_expectation_annotation
rule with the config below:
['target' => '4.3']
Using the @PHPUnit55Migration:risky rule set will enable the php_unit_no_expectation_annotation
rule with the config below:
['target' => '4.3']
Using the @PHPUnit56Migration:risky rule set will enable the php_unit_no_expectation_annotation
rule with the config below:
['target' => '4.3']
Using the @PHPUnit57Migration:risky rule set will enable the php_unit_no_expectation_annotation
rule with the config below:
['target' => '4.3']
Using the @PHPUnit60Migration:risky rule set will enable the php_unit_no_expectation_annotation
rule with the config below:
['target' => '4.3']
Using the @PHPUnit75Migration:risky rule set will enable the php_unit_no_expectation_annotation
rule with the config below:
['target' => '4.3']
Using the @PHPUnit84Migration:risky rule set will enable the php_unit_no_expectation_annotation
rule with the config below:
['target' => '4.3']