From 9e58d4179d72c8a4a486f138611a124f61282677 Mon Sep 17 00:00:00 2001 From: Brent Roose Date: Wed, 20 Nov 2024 10:04:54 +0100 Subject: [PATCH] Infer binary path --- .../src/Initializers/SchedulerInitializer.php | 2 ++ .../src/Scheduler/GenericScheduler.php | 8 ++++++-- .../Console/src/Scheduler/SchedulerConfig.php | 2 -- .../Scheduler/GenericSchedulerTest.php | 20 +++++++++++-------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/Tempest/Console/src/Initializers/SchedulerInitializer.php b/src/Tempest/Console/src/Initializers/SchedulerInitializer.php index bac343669..5696a6a9e 100644 --- a/src/Tempest/Console/src/Initializers/SchedulerInitializer.php +++ b/src/Tempest/Console/src/Initializers/SchedulerInitializer.php @@ -5,6 +5,7 @@ namespace Tempest\Console\Initializers; use Tempest\Console\ConsoleApplication; +use Tempest\Console\Input\ConsoleArgumentBag; use Tempest\Console\Scheduler; use Tempest\Console\Scheduler\GenericScheduler; use Tempest\Console\Scheduler\NullScheduler; @@ -28,6 +29,7 @@ public function initialize(Container $container): Scheduler return new GenericScheduler( $container->get(SchedulerConfig::class), + $container->get(ConsoleArgumentBag::class), $container->get(ShellExecutor::class), ); } diff --git a/src/Tempest/Console/src/Scheduler/GenericScheduler.php b/src/Tempest/Console/src/Scheduler/GenericScheduler.php index 4a3a3aa6e..2c68f267c 100644 --- a/src/Tempest/Console/src/Scheduler/GenericScheduler.php +++ b/src/Tempest/Console/src/Scheduler/GenericScheduler.php @@ -5,6 +5,7 @@ namespace Tempest\Console\Scheduler; use DateTime; +use Tempest\Console\Input\ConsoleArgumentBag; use Tempest\Console\Scheduler; use Tempest\Console\ShellExecutor; use function Tempest\event; @@ -15,6 +16,7 @@ public function __construct( private SchedulerConfig $config, + private ConsoleArgumentBag $argumentBag, private ShellExecutor $executor ) { } @@ -41,8 +43,10 @@ private function execute(ScheduledInvocation $invocation): void private function compileInvocation(ScheduledInvocation $invocation): string { - return join(' ', [ - '(' . $this->config->path, + $binary = $this->argumentBag->getBinaryPath() . ' ' . $this->argumentBag->getCliName(); + + return implode(' ', [ + '(' . $binary, $invocation->getCommandName() . ')', $invocation->schedule->outputMode->value, $invocation->schedule->output, diff --git a/src/Tempest/Console/src/Scheduler/SchedulerConfig.php b/src/Tempest/Console/src/Scheduler/SchedulerConfig.php index e3ed271d3..c46519a79 100644 --- a/src/Tempest/Console/src/Scheduler/SchedulerConfig.php +++ b/src/Tempest/Console/src/Scheduler/SchedulerConfig.php @@ -11,8 +11,6 @@ final class SchedulerConfig { public function __construct( - public string $path = "php tempest", - /** @var ScheduledInvocation[] $scheduledInvocations */ public array $scheduledInvocations = [], ) { diff --git a/tests/Integration/Console/Scheduler/GenericSchedulerTest.php b/tests/Integration/Console/Scheduler/GenericSchedulerTest.php index 572df5ea1..78038b134 100644 --- a/tests/Integration/Console/Scheduler/GenericSchedulerTest.php +++ b/tests/Integration/Console/Scheduler/GenericSchedulerTest.php @@ -7,6 +7,7 @@ use DateTime; use ReflectionMethod; use Tempest\Console\ConsoleCommand; +use Tempest\Console\Input\ConsoleArgumentBag; use Tempest\Console\Schedule; use Tempest\Console\Scheduler\Every; use Tempest\Console\Scheduler\GenericScheduler; @@ -40,12 +41,13 @@ public function test_scheduler_executes_handlers(): void ); $executor = new NullShellExecutor(); - $scheduler = new GenericScheduler($config, $executor); + $argumentBag = new ConsoleArgumentBag(['tempest']); + $scheduler = new GenericScheduler($config, $argumentBag, $executor); $scheduler->run(); $this->assertSame( - '(php tempest schedule:task Tests\\\Tempest\\\Integration\\\Console\\\Scheduler\\\GenericSchedulerTest::handler) >> /dev/null &', + '(' . PHP_BINARY . ' tempest schedule:task Tests\\\Tempest\\\Integration\\\Console\\\Scheduler\\\GenericSchedulerTest::handler) >> /dev/null &', $executor->executedCommand, ); } @@ -61,11 +63,12 @@ public function test_scheduler_executes_commands(): void ); $executor = new NullShellExecutor(); - $scheduler = new GenericScheduler($config, $executor); + $argumentBag = new ConsoleArgumentBag(['tempest']); + $scheduler = new GenericScheduler($config, $argumentBag, $executor); $scheduler->run(); $this->assertSame( - '(php tempest command) >> /dev/null &', + '(' . PHP_BINARY . ' tempest command) >> /dev/null &', $executor->executedCommand, ); } @@ -81,11 +84,12 @@ public function test_scheduler_only_dispatches_the_command_in_desired_times(): v ); $executor = new NullShellExecutor(); - $scheduler = new GenericScheduler($config, $executor); + $argumentBag = new ConsoleArgumentBag(['tempest']); + $scheduler = new GenericScheduler($config, $argumentBag, $executor); $scheduler->run($at); $this->assertSame( - '(php tempest schedule:task Tests\\\Tempest\\\Integration\\\Console\\\Scheduler\\\GenericSchedulerTest::handler) >> /dev/null &', + '(' . PHP_BINARY . ' tempest schedule:task Tests\\\Tempest\\\Integration\\\Console\\\Scheduler\\\GenericSchedulerTest::handler) >> /dev/null &', $executor->executedCommand, ); @@ -97,12 +101,12 @@ public function test_scheduler_only_dispatches_the_command_in_desired_times(): v $executor = new NullShellExecutor(); - $scheduler = new GenericScheduler($config, $executor); + $scheduler = new GenericScheduler($config, $argumentBag, $executor); $scheduler->run($at->modify('+1 minute')); $this->assertSame( - '(php tempest schedule:task Tests\\\Tempest\\\Integration\\\Console\\\Scheduler\\\GenericSchedulerTest::handler) >> /dev/null &', + '(' . PHP_BINARY . ' tempest schedule:task Tests\\\Tempest\\\Integration\\\Console\\\Scheduler\\\GenericSchedulerTest::handler) >> /dev/null &', $executor->executedCommand, ); }