From 7f5e683ea8f41396e6ecbd9b1bb3870bbf0154f8 Mon Sep 17 00:00:00 2001 From: Herbert Maschke Date: Fri, 18 Feb 2022 16:47:06 +0100 Subject: [PATCH 1/2] avoid passing argument key to command line argument --- src/Console/Scheduling/Schedule.php | 2 +- tests/Feature/ScheduleCommandTest.php | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Console/Scheduling/Schedule.php b/src/Console/Scheduling/Schedule.php index 01085a6..d81d9bf 100644 --- a/src/Console/Scheduling/Schedule.php +++ b/src/Console/Scheduling/Schedule.php @@ -43,7 +43,7 @@ private function dispatch($task) $command = $task->command; $event = $this->schedule->command( $command, - $task->getArguments() + $task->getOptions() + array_values($task->getArguments()) + $task->getOptions() ); } $event->cron($task->expression); diff --git a/tests/Feature/ScheduleCommandTest.php b/tests/Feature/ScheduleCommandTest.php index 1cbda1d..7a31174 100644 --- a/tests/Feature/ScheduleCommandTest.php +++ b/tests/Feature/ScheduleCommandTest.php @@ -52,7 +52,10 @@ public function testCommandWithRequiredArgument() $events->each(function (\Illuminate\Console\Scheduling\Event $event) use ($task) { // This example is for hourly commands. $this->assertEquals($task->expression, $event->expression); - $this->assertStringEndsWith("phpunit:test argument='this is a argument'", $event->command); + $this->assertStringEndsWith( + "phpunit:test 'this is a argument'", + $event->command + ); }); } @@ -75,7 +78,9 @@ public function testCommandWithOptionalArgument() /** @var \Illuminate\Console\Scheduling\Schedule $schedule */ $schedule = app()->make(\Illuminate\Console\Scheduling\Schedule::class); - $events = collect($schedule->events())->filter(function (\Illuminate\Console\Scheduling\Event $event) use ($task) { + $events = collect( + $schedule->events())->filter( + function (\Illuminate\Console\Scheduling\Event $event) use ($task) { return stripos($event->command, $task->command); }); @@ -86,7 +91,10 @@ public function testCommandWithOptionalArgument() $events->each(function (\Illuminate\Console\Scheduling\Event $event) use ($task) { // This example is for hourly commands. $this->assertEquals($task->expression, $event->expression); - $this->assertStringEndsWith("phpunit:test argument='this is a argument' optionalArgument='this is a optional argument'", $event->command); + $this->assertStringEndsWith( + "phpunit:test 'this is a argument' 'this is a optional argument'", + $event->command + ); }); } } From a7bae359993a7bb9d47aa9c191977e867d9322a6 Mon Sep 17 00:00:00 2001 From: Herbert Maschke Date: Fri, 18 Feb 2022 17:34:12 +0100 Subject: [PATCH 2/2] attempt to pass pipeline --- tests/Feature/ScheduleCommandTest.php | 29 +++++++++++++++------------ tests/Unit/ScheduleCommandsTest.php | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/Feature/ScheduleCommandTest.php b/tests/Feature/ScheduleCommandTest.php index 7a31174..d7f9370 100644 --- a/tests/Feature/ScheduleCommandTest.php +++ b/tests/Feature/ScheduleCommandTest.php @@ -70,7 +70,7 @@ public function testCommandWithOptionalArgument() 'type' => 'string' ], 'optionalArgument' => [ - 'value' => 'this is a optional argument', + 'value' => 'optional argument', 'type' => 'string' ] ] @@ -78,23 +78,26 @@ public function testCommandWithOptionalArgument() /** @var \Illuminate\Console\Scheduling\Schedule $schedule */ $schedule = app()->make(\Illuminate\Console\Scheduling\Schedule::class); - $events = collect( - $schedule->events())->filter( + $events = collect($schedule->events()) + ->filter( function (\Illuminate\Console\Scheduling\Event $event) use ($task) { - return stripos($event->command, $task->command); - }); + return stripos($event->command, $task->command); + } + ); if ($events->count() == 0) { $this->fail('No events found'); } - $events->each(function (\Illuminate\Console\Scheduling\Event $event) use ($task) { - // This example is for hourly commands. - $this->assertEquals($task->expression, $event->expression); - $this->assertStringEndsWith( - "phpunit:test 'this is a argument' 'this is a optional argument'", - $event->command - ); - }); + $events->each( + function (\Illuminate\Console\Scheduling\Event $event) use ($task) { + // This example is for hourly commands. + $this->assertEquals($task->expression, $event->expression); + $this->assertStringEndsWith( + "phpunit:test 'this is a argument' 'optional argument'", + $event->command + ); + } + ); } } diff --git a/tests/Unit/ScheduleCommandsTest.php b/tests/Unit/ScheduleCommandsTest.php index fce2837..3544ffa 100644 --- a/tests/Unit/ScheduleCommandsTest.php +++ b/tests/Unit/ScheduleCommandsTest.php @@ -64,7 +64,7 @@ public function testRunInspireWithArguments() $this->mock(\Illuminate\Console\Scheduling\Schedule::class, function (Mockery\MockInterface $mock) { $mock->shouldReceive('command') ->once() - ->with('inspire', ['test' => '1']) + ->with('inspire', ['1']) ->andReturn($this->event); });