{"record":{"id":"1d51c5462f7c7722","repo":"twigphp/Twig","slug":"s-s","errorCode":null,"errorMessage":"%s: %s","messagePattern":"%s: %s","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/Test/IntegrationTestCase.php","lineNumber":324,"sourceCode":"                    }\n\n                    return $prevHandler ? $prevHandler($type, $msg, $file, $line, $context) : false;\n                });\n\n                foreach (array_keys($templateSources) as $templateName) {\n                    $templates[$templateName] = $twig->load($templateName);\n                }\n            } catch (\\Exception $e) {\n                if (false !== $exception) {\n                    $message = $e->getMessage();\n                    $this->assertSame(trim($exception), trim(\\sprintf('%s: %s', $e::class, $message)));\n                    $last = substr($message, \\strlen($message) - 1);\n                    $this->assertTrue('.' === $last || '?' === $last, 'Exception message must end with a dot or a question mark.');\n\n                    return;\n                }\n\n                throw new Error(\\sprintf('%s: %s', $e::class, $e->getMessage()), -1, null, $e);\n            } finally {\n                restore_error_handler();\n            }\n\n            $template = $templates['index.twig'];\n            $captureRenderDeprecations = '' !== $deprecation;\n\n            try {\n                if ($captureRenderDeprecations) {\n                    $prevHandler = set_error_handler(static function ($type, $msg, $file, $line, $context = []) use (&$deprecations, &$prevHandler) {\n                        if (\\E_USER_DEPRECATED === $type) {\n                            $deprecations[] = $msg;\n\n                            return true;\n                        }\n\n                        return $prevHandler ? $prevHandler($type, $msg, $file, $line, $context) : false;\n                    });","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Test/IntegrationTestCase.php#L306-L342","documentation":"In Twig's integration test suite (Test/IntegrationTestCase::doIntegrationTest), when a test case expects an exception and one is thrown but does not match the expectation (or does not satisfy prior assertions like message wording), the suite rethrows it wrapped in a plain Error formatted as \"ExceptionClass: message\". This is test-harness plumbing: it preserves the original exception as $previous while flattening it for phpUnit failure output.","triggerScenarios":"A .test integration fixture declares an exception (or deprecation) expectation, but the code under test throws a different exception class or a message that fails the suite's assertions (e.g. message not ending with '.' or '?'), so Error(sprintf('%s: %s', ...)) is raised inside testIntegration/testLegacyIntegration.","commonSituations":"Contributing a patch to Twig and writing integration test fixtures whose expected exception message/class doesn't match the actual thrown error; changes to error messages breaking the suite's message-format assertions.","solutions":["Read the wrapped original exception (given as the Error's previous) to see what actually failed.","Update the fixture's EXPECTED exception line to match the actual exception class and message.","If the message text changed intentionally, update the message and keep it ending with '.' or '?' to pass formatting assertions.","Fix the library code if the new exception is a regression."],"exampleFix":"--EXPECT--\nLogicException: Foo bar\n\n{# after: match actual exception #}\n--EXPECT EXCEPTION--\nTwig\\Error\\SyntaxError: Unexpected token \"foo\".","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// In test fixtures, align expectations with reality:\n// --EXPECT EXCEPTION--\n// Twig\\Error\\SyntaxError: <message ending with '.' or '?'>.\n// The harness rethrows as Error with the original as previous — read getPrevious() when debugging.","preventionTips":["Keep EXPECT EXCEPTION blocks in fixtures exactly matching class and message.","Ensure expected exception messages end with '.' or '?' per suite rules.","Run the integration suite locally before committing parser/compiler changes."],"tags":["twig","testing","phpunit","test-harness"],"backgroundTag":"unexpected-response-shape","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}