Skip to content

Commit d3a74a4

Browse files
committed
fix: use bin-dir for correct path to the Composer executables
1 parent e6ef7e9 commit d3a74a4

File tree

5 files changed

+82
-25
lines changed

5 files changed

+82
-25
lines changed

CHANGELOG.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2121
### Security
2222

2323

24+
## [1.0.1] - 2020-08-25
25+
26+
### Fixed
27+
28+
* use `bin-dir` for correct path to the Composer executables
29+
30+
2431
## [1.0.0] - 2020-08-25
2532

2633
### Added
2734

2835
* create a REPL plugin for Composer
2936

3037

31-
[Unreleased]: https://github.com/ramsey/composer-repl/compare/1.0.0...HEAD
38+
[Unreleased]: https://github.com/ramsey/composer-repl/compare/1.0.1...HEAD
39+
[1.0.1]: https://github.com/ramsey/composer-repl/compare/1.0.0...1.0.1
3240
[1.0.0]: https://github.com/ramsey/composer-repl/commits/1.0.0

src/Composer/ReplCommand.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9898
$config->setInteractiveMode(Configuration::INTERACTIVE_MODE_DISABLED);
9999
}
100100

101+
/** @var Composer $composer */
102+
$composer = $this->getComposer(true);
103+
101104
$shell = new Shell($config);
102105
$shell->setScopeVariables($this->getScopeVariables());
103106
$shell->add(new PhpunitTestCommand());
104-
$shell->add(new PhpunitRunCommand($this->repositoryRoot, $this->processFactory));
107+
$shell->add(new PhpunitRunCommand(
108+
$this->repositoryRoot,
109+
$this->processFactory,
110+
$composer,
111+
));
105112
$shell->add(new 🐘Command());
106113

107114
return $shell->run();

src/Composer/ReplPlugin.php

+31-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,19 @@
2525
use Composer\Command\BaseCommand;
2626
use Composer\Composer;
2727
use Composer\Factory;
28+
use Composer\IO\ConsoleIO;
2829
use Composer\IO\IOInterface;
2930
use Composer\Plugin\Capability\CommandProvider;
3031
use Composer\Plugin\Capable;
3132
use Composer\Plugin\PluginInterface;
3233
use Ramsey\Dev\Repl\Process\ProcessFactory;
34+
use Symfony\Component\Console\Helper\DescriptorHelper;
35+
use Symfony\Component\Console\Helper\FormatterHelper;
36+
use Symfony\Component\Console\Helper\HelperSet;
37+
use Symfony\Component\Console\Helper\ProcessHelper;
38+
use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
39+
use Symfony\Component\Console\Input\StringInput;
40+
use Symfony\Component\Console\Output\ConsoleOutput;
3341

3442
use function realpath;
3543

