Rule php_unit_no_expectation_annotation¶
Usages of @expectedException* annotations MUST be replaced by
->setExpectedException* methods.
Warnings¶
This rule is RISKY¶
Risky when PHPUnit classes are overridden or not accessible, or when project has PHPUnit incompatibilities.
This rule is CONFIGURABLE¶
You can configure this rule using the following options: target,
use_class_const.
Configuration¶
target¶
Target version of PHPUnit.
Allowed values: '3.2', '4.3' and 'newest'
Default value: 'newest'
use_class_const¶
Use ::class notation.
Allowed types: bool
Default value: true
Examples¶
Example #1¶
Default configuration.
--- Original
+++ New
<?php
final class MyTest extends \PHPUnit_Framework_TestCase
{
/**
- * @expectedException FooException
- * @expectedExceptionMessageRegExp /foo.*$/
- * @expectedExceptionCode 123
*/
function testAaa()
{
+ $this->setExpectedExceptionRegExp(\FooException::class, '/foo.*$/', 123);
+
aaa();
}
}
Example #2¶
With configuration: ['target' => '3.2'].
--- Original
+++ New
<?php
final class MyTest extends \PHPUnit_Framework_TestCase
{
/**
- * @expectedException FooException
- * @expectedExceptionCode 123
*/
function testBbb()
{
+ $this->setExpectedException(\FooException::class, null, 123);
+
bbb();
}
/**
* @expectedException FooException
* @expectedExceptionMessageRegExp /foo.*$/
*/
function testCcc()
{
ccc();
}
}
Rule sets¶
The rule is part of the following rule sets:
@PHPUnit3x2Migration:risky with config:
['target' => '3.2']@PHPUnit3x5Migration:risky with config:
['target' => '3.2']@PHPUnit4x3Migration:risky with config:
['target' => '4.3']@PHPUnit4x8Migration:risky with config:
['target' => '4.3']@PHPUnit5x0Migration:risky with config:
['target' => '4.3']@PHPUnit5x2Migration:risky with config:
['target' => '4.3']@PHPUnit5x4Migration:risky with config:
['target' => '4.3']@PHPUnit5x5Migration:risky with config:
['target' => '4.3']@PHPUnit5x6Migration:risky with config:
['target' => '4.3']@PHPUnit5x7Migration:risky with config:
['target' => '4.3']@PHPUnit6x0Migration:risky with config:
['target' => '4.3']@PHPUnit7x5Migration:risky with config:
['target' => '4.3']@PHPUnit8x4Migration:risky with config:
['target' => '4.3']@PHPUnit9x1Migration:risky with config:
['target' => '4.3']@PHPUnit10x0Migration:risky with config:
['target' => '4.3']@PHPUnit32Migration:risky (deprecated) with config:
['target' => '3.2']@PHPUnit35Migration:risky (deprecated) with config:
['target' => '3.2']@PHPUnit43Migration:risky (deprecated) with config:
['target' => '4.3']@PHPUnit48Migration:risky (deprecated) with config:
['target' => '4.3']@PHPUnit50Migration:risky (deprecated) with config:
['target' => '4.3']@PHPUnit52Migration:risky (deprecated) with config:
['target' => '4.3']@PHPUnit54Migration:risky (deprecated) with config:
['target' => '4.3']@PHPUnit55Migration:risky (deprecated) with config:
['target' => '4.3']@PHPUnit56Migration:risky (deprecated) with config:
['target' => '4.3']@PHPUnit57Migration:risky (deprecated) with config:
['target' => '4.3']@PHPUnit60Migration:risky (deprecated) with config:
['target' => '4.3']@PHPUnit75Migration:risky (deprecated) with config:
['target' => '4.3']@PHPUnit84Migration:risky (deprecated) with config:
['target' => '4.3']@PHPUnit91Migration:risky (deprecated) with config:
['target' => '4.3']@PHPUnit100Migration:risky (deprecated) with config:
['target' => '4.3']
References¶
Fixer class: PhpCsFixer\Fixer\PhpUnit\PhpUnitNoExpectationAnnotationFixer
Test class: PhpCsFixer\Tests\Fixer\PhpUnit\PhpUnitNoExpectationAnnotationFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.