Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public function startBuffering(): void
}

/**
* TODO: replace callable by Closure.
* @param callable(SymbolsRegistry, string, string[]): void $dumpAutoload
*/
public function endBuffering(?callable $dumpAutoload): void
Expand Down
5 changes: 3 additions & 2 deletions src/Test/CommandTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace KevinGH\Box\Test;

use Closure;
use Fidry\Console\Bridge\Command\SymfonyCommand;
use Fidry\Console\Command\Command;
use Fidry\Console\Test\CommandTester;
Expand Down Expand Up @@ -61,12 +62,12 @@ protected function tearDown(): void
abstract protected function getCommand(): Command;

/**
* @param callable(string):string $extraNormalizers
* @param Closure(string):string $extraNormalizers
*/
public function assertSameOutput(
string $expectedOutput,
int $expectedStatusCode,
callable ...$extraNormalizers,
Closure ...$extraNormalizers,
): void {
OutputAssertions::assertSameOutput(
$expectedOutput,
Expand Down
7 changes: 4 additions & 3 deletions tests/Configuration/ConfigurationFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace KevinGH\Box\Configuration;

use Closure;
use Fidry\FileSystem\FS;
use InvalidArgumentException;
use KevinGH\Box\Json\JsonValidationException;
Expand Down Expand Up @@ -139,7 +140,7 @@ public function test_the_files_can_be_configured(): void
}

#[DataProvider('configWithMainScriptProvider')]
public function test_the_main_script_file_is_always_ignored(callable $setUp, array $config, array $expectedFiles, array $expectedBinFiles): void
public function test_the_main_script_file_is_always_ignored(Closure $setUp, array $config, array $expectedFiles, array $expectedBinFiles): void
{
$setUp();

Expand All @@ -153,7 +154,7 @@ public function test_the_main_script_file_is_always_ignored(callable $setUp, arr
}

#[DataProvider('configWithGeneratedArtefactProvider')]
public function test_the_generated_artefact_is_always_ignored(callable $setUp, array $config, array $expectedFiles, array $expectedBinFiles): void
public function test_the_generated_artefact_is_always_ignored(Closure $setUp, array $config, array $expectedFiles, array $expectedBinFiles): void
{
$setUp();

Expand Down Expand Up @@ -1552,7 +1553,7 @@ public function test_files_are_autodiscovered_by_default(): void

#[DataProvider('filesAutodiscoveryConfigProvider')]
public function test_files_are_autodiscovered_unless_directory_or_finder_config_is_provided(
callable $setUp,
Closure $setUp,
array $config,
bool $expectedFilesAutodiscovery,
): void {
Expand Down
3 changes: 2 additions & 1 deletion tests/Configuration/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace KevinGH\Box\Configuration;

use Closure;
use DateTimeImmutable;
use DateTimeInterface;
use Fidry\FileSystem\FS;
Expand Down Expand Up @@ -316,7 +317,7 @@ public function test_the_base_path_value_is_normalized(): void

#[DataProvider('composerArtifactsProvider')]
public function test_it_attempts_to_get_and_decode_the_json_and_lock_files(
callable $setup,
Closure $setup,
?string $expectedJsonPath,
?array $expectedJsonContents,
?string $expectedLockPath,
Expand Down
4 changes: 2 additions & 2 deletions tests/Console/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function test_it_can_display_the_version_when_no_specific_version_is_give
$expected,
ExitCode::SUCCESS,
$appTester,
DisplayNormalizer::createReplaceBoxVersionNormalizer(),
DisplayNormalizer::normalizeBoxVersion(...),
);
}

Expand Down Expand Up @@ -154,7 +154,7 @@ public function test_get_helper_menu(): void
$expected,
ExitCode::SUCCESS,
$appTester,
DisplayNormalizer::createReplaceBoxVersionNormalizer(),
DisplayNormalizer::normalizeBoxVersion(...),
);
}

Expand Down
113 changes: 55 additions & 58 deletions tests/Console/Command/CompileCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace KevinGH\Box\Console\Command;

use Closure;
use DirectoryIterator;
use Fidry\Console\Bridge\Command\SymfonyCommand;
use Fidry\Console\Command\Command;
Expand Down Expand Up @@ -913,7 +914,7 @@ public function test_it_can_build_a_phar_file_in_verbose_mode(): void
$this->assertSameOutput(
$expected,
ExitCode::SUCCESS,
self::createComposerPathNormalizer(),
self::normalizeComposerPath(...),
);
}

