Skip to content

Commit 22d3e28

Browse files
authored
Merge pull request #163 from Bellangelo/add-question-option-helper-set
Allow composer to ask for credentials
2 parents 900e6b1 + 2cf8af2 commit 22d3e28

File tree

6 files changed

+61
-12
lines changed

6 files changed

+61
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Php\Pie\ComposerIntegration;
6+
7+
use Symfony\Component\Console\Helper\HelperSet;
8+
use Symfony\Component\Console\Helper\QuestionHelper;
9+
use Webmozart\Assert\Assert;
10+
11+
/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
12+
class MinimalHelperSet extends HelperSet
13+
{
14+
/** @param array{question: QuestionHelper} $helpers */
15+
public function __construct(array $helpers)
16+
{
17+
Assert::isInstanceOf(
18+
$helpers['question'] ?? null,
19+
QuestionHelper::class,
20+
'The question option must be an instance of %2$s, got %s',
21+
);
22+
23+
parent::__construct($helpers);
24+
}
25+
}

src/ComposerIntegration/QuieterConsoleIO.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Closure;
88
use Composer\IO\ConsoleIO;
99
use Composer\IO\IOInterface;
10-
use Symfony\Component\Console\Helper\HelperSet;
1110
use Symfony\Component\Console\Input\InputInterface;
1211
use Symfony\Component\Console\Output\OutputInterface;
1312

@@ -21,7 +20,7 @@ class QuieterConsoleIO extends ConsoleIO
2120
/** @var string[] */
2221
public array $errors = [];
2322

24-
public function __construct(InputInterface $input, OutputInterface $output, HelperSet $helperSet)
23+
public function __construct(InputInterface $input, OutputInterface $output, MinimalHelperSet $helperSet)
2524
{
2625
parent::__construct($input, $output, $helperSet);
2726

src/Container.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Php\Pie\Command\InfoCommand;
1515
use Php\Pie\Command\InstallCommand;
1616
use Php\Pie\Command\ShowCommand;
17+
use Php\Pie\ComposerIntegration\MinimalHelperSet;
1718
use Php\Pie\ComposerIntegration\QuieterConsoleIO;
1819
use Php\Pie\DependencyResolver\DependencyResolver;
1920
use Php\Pie\DependencyResolver\ResolveDependencyWithComposer;
@@ -24,7 +25,7 @@
2425
use Php\Pie\Installing\UnixInstall;
2526
use Php\Pie\Installing\WindowsInstall;
2627
use Psr\Container\ContainerInterface;
27-
use Symfony\Component\Console\Helper\HelperSet;
28+
use Symfony\Component\Console\Helper\QuestionHelper;
2829
use Symfony\Component\Console\Input\ArgvInput;
2930
use Symfony\Component\Console\Input\InputInterface;
3031
use Symfony\Component\Console\Output\ConsoleOutput;
@@ -50,7 +51,11 @@ public static function factory(): ContainerInterface
5051
return new QuieterConsoleIO(
5152
$container->get(InputInterface::class),
5253
$container->get(OutputInterface::class),
53-
new HelperSet(),
54+
new MinimalHelperSet(
55+
[
56+
'question' => new QuestionHelper(),
57+
],
58+
),
5459
);
5560
});
5661

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Php\PieUnitTest\ComposerIntegration;
6+
7+
use Php\Pie\ComposerIntegration\MinimalHelperSet;
8+
use PHPUnit\Framework\Attributes\CoversClass;
9+
use PHPUnit\Framework\TestCase;
10+
use Symfony\Component\Console\Helper\QuestionHelper;
11+
12+
#[CoversClass(MinimalHelperSet::class)]
13+
class MinimalHelperSetTest extends TestCase
14+
{
15+
public function testHappyPath(): void
16+
{
17+
$this->expectNotToPerformAssertions();
18+
new MinimalHelperSet(['question' => $this->createMock(QuestionHelper::class)]);
19+
}
20+
}

test/unit/ComposerIntegration/QuieterConsoleIOTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
namespace Php\PieUnitTest\ComposerIntegration;
66

