Skip to content

Commit

Permalink
Add helper for the enum CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
cerbero90 committed Jan 9, 2025
1 parent e563797 commit c2abbd2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions helpers/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,19 @@ function runAnnotate(string $enum, bool $force = false): bool
// Since we are writing on the disk, the enum in memory might get out of sync.
// To ensure that the annotations reflect the current content of such enum,
// we spin a new process to load in memory the latest state of the enum.
$command = path(__DIR__ . '/../bin/enum') . " annotate \"{$enum}\"" . ($force ? ' --force' : '');

ob_start();

$succeeded = passthru('"' . PHP_BINARY . '" ' . $command . ' 2>&1') === null;
$succeeded = cli("annotate \"{$enum}\"" . ($force ? ' --force' : ''));

ob_end_clean();

return $succeeded;
}

/**
* Run the enum CLI in a new process.
*/
function cli(string $command, ?int &$status = null): bool
{
return passthru('"' . PHP_BINARY . '" ' . path(__DIR__ . '/../bin/enum') . " {$command} 2>&1", $status) === null;
}
4 changes: 2 additions & 2 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
|
*/

use function Cerbero\Enum\path;
use function Cerbero\Enum\cli;

expect()->extend('toAnnotate', function (array $enums, bool $overwrite = false) {
$oldContents = [];
Expand Down Expand Up @@ -84,7 +84,7 @@ function runEnum(string $command): stdClass
{
ob_start();

passthru('"' . PHP_BINARY . '" ' . path(__DIR__ . '/../bin/enum') . " {$command} 2>&1", $status);
cli($command, $status);

$output = ob_get_clean();

Expand Down

0 comments on commit c2abbd2

Please sign in to comment.