From 65ea083c8b9e115a917963368d7d209d534bd6c8 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Sun, 13 Dec 2020 21:09:08 -0800 Subject: [PATCH 01/14] Mover::moveFile() --- src/Mover.php | 60 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/src/Mover.php b/src/Mover.php index 61cc2379..46106340 100644 --- a/src/Mover.php +++ b/src/Mover.php @@ -166,32 +166,34 @@ public function movePackage(Package $package) */ 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())); + + $namespacePath = $this->clean($package->config->name); + if ($autoloader instanceof NamespaceAutoloader) { - $namespacePath = $autoloader->getNamespacePath(); - $replaceWith = $this->config->dep_directory . $namespacePath; - $targetFile = str_replace($this->workingDir, $replaceWith, $file->getPathname()); - - $packageVendorPath = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $package->config->name - . DIRECTORY_SEPARATOR . $path; - $packageVendorPath = str_replace('/', DIRECTORY_SEPARATOR, $packageVendorPath); - $targetFile = str_replace($packageVendorPath, '', $targetFile); + $namespacePath = $this->clean($autoloader->getNamespacePath()); + + // TODO: Should $path come from the NameSpaceAutoloader object? + $packageVendorPath = 'vendor' . DIRECTORY_SEPARATOR . $namespacePath + . DIRECTORY_SEPARATOR . $this->clean($path); + + $mozartDepPath = $this->clean($this->config->dep_directory) . DIRECTORY_SEPARATOR . $namespacePath; + + $targetFilePath = str_ireplace($packageVendorPath, $mozartDepPath, $sourceFilePath); } else { - $namespacePath = $package->config->name; - $replaceWith = $this->config->classmap_directory . DIRECTORY_SEPARATOR . $namespacePath; - $targetFile = str_replace($this->workingDir, $replaceWith, $file->getPathname()); - - $packageVendorPath = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $package->config->name - . DIRECTORY_SEPARATOR; - $packageVendorPath = str_replace('/', DIRECTORY_SEPARATOR, $packageVendorPath); - $targetFile = str_replace($packageVendorPath, DIRECTORY_SEPARATOR, $targetFile); + $classmapDirectory = $this->clean($this->config->classmap_directory); + + $packageVendorPath = 'vendor' . DIRECTORY_SEPARATOR . $namespacePath; + + $mozartClassesPath = $classmapDirectory . DIRECTORY_SEPARATOR . $namespacePath; + + $targetFilePath = str_ireplace($packageVendorPath, $mozartClassesPath, $sourceFilePath); } - $this->filesystem->copy( - str_replace($this->workingDir, '', $file->getPathname()), - $targetFile - ); + $this->filesystem->copy($sourceFilePath, $targetFilePath); - return $targetFile; + return $targetFilePath; } /** @@ -223,4 +225,20 @@ private function dirIsEmpty($dir) $di = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS); return iterator_count($di) === 0; } + + /** + * For Windows & Unix file paths' compatibility. + * + * * Removes duplicate `\` and `/`. + * * Trims them from each end. + * * Replaces them with the OS agnostic DIRECTORY_SEPARATOR. + * + * @param string $path A full or partial filepath. + * + * @return string + */ + protected function clean($path) + { + return trim(preg_replace('/[\/\\\\]+/', DIRECTORY_SEPARATOR, $path), DIRECTORY_SEPARATOR); + } } From f0e6aec71c20633cb053714afe4c4c7106afb88e Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Sun, 13 Dec 2020 21:26:05 -0800 Subject: [PATCH 02/14] Clean everything as it enters the object --- src/Mover.php | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/src/Mover.php b/src/Mover.php index 46106340..d91ed90f 100644 --- a/src/Mover.php +++ b/src/Mover.php @@ -19,10 +19,7 @@ class Mover protected $workingDir; /** @var string */ - protected $targetDir; - - /** @var \stdClass */ - protected $config; + protected $dep_directory; /** @var Filesystem */ protected $filesystem; @@ -32,9 +29,11 @@ class Mover public function __construct($workingDir, $config) { - $this->workingDir = $workingDir; - $this->targetDir = $config->dep_directory; - $this->config = $config; + + $this->workingDir = DIRECTORY_SEPARATOR . $this->clean($workingDir); + + $this->dep_directory = $this->clean($config->dep_directory); + $this->classmap_directory = $this->clean($config->classmap_directory); $this->filesystem = new Filesystem(new Local($this->workingDir)); } @@ -46,9 +45,9 @@ public function __construct($workingDir, $config) */ public function deleteTargetDirs($packages) { - $this->filesystem->createDir($this->config->dep_directory); + $this->filesystem->createDir($this->dep_directory); - $this->filesystem->createDir($this->config->classmap_directory); + $this->filesystem->createDir($this->classmap_directory); foreach ($packages as $package) { $this->deleteDepTargetDirs($package); @@ -70,13 +69,11 @@ private function deleteDepTargetDirs($package) switch ($autoloaderType) { case Psr0::class: case Psr4::class: - $outputDir = $this->config->dep_directory . $packageAutoloader->namespace; - $outputDir = str_replace('\\', DIRECTORY_SEPARATOR, $outputDir); + $outputDir = $this->dep_directory . DIRECTORY_SEPARATOR . $this->clean($packageAutoloader->namespace); $this->filesystem->deleteDir($outputDir); break; case Classmap::class: - $outputDir = $this->config->classmap_directory . $package->config->name; - $outputDir = str_replace('\\', DIRECTORY_SEPARATOR, $outputDir); + $outputDir = $this->classmap_directory . DIRECTORY_SEPARATOR . $this->clean($package->config->name); $this->filesystem->deleteDir($outputDir); break; } @@ -89,12 +86,12 @@ private function deleteDepTargetDirs($package) public function deleteEmptyDirs() { - if (count($this->filesystem->listContents($this->config->dep_directory, true)) === 0) { - $this->filesystem->deleteDir($this->config->dep_directory); + if (count($this->filesystem->listContents($this->dep_directory, true)) === 0) { + $this->filesystem->deleteDir($this->dep_directory); } - if (count($this->filesystem->listContents($this->config->classmap_directory, true)) === 0) { - $this->filesystem->deleteDir($this->config->classmap_directory); + if (count($this->filesystem->listContents($this->classmap_directory, true)) === 0) { + $this->filesystem->deleteDir($this->classmap_directory); } } @@ -110,9 +107,7 @@ public function movePackage(Package $package) foreach ($autoloader->paths as $path) { $source_path = $this->workingDir . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR - . $package->config->name . DIRECTORY_SEPARATOR . $path; - - $source_path = str_replace('/', DIRECTORY_SEPARATOR, $source_path); + . $this->clean($package->config->name) . DIRECTORY_SEPARATOR . $this->clean($path); $finder->files()->in($source_path); @@ -125,7 +120,7 @@ public function movePackage(Package $package) foreach ($autoloader->files as $file) { $source_path = $this->workingDir . DIRECTORY_SEPARATOR . 'vendor' - . DIRECTORY_SEPARATOR . $package->config->name; + . DIRECTORY_SEPARATOR . $this->clean($package->config->name); $finder->files()->name($file)->in($source_path); foreach ($finder as $foundFile) { @@ -136,8 +131,8 @@ public function movePackage(Package $package) $finder = new Finder(); foreach ($autoloader->paths as $path) { - $source_path = $this->workingDir . DIRECTORY_SEPARATOR . 'vendor' - . DIRECTORY_SEPARATOR . $package->config->name . DIRECTORY_SEPARATOR . $path; + $source_path = $this->workingDir . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . + $this->clean($package->config->name) . DIRECTORY_SEPARATOR . $this->clean($path); $finder->files()->in($source_path); @@ -178,11 +173,11 @@ public function moveFile(Package $package, $autoloader, $file, $path = '') $packageVendorPath = 'vendor' . DIRECTORY_SEPARATOR . $namespacePath . DIRECTORY_SEPARATOR . $this->clean($path); - $mozartDepPath = $this->clean($this->config->dep_directory) . DIRECTORY_SEPARATOR . $namespacePath; + $mozartDepPath = $this->dep_directory . DIRECTORY_SEPARATOR . $namespacePath; $targetFilePath = str_ireplace($packageVendorPath, $mozartDepPath, $sourceFilePath); } else { - $classmapDirectory = $this->clean($this->config->classmap_directory); + $classmapDirectory = $this->classmap_directory; $packageVendorPath = 'vendor' . DIRECTORY_SEPARATOR . $namespacePath; @@ -204,7 +199,7 @@ public function moveFile(Package $package, $autoloader, $file, $path = '') protected function deletePackageVendorDirectories() { foreach ($this->movedPackages as $movedPackage) { - $packageDir = 'vendor' . DIRECTORY_SEPARATOR . $movedPackage; + $packageDir = 'vendor' . DIRECTORY_SEPARATOR . $this->clean($movedPackage); if (!is_dir($packageDir) || is_link($packageDir)) { continue; } From 4adc6b47fa925e1389c3e004c13672116e10cf29 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Sun, 13 Dec 2020 21:30:58 -0800 Subject: [PATCH 03/14] Mark $workingdir as having a leading slash. --- src/Mover.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Mover.php b/src/Mover.php index d91ed90f..655f5b5f 100644 --- a/src/Mover.php +++ b/src/Mover.php @@ -15,7 +15,11 @@ class Mover { - /** @var string */ + /** + * The only path variable with a leading slash. + * + * @var string + */ protected $workingDir; /** @var string */ From 6209aa5f5952b2d83087533985898bdbd0bf4857 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Sun, 13 Dec 2020 21:39:34 -0800 Subject: [PATCH 04/14] Update Mover.php --- src/Mover.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Mover.php b/src/Mover.php index 655f5b5f..2a1cf6dc 100644 --- a/src/Mover.php +++ b/src/Mover.php @@ -10,6 +10,7 @@ use CoenJacobs\Mozart\Composer\Package; use League\Flysystem\Adapter\Local; use League\Flysystem\Filesystem; +use stdClass; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; @@ -25,6 +26,12 @@ class Mover /** @var string */ protected $dep_directory; + /** @var string */ + protected $classmap_directory; + + /** @var stdClass */ + protected $config; + /** @var Filesystem */ protected $filesystem; @@ -33,6 +40,7 @@ class Mover public function __construct($workingDir, $config) { + $this->config = $config; $this->workingDir = DIRECTORY_SEPARATOR . $this->clean($workingDir); @@ -73,7 +81,8 @@ private function deleteDepTargetDirs($package) switch ($autoloaderType) { case Psr0::class: case Psr4::class: - $outputDir = $this->dep_directory . DIRECTORY_SEPARATOR . $this->clean($packageAutoloader->namespace); + $outputDir = $this->dep_directory . DIRECTORY_SEPARATOR . + $this->clean($packageAutoloader->namespace); $this->filesystem->deleteDir($outputDir); break; case Classmap::class: From faacfbe5f416022c9b9cf7bd1286e1959890713e Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 14 Dec 2020 12:32:08 -0800 Subject: [PATCH 05/14] Comments and typing --- src/Composer/Autoload/NamespaceAutoloader.php | 6 ++++-- src/Composer/Autoload/Psr0.php | 3 +++ src/Composer/Autoload/Psr4.php | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Composer/Autoload/NamespaceAutoloader.php b/src/Composer/Autoload/NamespaceAutoloader.php index dfd20499..bbc8e5b3 100644 --- a/src/Composer/Autoload/NamespaceAutoloader.php +++ b/src/Composer/Autoload/NamespaceAutoloader.php @@ -2,6 +2,8 @@ namespace CoenJacobs\Mozart\Composer\Autoload; +use stdClass; + abstract class NamespaceAutoloader implements Autoloader { /** @var string */ @@ -17,9 +19,9 @@ abstract class NamespaceAutoloader implements Autoloader public $paths = []; /** - * A package's composer.json config autoload key's value, where $key is `psr-1`|`psr-4`|`classmap`. + * A package's composer.json config autoload key's value, where $key is `psr-0`|`psr-4`|`classmap`. * - * @param $autoloadConfig + * @param stdClass[] $autoloadConfig */ public function processConfig($autoloadConfig) { diff --git a/src/Composer/Autoload/Psr0.php b/src/Composer/Autoload/Psr0.php index 2a009821..1a8028c4 100644 --- a/src/Composer/Autoload/Psr0.php +++ b/src/Composer/Autoload/Psr0.php @@ -1,4 +1,7 @@ namespace, '\\'); } - public function getNamespacePath() + public function getNamespacePath(): string { return str_replace('\\', DIRECTORY_SEPARATOR, $this->namespace); } From d579931a070def911b2b63d4a0ab2019064f0d48 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 14 Dec 2020 12:38:40 -0800 Subject: [PATCH 06/14] Failing testes for #43 #90 --- tests/MoverIntegrationTest.php | 168 +++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 tests/MoverIntegrationTest.php diff --git a/tests/MoverIntegrationTest.php b/tests/MoverIntegrationTest.php new file mode 100644 index 00000000..0e0d654d --- /dev/null +++ b/tests/MoverIntegrationTest.php @@ -0,0 +1,168 @@ +testsWorkingDir = __DIR__ . '/temptestdir'; + if (file_exists($this->testsWorkingDir)) { + $this->delete_dir($this->testsWorkingDir); + } + mkdir($this->testsWorkingDir); + + $mozart_config = new class() { + public $dep_namespace = "Mozart"; + public $classmap_prefix = "Mozart_"; + public $dep_directory = "/dep_directory/"; + public $classmap_directory = "/classmap_directory/"; + + }; + + $composer = new class() { + public $require = array(); + public $extra; + }; + + $composer->extra = new class() { + public $mozart; + }; + + $composer->extra->mozart = $mozart_config; + + $this->composer = $composer; + } + + /** + * Issue 43. Needs "aws/aws-sdk-php". + * + * League\Flysystem\FileExistsException : File already exists at path: + * dep_directory/vendor/guzzle/guzzle/src/Guzzle/Cache/Zf1CacheAdapter.php + */ + public function test_aws_sdk_succeeds() + { + + $composer = $this->composer; + + $composer->require["aws/aws-sdk-php"] = "2.8.31"; + + 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); + + try { + $php_string = file_get_contents($this->testsWorkingDir . '/dep_directory/Aws/Ses/Common/Aws.php'); + } catch (FileExistsException $e) { + $this->fail(); + } + +// $this->assertStringContainsString('class Mpdf implements', $php_string); + } + + + /** + * Issue 90. Needs "iio/libmergepdf". + * + * Error: "File already exists at path: classmap_directory/tecnickcom/tcpdf/tcpdf.php". + */ + public function test_libpdfmerge_succeeds() + { + + $composer = $this->composer; + + $composer->require["iio/libmergepdf"] = "4.0.3"; + + 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); + // classmap_directory/tecnickcom/tcpdf/tcpdf.php + $php_string = file_get_contents($this->testsWorkingDir .'/dep_directory/iio/libmergepdf/tcpdi/tcpdi.php'); + +// // Confirm solution is correct. +// $this->assertStringContainsString('class Mpdf implements', $php_string); + } + + + /** + * Delete $this->testsWorkingDir after each test. + * + * @see https://stackoverflow.com/questions/3349753/delete-directory-with-files-in-it + */ + public function tearDown(): void + { + parent::tearDown(); + + $dir = $this->testsWorkingDir; + + $this->delete_dir($dir); + } + + protected function delete_dir($dir) + { + if(!file_exists($dir)){ + return; + } + + + $it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS); + $files = new RecursiveIteratorIterator( + $it, + RecursiveIteratorIterator::CHILD_FIRST + ); + foreach ($files as $file) { + if ($file->isDir()) { + rmdir($file->getRealPath()); + } else { + unlink($file->getRealPath()); + } + } + rmdir($dir); + } +} From 4152deb6d3892a7f66fc24c4fb674d45683f948f Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 14 Dec 2020 12:40:34 -0800 Subject: [PATCH 07/14] Make NamespaceAutoloader::getNamespacePath abstract Previous inheritence required PSR-4 to override anyway. --- src/Composer/Autoload/NamespaceAutoloader.php | 5 +---- src/Composer/Autoload/Psr0.php | 5 +++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Composer/Autoload/NamespaceAutoloader.php b/src/Composer/Autoload/NamespaceAutoloader.php index bbc8e5b3..6d31b3e3 100644 --- a/src/Composer/Autoload/NamespaceAutoloader.php +++ b/src/Composer/Autoload/NamespaceAutoloader.php @@ -36,8 +36,5 @@ public function getSearchNamespace() return $this->namespace; } - public function getNamespacePath() - { - return ''; - } + abstract public function getNamespacePath(): string; } diff --git a/src/Composer/Autoload/Psr0.php b/src/Composer/Autoload/Psr0.php index 1a8028c4..1fba42b4 100644 --- a/src/Composer/Autoload/Psr0.php +++ b/src/Composer/Autoload/Psr0.php @@ -7,4 +7,9 @@ class Psr0 extends NamespaceAutoloader { + + public function getNamespacePath(): string + { + return ''; + } } From c795e97b63b10b79668653d29476693a8a868e8e Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 14 Dec 2020 14:24:33 -0800 Subject: [PATCH 08/14] Update MoverIntegrationTest.php --- tests/MoverIntegrationTest.php | 56 +++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/tests/MoverIntegrationTest.php b/tests/MoverIntegrationTest.php index 0e0d654d..def655bf 100644 --- a/tests/MoverIntegrationTest.php +++ b/tests/MoverIntegrationTest.php @@ -2,15 +2,12 @@ declare(strict_types=1); use CoenJacobs\Mozart\Console\Commands\Compose; -use League\Flysystem\FileExistsException; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** - * @covers CoenJacobs\Mozart\Mover:: - * - + * @codeCoverageIgnore */ class MoverIntegrationTest extends TestCase { @@ -62,20 +59,40 @@ public function setUp(): void $this->composer = $composer; } + /** * Issue 43. Needs "aws/aws-sdk-php". * * League\Flysystem\FileExistsException : File already exists at path: * dep_directory/vendor/guzzle/guzzle/src/Guzzle/Cache/Zf1CacheAdapter.php */ - public function test_aws_sdk_succeeds() + public function testAwsSdkSucceeds() { $composer = $this->composer; $composer->require["aws/aws-sdk-php"] = "2.8.31"; - file_put_contents($this->testsWorkingDir . '/composer.json', json_encode($composer)); + $composer->extra->mozart->override_autoload = new class() { + public $guzzle_guzzle; + + public function __construct() + { + $this->guzzle_guzzle = new class() { + public $psr_4 = array( + "Guzzle"=>"src/" + ); + }; + } + }; + + $composer_json_string = json_encode($composer); + + $composer_json_string = str_replace("psr_4", "psr-4", $composer_json_string); + $composer_json_string = str_replace("guzzle_guzzle", "guzzle/guzzle", $composer_json_string); + + + file_put_contents($this->testsWorkingDir . '/composer.json', $composer_json_string); chdir($this->testsWorkingDir); @@ -88,13 +105,9 @@ public function test_aws_sdk_succeeds() $result = $mozartCompose->run($inputInterfaceMock, $outputInterfaceMock); - try { - $php_string = file_get_contents($this->testsWorkingDir . '/dep_directory/Aws/Ses/Common/Aws.php'); - } catch (FileExistsException $e) { - $this->fail(); - } + $this->assertEquals(0, $result); -// $this->assertStringContainsString('class Mpdf implements', $php_string); + $this->assertFileExists($this->testsWorkingDir . '/dep_directory/Aws/Common/Aws.php'); } @@ -103,7 +116,7 @@ public function test_aws_sdk_succeeds() * * Error: "File already exists at path: classmap_directory/tecnickcom/tcpdf/tcpdf.php". */ - public function test_libpdfmerge_succeeds() + public function testLibpdfmergeSucceeds() { $composer = $this->composer; @@ -122,11 +135,13 @@ public function test_libpdfmerge_succeeds() $mozartCompose = new Compose(); $result = $mozartCompose->run($inputInterfaceMock, $outputInterfaceMock); - // classmap_directory/tecnickcom/tcpdf/tcpdf.php - $php_string = file_get_contents($this->testsWorkingDir .'/dep_directory/iio/libmergepdf/tcpdi/tcpdi.php'); -// // Confirm solution is correct. -// $this->assertStringContainsString('class Mpdf implements', $php_string); + $this->assertEquals(0, $result); + + // This test would only fail on Windows? + $this->assertDirectoryNotExists($this->testsWorkingDir .'classmap_directory/iio/libmergepdf/vendor/iio/libmergepdf/tcpdi'); + + $this->assertFileExists($this->testsWorkingDir .'/classmap_directory/iio/libmergepdf/tcpdi/tcpdi.php'); } @@ -146,10 +161,9 @@ public function tearDown(): void protected function delete_dir($dir) { - if(!file_exists($dir)){ - return; - } - + if (!file_exists($dir)) { + return; + } $it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS); $files = new RecursiveIteratorIterator( From 878811856abf676e235b9afd85fb3ee150169fa2 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 14 Dec 2020 14:25:54 -0800 Subject: [PATCH 09/14] Fix $namespacePath -> $packageName And rename variables for better understandinf --- src/Mover.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Mover.php b/src/Mover.php index 2a1cf6dc..1d8b835b 100644 --- a/src/Mover.php +++ b/src/Mover.php @@ -177,26 +177,25 @@ 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())); - $namespacePath = $this->clean($package->config->name); + $packageName = $this->clean($package->config->name); if ($autoloader instanceof NamespaceAutoloader) { $namespacePath = $this->clean($autoloader->getNamespacePath()); // TODO: Should $path come from the NameSpaceAutoloader object? - $packageVendorPath = 'vendor' . DIRECTORY_SEPARATOR . $namespacePath - . DIRECTORY_SEPARATOR . $this->clean($path); + $sourceVendorPath = $this->clean('vendor' . DIRECTORY_SEPARATOR . $packageName + . DIRECTORY_SEPARATOR . $path); - $mozartDepPath = $this->dep_directory . DIRECTORY_SEPARATOR . $namespacePath; + $destinationMozartPath = $this->dep_directory . DIRECTORY_SEPARATOR . $namespacePath; - $targetFilePath = str_ireplace($packageVendorPath, $mozartDepPath, $sourceFilePath); + $targetFilePath = str_ireplace($sourceVendorPath, $destinationMozartPath, $sourceFilePath); } else { - $classmapDirectory = $this->classmap_directory; - $packageVendorPath = 'vendor' . DIRECTORY_SEPARATOR . $namespacePath; + $sourceVendorPath = 'vendor' . DIRECTORY_SEPARATOR . $packageName; - $mozartClassesPath = $classmapDirectory . DIRECTORY_SEPARATOR . $namespacePath; + $destinationMozartPath = $this->classmap_directory . DIRECTORY_SEPARATOR . $packageName; - $targetFilePath = str_ireplace($packageVendorPath, $mozartClassesPath, $sourceFilePath); + $targetFilePath = str_ireplace($sourceVendorPath, $destinationMozartPath, $sourceFilePath); } $this->filesystem->copy($sourceFilePath, $targetFilePath); From 832a5587e4ad3ccc200a0395d200d9e67c3a92c7 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 14 Dec 2020 14:26:39 -0800 Subject: [PATCH 10/14] Update .gitignore The integration tests are creating a temptestdir which is deleted after each test is run, but when they fail remains. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 3d6c7cac..46161589 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ vendor/ .DS_Store composer.lock .phpunit.result.cache + +temptestdir \ No newline at end of file From 7bde094f38012f2d64c7c5ff8ef2f16b575286e8 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Wed, 16 Dec 2020 12:22:19 -0800 Subject: [PATCH 11/14] Do not "clean" $workingDir Source of `$workingDir` is `getcwd()`. Automated tests pass on MacOS. Manual test passes on Windows: https://github.com/coenjacobs/mozart/issues/90#issuecomment-746851736 --- src/Mover.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mover.php b/src/Mover.php index 1d8b835b..3c59a13c 100644 --- a/src/Mover.php +++ b/src/Mover.php @@ -41,8 +41,8 @@ class Mover public function __construct($workingDir, $config) { $this->config = $config; - - $this->workingDir = DIRECTORY_SEPARATOR . $this->clean($workingDir); + + $this->workingDir = $workingDir; $this->dep_directory = $this->clean($config->dep_directory); $this->classmap_directory = $this->clean($config->classmap_directory); From 43258873454631212455756a6f34350b836805ad Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Sat, 30 Jan 2021 12:58:28 -0800 Subject: [PATCH 12/14] Bad merge conflict fix fixed --- src/Composer/Autoload/NamespaceAutoloader.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Composer/Autoload/NamespaceAutoloader.php b/src/Composer/Autoload/NamespaceAutoloader.php index e5999247..669b02c8 100644 --- a/src/Composer/Autoload/NamespaceAutoloader.php +++ b/src/Composer/Autoload/NamespaceAutoloader.php @@ -22,7 +22,6 @@ abstract class NamespaceAutoloader implements Autoloader * A package's composer.json config autoload key's value, where $key is `psr-0`|`psr-4`|`classmap`. * * @param stdClass[] $autoloadConfig - * @param $autoloadConfig * * @return void */ From fe4702e2189d8ee7835bdb45995549227f65e98d Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Sat, 30 Jan 2021 13:06:52 -0800 Subject: [PATCH 13/14] lint psalm --- src/Composer/Autoload/NamespaceAutoloader.php | 2 +- src/Mover.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Composer/Autoload/NamespaceAutoloader.php b/src/Composer/Autoload/NamespaceAutoloader.php index 669b02c8..b073eb69 100644 --- a/src/Composer/Autoload/NamespaceAutoloader.php +++ b/src/Composer/Autoload/NamespaceAutoloader.php @@ -21,7 +21,7 @@ abstract class NamespaceAutoloader implements Autoloader /** * A package's composer.json config autoload key's value, where $key is `psr-0`|`psr-4`|`classmap`. * - * @param stdClass[] $autoloadConfig + * @param $autoloadConfig * * @return void */ diff --git a/src/Mover.php b/src/Mover.php index 4bf4e296..cd23ffd7 100644 --- a/src/Mover.php +++ b/src/Mover.php @@ -198,14 +198,13 @@ public function moveFile(Package $package, $autoloader, $file, $path = '') $namespacePath = $this->clean($autoloader->getNamespacePath()); // TODO: Should $path come from the NameSpaceAutoloader object? - $sourceVendorPath = $this->clean('vendor' . DIRECTORY_SEPARATOR . $packageName + $sourceVendorPath = $this->clean('vendor' . DIRECTORY_SEPARATOR . $packageName . 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; $destinationMozartPath = $this->classmap_directory . DIRECTORY_SEPARATOR . $packageName; From f78e341b6c1e169e73d325b50306d2b2a03ecddb Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Sun, 7 Feb 2021 13:09:07 -0800 Subject: [PATCH 14/14] Update libmergepdf versioin for PHP 8 --- tests/MoverIntegrationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/MoverIntegrationTest.php b/tests/MoverIntegrationTest.php index def655bf..45d6cfc6 100644 --- a/tests/MoverIntegrationTest.php +++ b/tests/MoverIntegrationTest.php @@ -121,7 +121,7 @@ public function testLibpdfmergeSucceeds() $composer = $this->composer; - $composer->require["iio/libmergepdf"] = "4.0.3"; + $composer->require["iio/libmergepdf"] = "4.0.4"; file_put_contents($this->testsWorkingDir . '/composer.json', json_encode($composer));