Skip to content

Commit

Permalink
Merge pull request #1080 from greew/greew-patch-1
Browse files Browse the repository at this point in the history
Extra bin-dir lookup feature
  • Loading branch information
veewee authored Apr 20, 2023
2 parents d600fc6 + e0be168 commit 4505f01
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 94 deletions.
94 changes: 0 additions & 94 deletions spec/Util/ComposerFileSpec.php

This file was deleted.

6 changes: 6 additions & 0 deletions src/Util/ComposerFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public function getBinDir(): string
return (string) $binDir;
}

$vendorDir = $this->configuration['config']['vendor-dir'] ?? null;

if (null !== $vendorDir) {
return $vendorDir . '/bin';
}

return 'vendor/bin';
}

Expand Down
106 changes: 106 additions & 0 deletions test/Unit/Util/ComposerFileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

declare(strict_types=1);

namespace GrumPHPTest\Unit\Util;

use GrumPHP\Util\ComposerFile;
use PHPUnit\Framework\TestCase;

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
*/
public function it_can_detect_the_bin_dir_using_the_bindir_configuration(): void
{
$composerFile = new ComposerFile('composer.json', [
'config' => [
'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());
}


/**
* @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());
}
}

0 comments on commit 4505f01

Please sign in to comment.