From d04194116cd6c573a046b31f8cda9b9c11973278 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Thu, 24 Oct 2024 20:17:41 -0700 Subject: [PATCH] Fix 108 --- src/FileEnumerator.php | 4 +- tests/Issues/StraussIssue108Test.php | 78 ++++++++++++++++++++++++++++ tests/Unit/PrefixerTest.php | 28 ++++++++++ 3 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 tests/Issues/StraussIssue108Test.php diff --git a/src/FileEnumerator.php b/src/FileEnumerator.php index b63214a9..9684ce2b 100644 --- a/src/FileEnumerator.php +++ b/src/FileEnumerator.php @@ -172,8 +172,8 @@ protected function addFile(ComposerPackage $dependency, string $packageRelativeP $projectRelativePath = $this->vendorDir . $outputRelativeFilepath; $isOutsideProjectDir = 0 !== strpos($sourceAbsoluteFilepath, $this->workingDir); - $f = $this->discoveredFiles[$outputRelativeFilepath] - ?? new File($dependency, $packageRelativePath, $sourceAbsoluteFilepath); + $f = $this->discoveredFiles->getFiles()[$outputRelativeFilepath] + ?? new File($dependency, $packageRelativePath, $sourceAbsoluteFilepath); $f->addAutoloader($autoloaderType); $f->setDoDelete($isOutsideProjectDir); diff --git a/tests/Issues/StraussIssue108Test.php b/tests/Issues/StraussIssue108Test.php new file mode 100644 index 00000000..d12b48a4 --- /dev/null +++ b/tests/Issues/StraussIssue108Test.php @@ -0,0 +1,78 @@ +testsWorkingDir); + + file_put_contents($this->testsWorkingDir . '/composer.json', $composerJsonString); + + @mkdir($this->testsWorkingDir . 'src'); + $replacementfilePath = $this->testsWorkingDir . '/src/file.php'; + file_put_contents($replacementfilePath, $replacementfile); + + exec('composer install'); + + $this->runStrauss(); + + $php_string = file_get_contents($replacementfilePath); + + self::assertStringNotContainsString("use Parsedown as MarkdownParser;", $php_string); + self::assertStringContainsString("use Prefixed_Parsedown as MarkdownParser;", $php_string); + } +} diff --git a/tests/Unit/PrefixerTest.php b/tests/Unit/PrefixerTest.php index 21928fba..57e7b47d 100644 --- a/tests/Unit/PrefixerTest.php +++ b/tests/Unit/PrefixerTest.php @@ -1939,4 +1939,32 @@ public static function ini( self::assertEqualsRN($expected, $result); } + public function testPrefixesAliasedGlobalClass(): void + { + $contents = <<<'EOD' +createMock(StraussConfig::class); + + $replacer = new Prefixer($config, __DIR__); + $result = $replacer->replaceClassname($contents, 'GlobalClass', 'Prefixed_'); + + $this->assertEqualsRN($expected, $result); + } }