Skip to content

Commit 864907f

Browse files
authored
Upgrade to FidryConsole 0.5.0 (#674)
1 parent d80c5e0 commit 864907f

File tree

9 files changed

+60
-85
lines changed

9 files changed

+60
-85
lines changed

bin/php-scoper

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,4 @@ if (false === class_exists(IsolatedFinder::class)) {
5757
class_alias(Finder::class, IsolatedFinder::class);
5858
}
5959

60-
ApplicationRunner::runApplication(
61-
Application::create(),
62-
null,
63-
null,
64-
);
60+
ApplicationRunner::runApplication(Application::create());

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require": {
2323
"php": "^7.4 || ^8.0",
2424
"composer/package-versions-deprecated": "^1.8",
25-
"fidry/console": "^0.4.0",
25+
"fidry/console": "^0.5.0",
2626
"jetbrains/phpstorm-stubs": "^v2021.1",
2727
"nikic/php-parser": "^4.12",
2828
"symfony/console": "^5.2 || ^6.0",

composer.lock

Lines changed: 17 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Console/Command/ChangeableDirectory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static function createOption(): InputOption
4848

4949
public static function changeWorkingDirectory(IO $io): void
5050
{
51-
$workingDir = $io->getNullableStringOption(self::WORKING_DIR_OPT);
51+
$workingDir = $io->getOption(self::WORKING_DIR_OPT)->asNullableString();
5252

5353
if (null === $workingDir) {
5454
return;

src/Console/Command/InitCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function execute(IO $io): int
106106

107107
private function retrieveConfig(IO $io): ?string
108108
{
109-
$configFile = $io->getNullableStringOption(self::CONFIG_FILE_OPT);
109+
$configFile = $io->getOption(self::CONFIG_FILE_OPT)->asNullableNonEmptyString();
110110

111111
$configFile = (null === $configFile)
112112
? $this->makeAbsolutePath(self::CONFIG_FILE_DEFAULT)

src/Console/Command/InspectSymbolCommand.php

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ public function execute(IO $io): int
117117
// working directory
118118
$cwd = getcwd();
119119

120-
$symbol = $io->getStringArgument(self::SYMBOL_ARG);
121-
$symbolType = self::getSymbolType($io);
120+
$symbol = $io->getArgument(self::SYMBOL_ARG)->asString();
121+
/** @var SymbolType::*_TYPE $symbolType */
122+
$symbolType = $io->getArgument(self::SYMBOL_TYPE_ARG)->asStringChoice(SymbolType::ALL);
122123
$config = $this->retrieveConfig($io, $cwd);
123124

124125
$enrichedReflector = $this->enrichedReflectorFactory->create(
@@ -136,27 +137,6 @@ public function execute(IO $io): int
136137
return ExitCode::SUCCESS;
137138
}
138139

139-
/**
140-
* @return SymbolType::*_TYPE
141-
*/
142-
private static function getSymbolType(IO $io): string
143-
{
144-
// TODO: use options when available https://github.com/theofidry/console/issues/18
145-
$type = $io->getStringArgument(self::SYMBOL_TYPE_ARG);
146-
147-
if (!in_array($type, SymbolType::ALL, true)) {
148-
throw new InvalidArgumentException(
149-
sprintf(
150-
'Expected symbol type to be one of "%s". Got "%s"',
151-
implode('", "', SymbolType::ALL),
152-
$type,
153-
),
154-
);
155-
}
156-
157-
return $type;
158-
}
159-
160140
private function retrieveConfig(IO $io, string $cwd): Configuration
161141
{
162142
$configLoader = new ConfigLoader(
@@ -166,7 +146,7 @@ private function retrieveConfig(IO $io, string $cwd): Configuration
166146
);
167147

168148
$configFilePath = $this->getConfigFilePath($io, $cwd);
169-
$noConfig = $io->getBooleanOption(self::NO_CONFIG_OPT);
149+
$noConfig = $io->getOption(self::NO_CONFIG_OPT)->asBoolean();
170150

171151
if (null === $configFilePath) {
172152
// Unlike when scoping, we do not want a config file to be created

tests/Console/AppTesterAbilities.php

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Humbug\PhpScoper\Console;
66

7-
use Fidry\Console\DisplayNormalizer as FidryDisplayNormalizer;
7+
use Fidry\Console\Test\OutputAssertions;
88
use Symfony\Component\Console\Tester\ApplicationTester;
99

1010
/**
@@ -21,36 +21,20 @@ public function getAppTester(): ApplicationTester
2121
}
2222

2323
/**
24-
* @param null|callable(string):string $extraNormalization
24+
* @param callable(string):string $extraNormalizers
2525
*/
2626
private function assertExpectedOutput(
2727
string $expectedOutput,
2828
int $expectedStatusCode,
29-
?callable $extraNormalization = null
29+
callable ...$extraNormalizers
3030
): void
3131
{
32-
$appTester = $this->getAppTester();
33-
34-
$actual = $this->getNormalizeDisplay(
35-
$appTester->getDisplay(true),
36-
$extraNormalization,
32+
OutputAssertions::assertSameOutput(
33+
$expectedOutput,
34+
$expectedStatusCode,
35+
$this->getAppTester(),
36+
[DisplayNormalizer::class, 'normalize'],
37+
...$extraNormalizers,
3738
);
38-
39-
self::assertSame($expectedOutput, $actual);
40-
self::assertSame($expectedStatusCode, $appTester->getStatusCode());
41-
}
42-
43-
private function getNormalizeDisplay(
44-
string $display,
45-
?callable $extraNormalization = null
46-
): string
47-
{
48-
$extraNormalization = $extraNormalization ?? static fn (string $display) => $display;
49-
50-
$display = DisplayNormalizer::normalizeDirectorySeparators($display);
51-
$display = DisplayNormalizer::normalizeProgressBar($display);
52-
$display = FidryDisplayNormalizer::removeTrailingSpaces($display);
53-
54-
return $extraNormalization($display);
5539
}
5640
}

tests/Console/Command/AddPrefixCommandIntegrationTest.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414

1515
namespace Humbug\PhpScoper\Console\Command;
1616

17-
use Fidry\Console\Application\SymfonyApplication;
17+
use Fidry\Console\Test\AppTester;
1818
use Humbug\PhpScoper\Console\Application;
1919
use Humbug\PhpScoper\Console\AppTesterAbilities;
2020
use Humbug\PhpScoper\Console\AppTesterTestCase;
2121
use Humbug\PhpScoper\Container;
2222
use Humbug\PhpScoper\FileSystemTestCase;
23-
use Symfony\Component\Console\Tester\ApplicationTester;
2423
use Symfony\Component\Finder\Finder;
2524
use Symfony\Component\Finder\SplFileInfo;
2625
use function array_reduce;
@@ -41,9 +40,7 @@
4140
*/
4241
class AddPrefixCommandIntegrationTest extends FileSystemTestCase implements AppTesterTestCase
4342
{
44-
use AppTesterAbilities {
45-
getNormalizeDisplay as getBaseNormalizeDisplay;
46-
}
43+
use AppTesterAbilities;
4744

4845
private const FIXTURE_PATH = __DIR__.'/../../../fixtures/set002/original';
4946

@@ -59,9 +56,7 @@ protected function setUp(): void
5956
false,
6057
);
6158

62-
$this->appTester = new ApplicationTester(
63-
new SymfonyApplication($application),
64-
);
59+
$this->appTester = AppTester::fromConsoleApp($application);
6560

6661
file_put_contents('scoper.inc.php', '<?php return [];');
6762
}
@@ -164,6 +159,7 @@ public function test_scope_in_normal_mode(): void
164159
$this->assertExpectedOutput(
165160
$expected,
166161
0,
162+
$this->createDisplayNormalizer(),
167163
$extraNormalization,
168164
);
169165
}
@@ -210,7 +206,11 @@ public function test_scope_in_verbose_mode(): void
210206

211207
EOF;
212208

213-
$this->assertExpectedOutput($expected, 0);
209+
$this->assertExpectedOutput(
210+
$expected,
211+
0,
212+
$this->createDisplayNormalizer(),
213+
);
214214
}
215215

216216
public function test_scope_in_very_verbose_mode(): void
@@ -291,17 +291,24 @@ public function test_scope_in_very_verbose_mode(): void
291291
$this->assertExpectedOutput(
292292
$expected,
293293
0,
294+
$this->createDisplayNormalizer(),
294295
$extraDisplayNormalization,
295296
);
296297
}
297298

298-
private function getNormalizeDisplay(string $display, ?callable $extraNormalization = null): string
299+
/**
300+
* @return callable(string):string
301+
*/
302+
private function createDisplayNormalizer(): callable
303+
{
304+
return fn ($display) => $this->getNormalizeDisplay($display);
305+
}
306+
307+
private function getNormalizeDisplay(string $display): string
299308
{
300309
$display = str_replace(realpath(self::FIXTURE_PATH), '/path/to', $display);
301310
$display = str_replace($this->tmp, '/path/to', $display);
302311

303-
$display = $this->getBaseNormalizeDisplay($display, $extraNormalization);
304-
305312
return preg_replace(
306313
'/\/\/ Memory usage: \d+\.\d{2}MB \(peak: \d+\.\d{2}MB\), time: \d+\.\d{2}s/',
307314
'// Memory usage: 5.00MB (peak: 10.00MB), time: 0.00s',

tests/Console/DisplayNormalizer.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222

2323
final class DisplayNormalizer
2424
{
25+
public static function normalize(string $display): string
26+
{
27+
return self::normalizeDirectorySeparators(
28+
self::normalizeProgressBar($display),
29+
);
30+
}
31+
2532
public static function normalizeDirectorySeparators(string $display): string
2633
{
2734
if ('\\' === DIRECTORY_SEPARATOR && preg_match_all('/\/path\/to(.*\\\\)+/', $display, $match)) {

0 commit comments

Comments
 (0)