@@ -40,6 +48,7 @@ class ReplPlugin implements Capable, CommandProvider, PluginInterface
4048
{
4149
private ProcessFactory $processFactory;
4250
private string $repoRoot;
51+
private Composer $composer;
4352

4453
/**
4554
* @var mixed[]
@@ -55,13 +64,18 @@ class ReplPlugin implements Capable, CommandProvider, PluginInterface
5564
*
5665
* @param mixed[] $args
5766
*/
58-
public function __construct(array $args = [], ?ProcessFactory $processFactory = null)
59-
{
67+
public function __construct(
68+
array $args = [],
69+
?Composer $composer = null,
70+
?IOInterface $io = null,
71+
?ProcessFactory $processFactory = null
72+
) {
6073
$composerFile = (string) Factory::getComposerFile();
6174

6275
$this->capabilityArgs = $args;
6376
$this->repoRoot = (string) realpath(dirname($composerFile));
6477
$this->processFactory = $processFactory ?? new ProcessFactory();
78+
$this->composer = $composer ?? Factory::create($io ?? $this->buildIO(), $composerFile);
6579
}
6680

6781
/**
@@ -95,4 +109,19 @@ public function deactivate(Composer $composer, IOInterface $io): void
95109
public function uninstall(Composer $composer, IOInterface $io): void
96110
{
97111
}
112+
113+
private function buildIO(): ConsoleIO
114+
{
115+
$input = new StringInput('');
116+
$output = new ConsoleOutput();
117+
118+
$helperSet = new HelperSet([
119+
new DescriptorHelper(),
120+
new FormatterHelper(),
121+
new ProcessHelper(),
122+
new SymfonyQuestionHelper(),
123+
]);
124+
125+
return new ConsoleIO($input, $output, $helperSet);
126+
}
98127
}

src/Psy/PhpunitRunCommand.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
namespace Ramsey\Dev\Repl\Psy;
2424

25+
use Composer\Composer;
2526
use Ramsey\Dev\Repl\Process\ProcessFactory;
2627
use Symfony\Component\Console\Input\InputArgument;
2728
use Symfony\Component\Console\Input\InputInterface;
@@ -40,13 +41,18 @@ class PhpunitRunCommand extends ContextAwareCommand
4041
{
4142
private string $repositoryRoot;
4243
private ProcessFactory $processFactory;
44+
private Composer $composer;
4345

44-
public function __construct(string $repositoryRoot, ProcessFactory $processFactory)
45-
{
46+
public function __construct(
47+
string $repositoryRoot,
48+
ProcessFactory $processFactory,
49+
Composer $composer
50+
) {
4651
parent::__construct(null);
4752

4853
$this->repositoryRoot = $repositoryRoot;
4954
$this->processFactory = $processFactory;
55+
$this->composer = $composer;
5056
}
5157

5258
protected function configure(): void
@@ -132,13 +138,8 @@ protected function configure(): void
132138

133139
protected function execute(InputInterface $input, OutputInterface $output): int
134140
{
135-
$phpunit = $this->repositoryRoot
136-
. DIRECTORY_SEPARATOR
137-
. 'vendor'
138-
. DIRECTORY_SEPARATOR
139-
. 'bin'
140-
. DIRECTORY_SEPARATOR
141-
. 'phpunit';
141+
$binDir = (string) $this->composer->getConfig()->get('bin-dir');
142+
$phpunit = $binDir . DIRECTORY_SEPARATOR . 'phpunit';
142143

143144
$process = $this->processFactory->factory(
144145
array_merge([$phpunit, '--colors=always'], $this->buildArguments($input)),

tests/Psy/PhpunitRunCommandTest.php

+24-12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Ramsey\Test\Dev\Repl\Psy;
66

7+
use Composer\Composer;
8+
use Composer\Config;
79
use Mockery\MockInterface;
810
use Psy\Context;
911
use Psy\Shell;
@@ -20,6 +22,22 @@
2022

2123
class PhpunitRunCommandTest extends RamseyTestCase
2224
{
25+
/**
26+
* @var Composer & MockInterface $composer
27+
*/
28+
private Composer $composer;
29+
30+
public function setUp(): void
31+
{
32+
/** @var Config & MockInterface $config */
33+
$config = $this->mockery(Config::class);
34+
$config->allows()->get('bin-dir')->andReturn('/path/to/vendor/bin');
35+
36+
$this->composer = $this->mockery(Composer::class, [
37+
'getConfig' => $config,
38+
]);
39+
}
40+
2341
public function testGetApplication(): void
2442
{
2543
/** @var ProcessFactory & MockInterface $processFactory */
@@ -30,7 +48,7 @@ public function testGetApplication(): void
3048
'getHelperSet' => $this->mockery(HelperSet::class),
3149
]);
3250

33-
$command = new PhpunitRunCommand('/path/to/repo', $processFactory);
51+
$command = new PhpunitRunCommand('/path/to/repo', $processFactory, $this->composer);
3452
$command->setApplication($application);
3553

3654
$this->assertSame($application, $command->getApplication());
@@ -41,7 +59,7 @@ public function testGetApplicationThrowsException(): void
4159
/** @var ProcessFactory & MockInterface $processFactory */
4260
$processFactory = $this->mockery(ProcessFactory::class);
4361

44-
$command = new PhpunitRunCommand('/path/to/repo', $processFactory);
62+
$command = new PhpunitRunCommand('/path/to/repo', $processFactory, $this->composer);
4563

4664
$this->expectException(RuntimeException::class);
4765
$this->expectExceptionMessage('Application is not set');
@@ -57,7 +75,7 @@ public function testGetContext(): void
5775
/** @var Context & MockInterface $context */
5876
$context = $this->mockery(Context::class);
5977

60-
$command = new PhpunitRunCommand('/path/to/repo', $processFactory);
78+
$command = new PhpunitRunCommand('/path/to/repo', $processFactory, $this->composer);
6179
$command->setContext($context);
6280

6381
$this->assertSame($context, $command->getContext());
@@ -68,7 +86,7 @@ public function testGetContextThrowsException(): void
6886
/** @var ProcessFactory & MockInterface $processFactory */
6987
$processFactory = $this->mockery(ProcessFactory::class);
7088

71-
$command = new PhpunitRunCommand('/path/to/repo', $processFactory);
89+
$command = new PhpunitRunCommand('/path/to/repo', $processFactory, $this->composer);
7290

7391
$this->expectException(RuntimeException::class);
7492
$this->expectExceptionMessage('Context is not set');
@@ -111,7 +129,7 @@ function (callable $callback) use ($expectedExitCode): int {
111129
->factory($expectedParams, '/path/to/repo')
112130
->andReturn($process);
113131

114-
$command = new PhpunitRunCommand('/path/to/repo', $processFactory);
132+
$command = new PhpunitRunCommand('/path/to/repo', $processFactory, $this->composer);
115133

116134
$this->assertSame($expectedExitCode, $command->run($input, $output));
117135
}
@@ -121,13 +139,7 @@ function (callable $callback) use ($expectedExitCode): int {
121139
*/
122140
public function provideCommandInput(): array
123141
{
124-
$phpunit = '/path/to/repo'
125-
. DIRECTORY_SEPARATOR
126-
. 'vendor'
127-
. DIRECTORY_SEPARATOR
128-
. 'bin'
129-
. DIRECTORY_SEPARATOR
130-
. 'phpunit';
142+
$phpunit = '/path/to/vendor/bin' . DIRECTORY_SEPARATOR . 'phpunit';
131143

132144
return [
133145
[

0 commit comments

Comments
 (0)