{"record":{"id":"93e8f445a903eb98","repo":"rectorphp/rector","slug":"fixture-file-and-input-file-cannot-be-the-same","errorCode":null,"errorMessage":"Fixture file and input file cannot be the same: ","messagePattern":"Fixture file and input file cannot be the same: ","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"src/Testing/PHPUnit/AbstractRectorTestCase.php","lineNumber":146,"sourceCode":"        return null;\n    }\n    protected function doTestFile(string $fixtureFilePath, bool $includeFixtureDirectoryAsSource = \\false): void\n    {\n        // prepare input file contents and expected file output contents\n        $fixtureFileContents = FileSystem::read($fixtureFilePath);\n        if (FixtureSplitter::containsSplit($fixtureFileContents)) {\n            // changed content\n            [$inputFileContents, $expectedFileContents] = FixtureSplitter::splitFixtureFileContents($fixtureFileContents);\n        } else {\n            // no change\n            $inputFileContents = $fixtureFileContents;\n            $expectedFileContents = $fixtureFileContents;\n        }\n        $inputFilePath = $this->createInputFilePath($fixtureFilePath);\n        // to remove later in tearDown()\n        $this->inputFilePath = $inputFilePath;\n        if ($fixtureFilePath === $inputFilePath) {\n            throw new ShouldNotHappenException('Fixture file and input file cannot be the same: ' . $fixtureFilePath);\n        }\n        // write temp file\n        FileSystem::write($inputFilePath, $inputFileContents, null);\n        $this->doTestFileMatchesExpectedContent($inputFilePath, $inputFileContents, $expectedFileContents, $fixtureFilePath, $includeFixtureDirectoryAsSource);\n    }\n    protected function doTestFileExpectingWarningAboutRuleApplied(string $fixtureFilePath, string $expectedRuleApplied): void\n    {\n        ob_start();\n        $this->doTestFile($fixtureFilePath);\n        $content = ob_get_clean();\n        $fixtureName = basename($fixtureFilePath);\n        $testClass = static::class;\n        $this->assertSame(\\PHP_EOL . 'WARNING: On fixture file \"' . $fixtureName . '\" for test \"' . $testClass . '\"' . \\PHP_EOL . 'File not changed but some Rector rules applied:' . \\PHP_EOL . ' * ' . $expectedRuleApplied . \\PHP_EOL, $content);\n    }\n    private function forgetRectorsRules(): void\n    {\n        $rectorConfig = self::getContainer();\n        // 1. forget tagged services","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/src/Testing/PHPUnit/AbstractRectorTestCase.php#L128-L164","documentation":"AbstractRectorTestCase::doTestFile() splits a fixture into input/expected halves and writes the input half to a derived temp path (createInputFilePath()). Before FileSystem::write(), it verifies the derived path differs from the fixture path; equality would mean the write destroys the source fixture, so it throws ShouldNotHappenException with the colliding path.","triggerScenarios":"The fixture already sits where the derived input path points — typically fixtures stored inside the temp directory that createInputFilePath() also uses, or a fixture filename whose transform (suffixing/extension swap) maps onto itself.","commonSituations":"Test suites relocated into sys_get_temp_dir() for CI isolation; a custom test case overriding createInputFilePath() without changing the suffix; running tests twice with cached temp fixtures from a prior aborted run.","solutions":["Keep fixtures outside the temp/input directory (standard tests/Fixtures/ layout) so paths can never collide","If you override createInputFilePath(), ensure it appends a distinct suffix (e.g. '.input' or '/input/') that the fixture itself does not carry","Clear stale temp files between runs and re-run the test"],"exampleFix":"// before: fixture and derived input path coincide\nprotected function createInputFilePath(string $fixtureFilePath): string\n{\n    return $fixtureFilePath; // identical -> throws\n}\n\n// after\nprotected function createInputFilePath(string $fixtureFilePath): string\n{\n    return $fixtureFilePath . '.input';\n}","handlingStrategy":"validation","validationCode":"// guard before doTestFile()\n$inputFilePath = $this->createInputFilePath($fixtureFilePath);\nif ($inputFilePath === $fixtureFilePath) {\n    self::markTestSkipped(sprintf('Fixture %s collides with its derived input path; move it out of the temp dir.', $fixtureFilePath));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Store fixtures under a stable tests/Fixtures directory, never under sys_get_temp_dir()","Keep createInputFilePath() derivations one-directional (fixture path + fixed suffix)","Clean derived temp inputs in tearDown() so repeat runs start from a known state"],"tags":["php","rector","testing","fixtures","path-collision"],"backgroundTag":"fixture-path-collision","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}