Code Inspection: Deprecated 'assertContains/assertNotContains' usage
Configure inspections: Settings | Editor | Inspections
Show intention actions: AltEnter
Reports the deprecated assertContains()
and assertNotContains()
calls with the string $needle
and $ignoreCase
arguments.
The string $needle
and optional boolean $ignoreCase
parameters of the assertContains()
and assertNotContains()
functions are deprecated and removed in PHPUnit 9. For assertions that operate on strings, the specific assertStringContainsString()
, assertStringContainsStringIgnoringCase()
, assertStringNotContainsString()
, and assertStringNotContainsStringIgnoringCase()
methods should be used.
See Usage of the assertEquals function (phpunit.readthedocs.io) for details.
In the following example, the deprecated assertContains()
/ assertNotContains()
calls are used for asserting whether $needle
is contained in $haystack
. After the quick-fix is applied, the more specific assertStringContainsString()
and assertStringNotContainsString()
calls are used instead.
Before the quick-fix
class Test extends TestCase { public function doTest() { $needle = 'value'; $haystack = 'source_string'; $this->assertContains($needle, $haystack); $this->assertNotContains($needle, $haystack); }}
After the quick-fix
use PHPUnit\Framework\TestCase;class Test extends TestCase { public function doTest() { $needle = 'value'; $haystack = 'source_string'; $this->assertStringContainsString($needle, $haystack); $this->assertStringNotContainsString($needle, $haystack); }}
Place the caret at the highlighted line and press AltEnter or click
.
Click the arrow next to the inspection you want to suppress and select the necessary suppress action.