{"record":{"id":"d7af430359cb5d4c","repo":"sebastianbergmann/phpunit","slug":"expected-deprecation-with-message-s-was-not-tri","errorCode":null,"errorMessage":"Expected deprecation with message \"%s\" was not triggered","messagePattern":"Expected deprecation with message \"(.+?)\" was not triggered","errorType":"exception","errorClass":"ExpectationFailedException","httpStatus":null,"severity":"error","filePath":"src/Framework/TestCase.php","lineNumber":1505,"sourceCode":"            $this->errorLogCapture->stop();\n        }\n\n        $this->emitEventForCustomTestMethodInvocation();\n        $this->exceptionExpectation->assertWasRaised($this);\n\n        return $testResult;\n    }\n\n    /**\n     * @throws ExpectationFailedException\n     */\n    private function verifyDeprecationExpectations(): void\n    {\n        foreach ($this->expectedUserDeprecationMessage as $deprecationExpectation) {\n            $this->numberOfAssertionsPerformed++;\n\n            if (!in_array($deprecationExpectation, DeprecationCollector::deprecations(), true)) {\n                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(","sourceCodeStart":1487,"sourceCodeEnd":1523,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Framework/TestCase.php#L1487-L1523","documentation":"Thrown after the test body finishes when expectDeprecation() was called but DeprecationCollector never recorded a matching user deprecation. PHPUnit verifies outstanding deprecation expectations in verifyDeprecationExpectations() during runBare(), so a missing deprecation is treated as a failed assertion.","triggerScenarios":"Calling $this->expectDeprecation('exact message') but the code under test never calls trigger_error($msg, E_USER_DEPRECATED) with exactly that message, or the deprecation fires in a separate process from the one collecting them.","commonSituations":"Message typos or dynamic parts in the deprecation string (use expectDeprecationMatch() for those); the deprecated code path not being reached by this test; process isolation splitting the collector; library versions changing deprecation wording.","solutions":["Verify the code under test actually executes the branch that triggers the deprecation in this test","Compare the expected string byte-for-byte with the trigger_error() message; fix typos or interpolated values","Switch to expectDeprecationMatch() with a regex when the message contains variable parts","Ensure the deprecation is triggered in the same PHP process (avoid process isolation for this test)"],"exampleFix":"// before\n$this->expectDeprecation('Using Config v2 is deprecated');\n$api->load(\"v3\"); // never touches the deprecated v2 path\n\n// after\n$this->expectDeprecation('Using Config v2 is deprecated');\n$api->load(\"v2\"); // exercises the deprecated path","handlingStrategy":"validation","validationCode":"// Before the test: confirm the expected deprecation is among collected ones in this process\n$this->expectDeprecation('Config v2 is deprecated');\n$api->load('v2');\nself::assertContains(\n    'Config v2 is deprecated',\n    DeprecationCollector::deprecations(),\n);","typeGuard":null,"tryCatchPattern":"// When wrapping third-party tests, let the failure surface instead of swallowing it:\ntry {\n    $test->runBare();\n} catch (ExpectationFailedException $e) {\n    if (!str_contains($e->getMessage(), 'Expected deprecation with message')) {\n        throw $e;\n    }\n    // record as deprecation-missing failure\n}","preventionTips":["Copy the deprecation string from the trigger_error() call, not from memory","Use expectDeprecationMatch() whenever the message has variable parts","Do not enable process isolation for tests that assert deprecations"],"tags":["phpunit","deprecation","assertion","expect-deprecation"],"backgroundTag":"expected-deprecation-not-triggered","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}