PhpStorm 2021.3 Help

Code Inspection: Deprecated 'assertContains/assertNotContains' usage

Reports deprecated usages of the assertContains and assertNotContains functions with string $needle and $ignoreCase parameter.

The string $needle and optional boolean $ignoreCase parameters of the assertContains and assertNotContains functions are deprecated and will be removed in PHPUnit 9.

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.

class Test extends TestCase { public function doTest() { $needle = 'value'; $haystack = 'source_string'; $this->assertContains($needle, $haystack); $this->assertNotContains($needle, $haystack); } }
class Test extends TestCase { public function doTest() { $needle = 'value'; $haystack = 'source_string'; $this->assertStringContainsString($needle, $haystack); $this->assertStringNotContainsString($needle, $haystack); } }

Suppress an inspection in the editor

  1. Position the caret at the highlighted line and press Alt+Enter or click the Intention action icon.

  2. Click the arrow next to the inspection you want to suppress and select the necessary suppress action.

Last modified: 11 February 2022