From 84e6b8272f3aee24251da231ae0e043d3cd12cf3 Mon Sep 17 00:00:00 2001 From: Jesper Skytte Marcussen Date: Tue, 4 Apr 2023 21:54:45 +0200 Subject: [PATCH 1/4] Extra bin-dir lookup feature The Composer bin-dir path is usually changed by setting the composer config `bin-dir`, but another common way of doing it is, if the vendor directory itself is moved by changing the `vendor-dir` configuration. --- src/Util/ComposerFile.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Util/ComposerFile.php b/src/Util/ComposerFile.php index 74cb62287..dc8545f32 100644 --- a/src/Util/ComposerFile.php +++ b/src/Util/ComposerFile.php @@ -29,6 +29,12 @@ public function getBinDir(): string if (null !== $binDir) { return (string) $binDir; } + + $binDir = $this->configuration['config']['vendor-dir'] ?? null; + + if (null !== $binDir) { + return (string) $binDir . '/bin'; + } return 'vendor/bin'; } From aabe997d9cec5555c09e00c303f57c623525545b Mon Sep 17 00:00:00 2001 From: Jesper Skytte Date: Sat, 8 Apr 2023 07:43:50 +0200 Subject: [PATCH 2/4] Change `$binDir` to `$vendorDir` as requested --- src/Util/ComposerFile.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Util/ComposerFile.php b/src/Util/ComposerFile.php index dc8545f32..8029c67e0 100644 --- a/src/Util/ComposerFile.php +++ b/src/Util/ComposerFile.php @@ -29,11 +29,11 @@ public function getBinDir(): string if (null !== $binDir) { return (string) $binDir; } - - $binDir = $this->configuration['config']['vendor-dir'] ?? null; - - if (null !== $binDir) { - return (string) $binDir . '/bin'; + + $vendorDir = $this->configuration['config']['vendor-dir'] ?? null; + + if (null !== $vendorDir) { + return $vendorDir . '/bin'; } return 'vendor/bin'; From 3cd4f7445a85d76db7077264a8a9dfbfcc3afeeb Mon Sep 17 00:00:00 2001 From: Jesper Skytte Date: Sat, 8 Apr 2023 07:44:27 +0200 Subject: [PATCH 3/4] Add unit test for method --- test/Unit/Util/ComposerFileTest.php | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/Unit/Util/ComposerFileTest.php diff --git a/test/Unit/Util/ComposerFileTest.php b/test/Unit/Util/ComposerFileTest.php new file mode 100644 index 000000000..d7fee76a8 --- /dev/null +++ b/test/Unit/Util/ComposerFileTest.php @@ -0,0 +1,46 @@ + [ + 'bin-dir' => 'alternative/bin', + ], + ]); + $this->assertSame('alternative/bin', $composerFile->getBinDir()); + } + + /** + * @test + */ + public function it_can_detect_the_bin_dir_using_the_vendordir_configuration(): void + { + $composerFile = new ComposerFile('composer.json', [ + 'config' => [ + 'vendor-dir' => 'alternative/vendor', + ], + ]); + $this->assertSame('alternative/vendor/bin', $composerFile->getBinDir()); + } + + /** + * @test + */ + public function it_can_detect_the_bin_dir_using_the_default_configuration(): void + { + $composerFile = new ComposerFile('composer.json', []); + $this->assertSame('vendor/bin', $composerFile->getBinDir()); + } +} From e0be168bc2fa7716d5fdbe93ba62b955c35e5f98 Mon Sep 17 00:00:00 2001 From: Jesper Skytte Date: Tue, 11 Apr 2023 08:45:35 +0200 Subject: [PATCH 4/4] Move tests from PhpSpec to PhpUnit --- spec/Util/ComposerFileSpec.php | 94 ----------------------------- test/Unit/Util/ComposerFileTest.php | 60 ++++++++++++++++++ 2 files changed, 60 insertions(+), 94 deletions(-) delete mode 100644 spec/Util/ComposerFileSpec.php diff --git a/spec/Util/ComposerFileSpec.php b/spec/Util/ComposerFileSpec.php deleted file mode 100644 index b774d51d7..000000000 --- a/spec/Util/ComposerFileSpec.php +++ /dev/null @@ -1,94 +0,0 @@ -beConstructedWith('/my/location/composer.json', []); - } - - function it_is_initializable() - { - $this->beConstructedWith( - '/my/location/composer.json', - [ - 'config' => [ - 'sort-packages' => true, - ] - ] - ); - $this->shouldHaveType(ComposerFile::class); - } - - function it_knows_the_composer_file_path() - { - $this->getPath()->shouldBe('/my/location/composer.json'); - } - - function it_should_have_a_default_bin_dir() - { - $this->beConstructedWith( - '/my/location/composer.json', - [ - 'config' => [ - 'sort-packages' => true, - ] - ] - ); - - $this->getBinDir()->shouldBe('vendor/bin'); - } - - function it_should_have_a_custom_bin_dir() - { - $this->beConstructedWith( - '/my/location/composer.json', - [ - 'config' => [ - 'sort-packages' => true, - 'bin-dir' => 'bin' - ] - ] - ); - - $this->getBinDir()->shouldBe('bin'); - } - - function it_should_have_a_default_config_path() - { - $this->beConstructedWith( - '/my/location/composer.json', - [ - 'config' => [ - 'sort-packages' => true, - ] - ] - ); - - $this->getConfigDefaultPath()->shouldBe(null); - } - - function it_should_have_a_custom_config_path() - { - $this->beConstructedWith( - '/my/location/composer.json', - [ - 'config' => [ - 'sort-packages' => true, - ], - 'extra' => [ - 'grumphp' => [ - 'config-default-path' => 'some/folder' - ] - ] - ] - ); - - $this->getConfigDefaultPath()->shouldBe('some/folder'); - } -} diff --git a/test/Unit/Util/ComposerFileTest.php b/test/Unit/Util/ComposerFileTest.php index d7fee76a8..6ab88f7ac 100644 --- a/test/Unit/Util/ComposerFileTest.php +++ b/test/Unit/Util/ComposerFileTest.php @@ -9,6 +9,19 @@ class ComposerFileTest extends TestCase { + /** + * @test + */ + public function it_is_initializable(): void + { + $composerFile = new ComposerFile('composer.json', [ + 'config' => [ + 'sort-packages' => true, + ] + ]); + $this->assertInstanceOf(ComposerFile::class, $composerFile); + } + /** * @test */ @@ -43,4 +56,51 @@ public function it_can_detect_the_bin_dir_using_the_default_configuration(): voi $composerFile = new ComposerFile('composer.json', []); $this->assertSame('vendor/bin', $composerFile->getBinDir()); } + + + /** + * @test + */ + public function it_knows_the_composer_file_path(): void + { + $composerFile = new ComposerFile('/my/location/composer.json', []); + $this->assertSame('/my/location/composer.json', $composerFile->getPath()); + } + + /** + * @test + */ + public function it_should_have_a_default_config_path(): void + { + $composerFile = new ComposerFile( + '/my/location/composer.json', + [ + 'config' => [ + 'sort-packages' => true, + ] + ] + ); + $this->assertNull($composerFile->getConfigDefaultPath()); + } + + /** + * @test + */ + public function it_should_have_a_custom_config_path(): void + { + $composerFile = new ComposerFile( + '/my/location/composer.json', + [ + 'config' => [ + 'sort-packages' => true, + ], + 'extra' => [ + 'grumphp' => [ + 'config-default-path' => 'some/folder' + ] + ] + ] + ); + $this->assertSame('some/folder', $composerFile->getConfigDefaultPath()); + } }