Skip to content

Commit

Permalink
fix(requirement-checker): Fix the constraint message displayed (#876)
Browse files Browse the repository at this point in the history
- When printing the constraint checked, the message shown should be the requirement message.
- When priting the recommendations, the message shown should be the failed requirements *help* message.

The current final output now makes no sense (it is inversed), but this is because the messages set upstream are incorrect and they will be fixed separately.
  • Loading branch information
theofidry committed Feb 12, 2023
1 parent 567715a commit c0b00d1
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ Box Requirements Checker

> Checking Box requirements:
✘ The application requires a version matching "^10".
✔ The application requires the extension "phar".
✔ The package "package-with-extensions" requires the extension "json".
✔ The application requires the extension "phar". Enable it or install a
polyfill.
✔ The package "package-with-extensions" requires the extension "json". Enable
it or install a polyfill.
✘ The package "package-with-extensions" requires the extension "ldap". Enable
it or install a polyfill.
✘ The package "package-with-extensions" requires the extension "random".
Expand All @@ -23,8 +25,6 @@ Fix the following mandatory requirements:
=========================================

* The application requires a version matching "^10".
* The package "package-with-extensions" requires the extension "ldap". Enable
it or install a polyfill.
* The package "package-with-extensions" requires the extension "random". Enable
it or install a polyfill.
* The package "package-with-extensions" requires the extension "ldap".
* The package "package-with-extensions" requires the extension "random".

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ Box Requirements Checker

> Checking Box requirements:
✘ The application requires a version matching "^10".
✔ The application requires the extension "phar".
✔ The package "package-with-extensions" requires the extension "json".
✔ The application requires the extension "phar". Enable it or install a
polyfill.
✔ The package "package-with-extensions" requires the extension "json". Enable
it or install a polyfill.
✘ The package "package-with-extensions" requires the extension "ldap". Enable
it or install a polyfill.
✘ The package "package-with-extensions" requires the extension "random".
Expand All @@ -23,8 +25,6 @@ Fix the following mandatory requirements:
=========================================

* The application requires a version matching "^10".
* The package "package-with-extensions" requires the extension "ldap". Enable
it or install a polyfill.
* The package "package-with-extensions" requires the extension "random". Enable
it or install a polyfill.
* The package "package-with-extensions" requires the extension "ldap".
* The package "package-with-extensions" requires the extension "random".

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Box Requirements Checker
WARNING: No configuration file (php.ini) used by PHP!

> Checking Box requirements:
✔ The application requires the extension "phar".
✔ The application requires the extension "phar". Enable it or install a
polyfill.
✘ The application conflicts with the extension "pdo".


Expand All @@ -17,5 +18,5 @@ Box Requirements Checker
Fix the following mandatory requirements:
=========================================

* The application conflicts with the extension "pdo".
* The application conflicts with the extension "pdo". Disable it.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Box Requirements Checker

> Checking Box requirements:
✔ The application requires a version matching ">=5.3".
✔ The application requires the extension "phar".
✔ The application requires the extension "phar". Enable it or install a
polyfill.


[OK] Your system is ready to run the application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Box Requirements Checker

> Checking Box requirements:
✔ The application requires a version matching ">=5.3".
✔ The application requires the extension "phar".
✔ The application requires the extension "phar". Enable it or install a
polyfill.


[OK] Your system is ready to run the application.
Expand Down
2 changes: 1 addition & 1 deletion requirement-checker/src/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function printCheck($checkPassed, Printer $printer, RequirementCol
}

if (IO::VERBOSITY_DEBUG === $printer->getVerbosity()) {
$printer->printvln(''.$requirement->getHelpText(), IO::VERBOSITY_DEBUG, 'green');
$printer->printvln(''.$requirement->getTestMessage(), IO::VERBOSITY_DEBUG, 'green');
$printer->printv(' ', IO::VERBOSITY_DEBUG);
} else {
$printer->printv('.', $verbosity, 'green');
Expand Down
2 changes: 1 addition & 1 deletion requirement-checker/src/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getRequirementErrorMessage(Requirement $requirement): ?string
return null;
}

return wordwrap($requirement->getTestMessage(), $this->width - 3, PHP_EOL.' ').PHP_EOL;
return wordwrap($requirement->getHelpText(), $this->width - 3, PHP_EOL.' ').PHP_EOL;
}