77
use Composer\IO\IOInterface;
8+
use Php\Pie\ComposerIntegration\MinimalHelperSet;
89
use Php\Pie\ComposerIntegration\QuieterConsoleIO;
910
use PHPUnit\Framework\Attributes\CoversClass;
1011
use PHPUnit\Framework\Attributes\DataProvider;
1112
use PHPUnit\Framework\TestCase;
12-
use Symfony\Component\Console\Helper\HelperSet;
1313
use Symfony\Component\Console\Input\InputInterface;
1414
use Symfony\Component\Console\Output\Output;
1515
use Symfony\Component\Console\Output\OutputInterface;
@@ -29,7 +29,7 @@ public function testErrorsAreLoggedAndWrittenWhenVerbose(): void
2929
->method('write')
3030
->with('Oh no');
3131

32-
$io = new QuieterConsoleIO($symfonyInput, $symfonyOutput, new HelperSet([]));
32+
$io = new QuieterConsoleIO($symfonyInput, $symfonyOutput, $this->createMock(MinimalHelperSet::class));
3333
$io->writeError('Oh no');
3434

3535
self::assertSame(['Oh no'], $io->errors);
@@ -47,7 +47,7 @@ public function testArrayOfErrorsAreLoggedAndWrittenWhenVerbose(): void
4747
->method('write')
4848
->with(['Oh no', 'Bad things']);
4949

50-
$io = new QuieterConsoleIO($symfonyInput, $symfonyOutput, new HelperSet([]));
50+
$io = new QuieterConsoleIO($symfonyInput, $symfonyOutput, $this->createMock(MinimalHelperSet::class));
5151
$io->writeError(['Oh no', 'Bad things']);
5252

5353
self::assertSame(['Oh no', 'Bad things'], $io->errors);
@@ -64,7 +64,7 @@ public function testErrorsAreLoggedButNotWritten(): void
6464
->expects(self::never())
6565
->method('write');
6666

67-
$io = new QuieterConsoleIO($symfonyInput, $symfonyOutput, new HelperSet([]));
67+
$io = new QuieterConsoleIO($symfonyInput, $symfonyOutput, $this->createMock(MinimalHelperSet::class));
6868
$io->writeError('Oh no');
6969

7070
self::assertSame(['Oh no'], $io->errors);
@@ -105,7 +105,7 @@ protected function doWrite(string $message, bool $newline): void
105105
};
106106
$symfonyOutput->setVerbosity($symfonyVerbosity);
107107

108-
$io = new QuieterConsoleIO($symfonyInput, $symfonyOutput, new HelperSet([]));
108+
$io = new QuieterConsoleIO($symfonyInput, $symfonyOutput, $this->createMock(MinimalHelperSet::class));
109109

110110
$io->write('Quiet', verbosity: IOInterface::QUIET);
111111
$io->write('Normal', verbosity: IOInterface::NORMAL);

test/unit/DependencyResolver/UnableToResolveRequirementTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
namespace Php\PieUnitTest\DependencyResolver;
66

77
use Composer\Package\PackageInterface;
8+
use Php\Pie\ComposerIntegration\MinimalHelperSet;
89
use Php\Pie\ComposerIntegration\QuieterConsoleIO;
910
use Php\Pie\DependencyResolver\RequestedPackageAndVersion;
1011
use Php\Pie\DependencyResolver\UnableToResolveRequirement;
1112
use PHPUnit\Framework\Attributes\CoversClass;
1213
use PHPUnit\Framework\TestCase;
13-
use Symfony\Component\Console\Helper\HelperSet;
1414
use Symfony\Component\Console\Input\InputInterface;
1515
use Symfony\Component\Console\Output\OutputInterface;
1616

@@ -42,7 +42,7 @@ public function testFromRequirementWithVersion(): void
4242
$io = new QuieterConsoleIO(
4343
$this->createMock(InputInterface::class),
4444
$this->createMock(OutputInterface::class),
45-
$this->createMock(HelperSet::class),
45+
$this->createMock(MinimalHelperSet::class),
4646
);
4747
$io->writeError('message1');
4848
$io->writeError('message2', true, QuieterConsoleIO::VERY_VERBOSE);
@@ -58,7 +58,7 @@ public function testFromRequirementWithoutVersion(): void
5858
$io = new QuieterConsoleIO(
5959
$this->createMock(InputInterface::class),
6060
$this->createMock(OutputInterface::class),
61-
$this->createMock(HelperSet::class),
61+
$this->createMock(MinimalHelperSet::class),
6262
);
6363
$io->writeError('message1');
6464
$io->writeError('message2', true, QuieterConsoleIO::VERY_VERBOSE);

0 commit comments

Comments
 (0)