{"record":{"id":"8045e94682800ac8","repo":"sebastianbergmann/phpunit","slug":"expected-deprecation-with-message-matching-regular","errorCode":null,"errorMessage":"Expected deprecation with message matching regular expression \"%s\" was not triggered","messagePattern":"Expected deprecation with message matching regular expression \"(.+?)\" was not triggered","errorType":"exception","errorClass":"ExpectationFailedException","httpStatus":null,"severity":"error","filePath":"src/Framework/TestCase.php","lineNumber":1523,"sourceCode":"                throw new ExpectationFailedException(\n                    sprintf(\n                        'Expected deprecation with message \"%s\" was not triggered',\n                        $deprecationExpectation,\n                    ),\n                );\n            }\n        }\n\n        foreach ($this->expectedUserDeprecationMessageRegularExpression as $deprecationExpectation) {\n            $this->numberOfAssertionsPerformed++;\n\n            $expectedDeprecationTriggered = array_any(\n                DeprecationCollector::deprecations(),\n                static fn (string $deprecation) => @preg_match($deprecationExpectation, $deprecation) > 0,\n            );\n\n            if (!$expectedDeprecationTriggered) {\n                throw new ExpectationFailedException(\n                    sprintf(\n                        'Expected deprecation with message matching regular expression \"%s\" was not triggered',\n                        $deprecationExpectation,\n                    ),\n                );\n            }\n        }\n    }\n\n    /**\n     * @throws Throwable\n     */\n    private function verifyMockObjects(): void\n    {\n        $allowsMockObjectsWithoutExpectations = $this->allowsMockObjectsWithoutExpectations();\n        $isPhpunitTestSuite                   = str_starts_with($this::class, 'PHPUnit\\\\');\n        $requireSealedMockObjects             = ConfigurationRegistry::get()->requireSealedMockObjects();\n","sourceCodeStart":1505,"sourceCodeEnd":1541,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Framework/TestCase.php#L1505-L1541","documentation":"Thrown after the test body when expectDeprecationMatch() was used but no collected user deprecation matches the given regular expression. verifyDeprecationExpectations() runs preg_match() of your pattern against every recorded deprecation and fails when none match (invalid regexes never match because of the @ suppression).","triggerScenarios":"Calling $this->expectDeprecationMatch('/pattern/') where no triggered E_USER_DEPRECATED message matches the pattern; also when the pattern itself is invalid PCRE and silently matches nothing.","commonSituations":"Over-anchored or mistyped regexes; delimiters forgotten; deprecation wording changed between library versions; the deprecated path not executed.","solutions":["Test the regex against the actual deprecation message (e.g. in a scratch script) and fix the pattern","Make the pattern more permissive (drop exact anchors, escape regex metacharacters that appear literally in the message)","Confirm the deprecated code path runs in this test and in the same process","Use expectDeprecation() with the literal message when no variable parts exist"],"exampleFix":"// before\n$this->expectDeprecationMatch('/^Using Config/'); // message is 'Config v2 is deprecated'\n\n// after\n$this->expectDeprecationMatch('/Config v\\d+ is deprecated/');","handlingStrategy":"validation","validationCode":"$pattern = '/Config v\\d+ is deprecated/';\n$actual = 'Config v2 is deprecated';\nself::assertSame(1, preg_match($pattern, $actual), 'regex must match the real message');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Smoke-test the pattern against the literal message before wiring it into expectDeprecationMatch()","Escape literal dots, slashes, and brackets that appear in the message","Prefer expectDeprecation() for static messages"],"tags":["phpunit","deprecation","regex","assertion"],"backgroundTag":"deprecation-pattern-not-matched","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}