public function block(string $title, string $message, int $verbosity, ?string $style = null): void
Expand Down
44 changes: 22 additions & 22 deletions requirement-checker/tests/CheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public function test_it_can_check_requirements(
public function provideRequirements(): Generator
{
$phpVersion = PHP_VERSION;
$remainingVerbosities = ['verbosity=verbose' => IO::VERBOSITY_VERBOSE, 'verbosity=normal' => IO::VERBOSITY_NORMAL, 'verbosity=quiet' => IO::VERBOSITY_QUIET];

yield (static function () use ($phpVersion) {
yield 'no requirement; verbosity=debug' => (static function () use ($phpVersion) {
return [
new RequirementCollection(),
IO::VERBOSITY_DEBUG,
Expand All @@ -89,7 +90,7 @@ public function provideRequirements(): Generator
];
})();

yield (static function () use ($phpVersion) {
yield 'no requirement; verbosity=very verbose' => (static function () use ($phpVersion) {
return [
new RequirementCollection(),
IO::VERBOSITY_VERY_VERBOSE,
Expand All @@ -114,8 +115,8 @@ public function provideRequirements(): Generator
];
})();

foreach ([IO::VERBOSITY_VERBOSE, IO::VERBOSITY_NORMAL, IO::VERBOSITY_QUIET] as $verbosity) {
yield (static function () use ($verbosity) {
foreach ($remainingVerbosities as $label => $verbosity) {
yield 'no requirements; '.$label => (static function () use ($verbosity) {
return [
new RequirementCollection(),
$verbosity,
Expand All @@ -125,13 +126,13 @@ public function provideRequirements(): Generator
})();
}

yield (static function () use ($phpVersion) {
yield 'requirements; check passes; verbosity=debug' => (static function () use ($phpVersion) {
$requirements = new RequirementCollection();

$requirements->addRequirement(
new ConditionIsFulfilled(),
'The application requires the version "7.2.0" or greater.',
'The application requires the version "7.2.0" or greater. Got "7.2.2"',
'The application requires the version "7.2.0" or greater.'
);
$requirements->addRequirement(
new class() implements IsFulfilled {
Expand All @@ -140,8 +141,8 @@ public function __invoke(): bool
return true;
}
},
'The package "acme/foo" requires the extension "random".',
'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.',
'The package "acme/foo" requires the extension "random".'
);

return [
Expand Down Expand Up @@ -170,7 +171,7 @@ public function __invoke(): bool
];
})();

yield (static function () use ($phpVersion) {
yield 'requirements; check passes; verbosity=very verbose' => (static function () use ($phpVersion) {
$requirements = new RequirementCollection();

$requirements->addRequirement(
Expand All @@ -180,8 +181,8 @@ public function __invoke(): bool
);
$requirements->addRequirement(
new ConditionIsFulfilled(),
'The package "acme/foo" requires the extension "random".',
'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.',
'The package "acme/foo" requires the extension "random".'
);

return [
Expand Down Expand Up @@ -209,8 +210,8 @@ public function __invoke(): bool
];
})();

foreach ([IO::VERBOSITY_VERBOSE, IO::VERBOSITY_NORMAL, IO::VERBOSITY_QUIET] as $verbosity) {
yield (static function () use ($verbosity) {
foreach ($remainingVerbosities as $label => $verbosity) {
yield 'requirements; check passes; '.$label => (static function () use ($verbosity) {
$requirements = new RequirementCollection();

$requirements->addRequirement(
Expand All @@ -220,8 +221,8 @@ public function __invoke(): bool
);
$requirements->addRequirement(
new ConditionIsFulfilled(),
'The package "acme/foo" requires the extension "random".',
'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.',
'The package "acme/foo" requires the extension "random".'
);

return [
Expand All @@ -233,7 +234,7 @@ public function __invoke(): bool
})();
}

yield (static function () use ($phpVersion) {
yield 'requirements; check do not pass; verbosity=debug' => (static function () use ($phpVersion) {
$requirements = new RequirementCollection();

$requirements->addRequirement(
Expand All @@ -243,8 +244,8 @@ public function __invoke(): bool
);
$requirements->addRequirement(
new ConditionIsNotFulfilled(),
'The package "acme/foo" requires the extension "random".',
'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.',
'The package "acme/foo" requires the extension "random".'
);

return [
Expand All @@ -261,9 +262,8 @@ public function __invoke(): bool
/path/to/php.ini
> Checking Box requirements:
✔ The application requires the version "7.2.0" or greater.
✘ The package "acme/foo" requires the extension "random". Enable it or install
a polyfill.
✔ The application requires the version "7.2.0" or greater. Got "7.2.2"
✘ The package "acme/foo" requires the extension "random".
[ERROR] Your system is not ready to run the application.
Expand All @@ -280,8 +280,8 @@ public function __invoke(): bool
];
})();

foreach ([IO::VERBOSITY_VERY_VERBOSE, IO::VERBOSITY_VERBOSE, IO::VERBOSITY_NORMAL] as $verbosity) {
yield (static function () use ($verbosity, $phpVersion) {
foreach (['verbosity=very verbose' => IO::VERBOSITY_VERY_VERBOSE, 'verbosity=verbose' => IO::VERBOSITY_VERBOSE, 'verbosity=normal' => IO::VERBOSITY_NORMAL] as $label => $verbosity) {
yield 'requirements; check do not pass; '.$label => (static function () use ($verbosity, $phpVersion) {
$requirements = new RequirementCollection();

$requirements->addRequirement(
Expand All @@ -291,8 +291,8 @@ public function __invoke(): bool
);
$requirements->addRequirement(
new ConditionIsNotFulfilled(),
'The package "acme/foo" requires the extension "random".',
'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.',
'The package "acme/foo" requires the extension "random".'
);

return [
Expand Down Expand Up @@ -327,7 +327,7 @@ public function __invoke(): bool
})();
}

yield (static function () use ($phpVersion) {
yield 'requirements; check do not pass; verbosity=quiet' => (static function () use ($phpVersion) {
$requirements = new RequirementCollection();

$requirements->addRequirement(
Expand All @@ -337,8 +337,8 @@ public function __invoke(): bool
);
$requirements->addRequirement(
new ConditionIsNotFulfilled(),
'The package "acme/foo" requires the extension "random".',
'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.',
'The package "acme/foo" requires the extension "random".'
);

return [
Expand Down
4 changes: 2 additions & 2 deletions requirement-checker/tests/PrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function provideErrorRequirements(): Generator
false,
50,
<<<'EOF'
Test message
Help message

EOF
];
Expand All @@ -210,7 +210,7 @@ public function provideErrorRequirements(): Generator
true,
50,
<<<'EOF'
Test message
Help message

EOF
];
Expand Down
2 changes: 1 addition & 1 deletion res/requirement-checker/src/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function printCheck($checkPassed, Printer $printer, RequirementCol
continue;
}
if (IO::VERBOSITY_DEBUG === $printer->getVerbosity()) {
$printer->printvln('' . $requirement->getHelpText(), IO::VERBOSITY_DEBUG, 'green');
$printer->printvln('' . $requirement->getTestMessage(), IO::VERBOSITY_DEBUG, 'green');
$printer->printv(' ', IO::VERBOSITY_DEBUG);
} else {
$printer->printv('.', $verbosity, 'green');
Expand Down
2 changes: 1 addition & 1 deletion res/requirement-checker/src/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getRequirementErrorMessage(Requirement $requirement) : ?string
if ($requirement->isFulfilled()) {
return null;
}
return wordwrap($requirement->getTestMessage(), $this->width - 3, PHP_EOL . ' ') . PHP_EOL;
return wordwrap($requirement->getHelpText(), $this->width - 3, PHP_EOL . ' ') . PHP_EOL;
}
public function block(string $title, string $message, int $verbosity, ?string $style = null) : void
{
Expand Down

0 comments on commit c0b00d1

Please sign in to comment.