Skip to content

Commit

Permalink
Merge branch 'Don't-infer-vendor-directory-from-package-name.-Fix-for-#…
Browse files Browse the repository at this point in the history
…97' into merge
  • Loading branch information
BrianHenryIE committed Apr 8, 2021
2 parents 3f966f2 + 9cd2f71 commit 06a20de
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
19 changes: 8 additions & 11 deletions src/Mover.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,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);

Expand All @@ -147,8 +146,8 @@ public function movePackage(Package $package)
$files_to_move = array();

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) {
Expand All @@ -160,8 +159,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);

Expand Down Expand Up @@ -198,24 +196,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;

$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);
Expand Down
34 changes: 33 additions & 1 deletion tests/MoverIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 06a20de

Please sign in to comment.