{"record":{"id":"ab0068191857e7b7","repo":"sebastianbergmann/comparator","slug":"failed-asserting-that-s-matches-expected-s-scalarcomparator","errorCode":null,"errorMessage":"Failed asserting that %s matches expected %s.","messagePattern":"Failed asserting that (.+?) matches expected (.+?)\\.","errorType":"exception","errorClass":"ComparisonFailure","httpStatus":null,"severity":"error","filePath":"src/ScalarComparator.php","lineNumber":84,"sourceCode":"        }\n\n        if ($expectedToCompare !== $actualToCompare && is_string($expected) && is_string($actual)) {\n            [$cutExpected, $cutActual] = self::removeOverlongCommonPrefix($expected, $actual);\n            [$cutExpected, $cutActual] = self::removeOverlongCommonSuffix($cutExpected, $cutActual);\n\n            throw new ComparisonFailure(\n                $expected,\n                $actual,\n                $exporter->export($cutExpected),\n                $exporter->export($cutActual),\n                'Failed asserting that two strings are equal.',\n                $this->contextLines(),\n            );\n        }\n\n        /** @phpstan-ignore notEqual.notAllowed */\n        if ($expectedToCompare != $actualToCompare) {\n            throw new ComparisonFailure(\n                $expected,\n                $actual,\n                // no diff is required\n                '',\n                '',\n                sprintf(\n                    'Failed asserting that %s matches expected %s.',\n                    $exporter->export($actual),\n                    $exporter->export($expected),\n                ),\n                $this->contextLines(),\n            );\n        }\n    }\n\n    /**\n     * @return array{string, string}\n     */","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/sebastianbergmann/comparator/blob/00837a9d227b4e123b0b42a91736960f6b0b3583/src/ScalarComparator.php#L66-L102","documentation":"Thrown by ScalarComparator::assertEquals when two string values differ. Before throwing, the comparator strips the overlong common prefix and suffix of the two strings so the ComparisonFailure diff shows only the diverging portion; the %s placeholders carry the exported actual and expected strings.","triggerScenarios":"Thrown at src/ScalarComparator.php:84 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the ComparisonFailure diff; it already trims the overlong common prefix/suffix to show just the diverging region of the two strings.","Inspect both strings for invisible differences: trailing whitespace, newline style, encoding, or multi-byte characters.","Use mb_strtolower or normalize both strings if case or encoding differences are expected.","Compare a substring or a computed value rather than full strings when the assertion targets specific content.","Correct the code path producing the actual string so it matches the expected value."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"00837a9d227b4e123b0b42a91736960f6b0b3583","analyzedAt":"2026-09-15T03:36:55.154Z","contentChangedAt":"2026-09-15T03:36:55.154Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}