From 68bea5bfb8cce11627897da69dbda4097e6e7d4c Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 14 Dec 2020 15:58:15 -0800 Subject: [PATCH 1/3] Failing test for #97 --- tests/MoverIntegrationTest.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/MoverIntegrationTest.php b/tests/MoverIntegrationTest.php index def655bf..de8b7f5f 100644 --- a/tests/MoverIntegrationTest.php +++ b/tests/MoverIntegrationTest.php @@ -145,7 +145,39 @@ public function testLibpdfmergeSucceeds() } - /** + + /** + * Issue 97. Package named "crewlabs/unsplash" is downloaded to `vendor/crewlabs/unsplash` but their composer.json + * has the package name as "unsplash/unsplash". + * + * "The "/Users/BrianHenryIE/Sites/mozart-97/vendor/unsplash/unsplash/src" directory does not exist." + */ + public function testCrewlabsUnsplashSucceeds() + { + + $composer = $this->composer; + + $composer->require["crewlabs/unsplash"] = "3.1.0"; + + file_put_contents($this->testsWorkingDir . '/composer.json', json_encode($composer)); + + chdir($this->testsWorkingDir); + + exec('composer install'); + + $inputInterfaceMock = $this->createMock(InputInterface::class); + $outputInterfaceMock = $this->createMock(OutputInterface::class); + + $mozartCompose = new Compose(); + + $result = $mozartCompose->run($inputInterfaceMock, $outputInterfaceMock); + + $this->assertEquals(0, $result); + + } + + + /** * Delete $this->testsWorkingDir after each test. * * @see https://stackoverflow.com/questions/3349753/delete-directory-with-files-in-it From 2902bd4eb3d210ffc21b952bc24f415944b2ccd5 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 14 Dec 2020 16:01:01 -0800 Subject: [PATCH 2/3] Use $package->path not $packageName to determine directories --- src/Mover.php | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Mover.php b/src/Mover.php index 1d8b835b..3eed3d37 100644 --- a/src/Mover.php +++ b/src/Mover.php @@ -119,8 +119,7 @@ public function movePackage(Package $package) $finder = new Finder(); foreach ($autoloader->paths as $path) { - $source_path = $this->workingDir . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR - . $this->clean($package->config->name) . DIRECTORY_SEPARATOR . $this->clean($path); + $source_path = DIRECTORY_SEPARATOR . $this->clean($package->path . DIRECTORY_SEPARATOR . $path); $finder->files()->in($source_path); @@ -132,8 +131,8 @@ public function movePackage(Package $package) $finder = new Finder(); foreach ($autoloader->files as $file) { - $source_path = $this->workingDir . DIRECTORY_SEPARATOR . 'vendor' - . DIRECTORY_SEPARATOR . $this->clean($package->config->name); + $source_path = DIRECTORY_SEPARATOR . $this->clean($package->path); + $finder->files()->name($file)->in($source_path); foreach ($finder as $foundFile) { @@ -144,8 +143,7 @@ public function movePackage(Package $package) $finder = new Finder(); foreach ($autoloader->paths as $path) { - $source_path = $this->workingDir . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . - $this->clean($package->config->name) . DIRECTORY_SEPARATOR . $this->clean($path); + $source_path = DIRECTORY_SEPARATOR . $this->clean($package->path . DIRECTORY_SEPARATOR . $path); $finder->files()->in($source_path); @@ -177,25 +175,23 @@ public function moveFile(Package $package, $autoloader, $file, $path = '') // The relative path to the file from the project root. $sourceFilePath = $this->clean(str_replace($this->workingDir, '', $file->getPathname())); - $packageName = $this->clean($package->config->name); + $packagePath = $this->clean(str_replace($this->workingDir, '', $package->path)); if ($autoloader instanceof NamespaceAutoloader) { $namespacePath = $this->clean($autoloader->getNamespacePath()); // TODO: Should $path come from the NameSpaceAutoloader object? - $sourceVendorPath = $this->clean('vendor' . DIRECTORY_SEPARATOR . $packageName - . DIRECTORY_SEPARATOR . $path); + $sourceVendorPath = $this->clean($packagePath . DIRECTORY_SEPARATOR . $path); - $destinationMozartPath = $this->dep_directory . DIRECTORY_SEPARATOR . $namespacePath; + $destinationMozartPath = $this->dep_directory . DIRECTORY_SEPARATOR . $namespacePath; $targetFilePath = str_ireplace($sourceVendorPath, $destinationMozartPath, $sourceFilePath); } else { - - $sourceVendorPath = 'vendor' . DIRECTORY_SEPARATOR . $packageName; + $packageName = $this->clean($package->config->name); $destinationMozartPath = $this->classmap_directory . DIRECTORY_SEPARATOR . $packageName; - $targetFilePath = str_ireplace($sourceVendorPath, $destinationMozartPath, $sourceFilePath); + $targetFilePath = str_ireplace($packagePath, $destinationMozartPath, $sourceFilePath); } $this->filesystem->copy($sourceFilePath, $targetFilePath); From 9cd2f714c4bf455533bc32e29ae56cbd0c474cf9 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Sun, 7 Feb 2021 13:25:04 -0800 Subject: [PATCH 3/3] phpcbf --- src/Mover.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Mover.php b/src/Mover.php index 75ab6a14..1058a057 100644 --- a/src/Mover.php +++ b/src/Mover.php @@ -193,20 +193,20 @@ public function moveFile(Package $package, $autoloader, $file, $path = '') $packagePath = $this->clean(str_replace($this->workingDir, '', $package->path)); if ($autoloader instanceof NamespaceAutoloader) { - $namespacePath = $this->clean($autoloader->getNamespacePath()); + $namespacePath = $this->clean($autoloader->getNamespacePath()); - // TODO: Should $path come from the NameSpaceAutoloader object? - $sourceVendorPath = $this->clean($packagePath . DIRECTORY_SEPARATOR . $path); + // TODO: Should $path come from the NameSpaceAutoloader object? + $sourceVendorPath = $this->clean($packagePath . DIRECTORY_SEPARATOR . $path); - $destinationMozartPath = $this->dep_directory . DIRECTORY_SEPARATOR . $namespacePath; + $destinationMozartPath = $this->dep_directory . DIRECTORY_SEPARATOR . $namespacePath; - $targetFilePath = str_ireplace($sourceVendorPath, $destinationMozartPath, $sourceFilePath); + $targetFilePath = str_ireplace($sourceVendorPath, $destinationMozartPath, $sourceFilePath); } else { - $packageName = $this->clean($package->config->name); + $packageName = $this->clean($package->config->name); - $destinationMozartPath = $this->classmap_directory . DIRECTORY_SEPARATOR . $packageName; + $destinationMozartPath = $this->classmap_directory . DIRECTORY_SEPARATOR . $packageName; - $targetFilePath = str_ireplace($packagePath, $destinationMozartPath, $sourceFilePath); + $targetFilePath = str_ireplace($packagePath, $destinationMozartPath, $sourceFilePath); } $this->filesystem->copy($sourceFilePath, $targetFilePath);