Expand Down Expand Up @@ -1050,7 +1051,7 @@ public function test_it_can_build_a_phar_file_in_very_verbose_mode(): void
$this->assertSameOutput(
$expected,
ExitCode::SUCCESS,
self::createComposerPathNormalizer(),
self::normalizeComposerPath(...),
);
}

Expand Down Expand Up @@ -2997,79 +2998,75 @@ public static function aliasConfigProvider(): iterable
yield [false];
}

private function createCompilerDisplayNormalizer(): callable
private function normalizeCompilerDisplay(string $output): string
{
$tmp = $this->tmp;
$output = str_replace($this->tmp, '/path/to/tmp', $output);

return static function (string $output) use ($tmp): string {
$output = str_replace($tmp, '/path/to/tmp', $output);
$output = preg_replace(
'/Loading the configuration file[\s\n]+.*[\s\n\/]+.*box\.json[comment\<\>\n\s\/]*"\./',
'Loading the configuration file "/path/to/box.json.dist".',
$output,
);

$output = preg_replace(
'/Loading the configuration file[\s\n]+.*[\s\n\/]+.*box\.json[comment\<\>\n\s\/]*"\./',
'Loading the configuration file "/path/to/box.json.dist".',
$output,
);
$output = preg_replace(
'/You can inspect the generated PHAR( | *\n *\/\/ *)with( | *\n *\/\/ *)the( | *\n *\/\/ *)"info"( | *\n *\/\/ *)command/',
'You can inspect the generated PHAR with the "info" command',
$output,
);

$output = preg_replace(
'/You can inspect the generated PHAR( | *\n *\/\/ *)with( | *\n *\/\/ *)the( | *\n *\/\/ *)"info"( | *\n *\/\/ *)command/',
'You can inspect the generated PHAR with the "info" command',
$output,
);
$output = preg_replace(
'/\/\/ PHAR: (\d+ files?) \(\d+\.\d{2}K?B\)/',
'// PHAR: $1 (100B)',
$output,
);

$output = preg_replace(
'/\/\/ PHAR: (\d+ files?) \(\d+\.\d{2}K?B\)/',
'// PHAR: $1 (100B)',
$output,
);
$output = preg_replace(
'/\/\/ Memory usage: \d+\.\d{2}MB \(peak: \d+\.\d{2}MB\), time: .*(sec|s|ms)/',
'// Memory usage: 5.00MB (peak: 10.00MB), time: 0.00s',
$output,
);

$output = preg_replace(
'/\/\/ Memory usage: \d+\.\d{2}MB \(peak: \d+\.\d{2}MB\), time: .*(sec|s|ms)/',
'// Memory usage: 5.00MB (peak: 10.00MB), time: 0.00s',
$output,
);
$output = str_replace(
'Xdebug',
'xdebug',
$output,
);

$output = str_replace(
'Xdebug',
'xdebug',
$output,
);
$output = preg_replace(
'/\[debug\] Increased the maximum number of open file descriptors from \([^\)]+\) to \([^\)]+\)'.PHP_EOL.'/',
'',
$output,
);

$output = preg_replace(
'/\[debug\] Increased the maximum number of open file descriptors from \([^\)]+\) to \([^\)]+\)'.PHP_EOL.'/',
'',
$output,
);
$output = str_replace(
'[debug] Restored the maximum number of open file descriptors'.PHP_EOL,
'',
$output,
);

$output = str_replace(
'[debug] Restored the maximum number of open file descriptors'.PHP_EOL,
if (extension_loaded('xdebug')) {
$output = preg_replace(
'/'.PHP_EOL.'You are running composer with xdebug enabled. This has a major impact on runtime performance. See https:\/[^\s]+'.PHP_EOL.'/',
'',
$output,
);
}

if (extension_loaded('xdebug')) {
$output = preg_replace(
'/'.PHP_EOL.'You are running composer with xdebug enabled. This has a major impact on runtime performance. See https:\/[^\s]+'.PHP_EOL.'/',
'',
$output,
);
}

return $output;
};
return $output;
}

private static function createComposerPathNormalizer(): callable
private static function normalizeComposerPath(string $output): string
{
return static fn (string $output): string => preg_replace(
return preg_replace(
'/(\/.*?composer(?:\.phar)?)/',
'/usr/local/bin/composer',
$output,
);
}

private static function createComposerVersionNormalizer(): callable
private static function normalizeComposerVersion(string $output): string
{
return static fn (string $output): string => preg_replace(
return preg_replace(
'/> Version detected: ([\d.]+) \(Box requires \^2\.2\.0\)/',
'> Version detected: 2.2.22 (Box requires ^2.2.0)',
$output,
Expand Down Expand Up @@ -3120,21 +3117,21 @@ private static function normalizeStub(string $pharStub): string
}

/**
* @param callable(string):string $extraNormalizers
* @param Closure(string):string $extraNormalizers
*/
private function assertSameOutput(
string $expectedOutput,
int $expectedStatusCode,
callable ...$extraNormalizers,
Closure ...$extraNormalizers,
): void {
OutputAssertions::assertSameOutput(
$expectedOutput,
$expectedStatusCode,
$this->commandTester,
BoxDisplayNormalizer::createReplaceBoxVersionNormalizer(),
$this->createCompilerDisplayNormalizer(),
self::createComposerPathNormalizer(),
self::createComposerVersionNormalizer(),
BoxDisplayNormalizer::normalizeBoxVersion(...),
$this->normalizeCompilerDisplay(...),
self::normalizeComposerPath(...),
self::normalizeComposerVersion(...),
...$extraNormalizers,
);
}
Expand Down
7 changes: 4 additions & 3 deletions tests/Console/Command/ProcessCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace KevinGH\Box\Console\Command;

use Closure;
use Fidry\Console\Command\Command;
use Fidry\Console\ExitCode;
use Fidry\FileSystem\FS;
Expand Down Expand Up @@ -263,13 +264,13 @@ public function test_it_processes_a_file_and_displays_only_the_processed_content
public function assertSameOutput(
string $expectedOutput,
int $expectedStatusCode,
callable ...$extraNormalizers,
Closure ...$extraNormalizers,
): void {
parent::assertSameOutput(
$expectedOutput,
$expectedStatusCode,
DisplayNormalizer::createVarDumperObjectReferenceNormalizer(),
DisplayNormalizer::createLoadingFilePathOutputNormalizer(),
DisplayNormalizer::normalizeVarDumperObjectReference(...),
DisplayNormalizer::normalizeLoadingFilePathOutput(...),
...$extraNormalizers,
);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Console/Command/ValidateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public function test_an_invalid_json_file_is_invalid(): void
$this->assertSameOutput(
$expected,
ExitCode::FAILURE,
DisplayNormalizer::createLoadingFilePathOutputNormalizer(),
DisplayNormalizer::normalizeLoadingFilePathOutput(...),
);
}

Expand Down Expand Up @@ -384,7 +384,7 @@ public function test_an_incorrect_config_file_is_invalid(): void
$this->assertSameOutput(
$expected,
ExitCode::FAILURE,
DisplayNormalizer::createLoadingFilePathOutputNormalizer(),
DisplayNormalizer::normalizeLoadingFilePathOutput(...),
);
}

Expand Down
21 changes: 6 additions & 15 deletions tests/Console/DisplayNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,27 @@ public static function removeTrailingSpaces(string $display): string
return implode("\n", $lines);
}

/**
* @return callable(string):string
*/
public static function createLoadingFilePathOutputNormalizer(): callable
public static function normalizeLoadingFilePathOutput(string $output): string
{
return static fn ($output) => preg_replace(
return preg_replace(
'/\s\/\/ Loading the configuration file([\s\S]*)box\.json[comment\<\>\n\s\/]*"\./',
' // Loading the configuration file "box.json".',
$output,
);
}

/**
* @return callable(string):string
*/
public static function createVarDumperObjectReferenceNormalizer(): callable
public static function normalizeVarDumperObjectReference(string $output): string
{
return static fn ($output) => preg_replace(
return preg_replace(
'/ \{#\d+/',
' {#140',
$output,
);
}

/**
* @return callable(string):string
*/
public static function createReplaceBoxVersionNormalizer(): callable
public static function normalizeBoxVersion(string $output): string
{
return static fn (string $output): string => preg_replace(
return preg_replace(
'/Box version .+@[a-z\d]{7}/',
'Box version x.x-dev@151e40a',
$output,
Expand Down
2 changes: 1 addition & 1 deletion tests/Console/DisplayNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static function test_it_can_normalize_an_object_reference_from_the_var_du
): void {
$expected ??= $value;

$actual = DisplayNormalizer::createVarDumperObjectReferenceNormalizer()($value);
$actual = DisplayNormalizer::normalizeVarDumperObjectReference($value);

self::assertSame($expected, $actual);
}
Expand Down
Loading