diff --git a/src/Maker/MakeSchedule.php b/src/Maker/MakeSchedule.php index 6bf1c3d99..3e94d8ed2 100644 --- a/src/Maker/MakeSchedule.php +++ b/src/Maker/MakeSchedule.php @@ -37,6 +37,7 @@ final class MakeSchedule extends AbstractMaker { private string $scheduleName; private ?string $message = null; + private ?string $transportName = null; public function __construct( private FileManager $fileManager, @@ -82,6 +83,8 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma } } + $this->transportName = $io->ask('What should we call the new transport? (To be used for the attribute #[AsSchedule(name)])'); + $scheduleNameHint = 'MainSchedule'; // If the count is 1, no other messages were found - don't ask to create a message @@ -126,6 +129,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen 'use_statements' => $useStatements, 'has_custom_message' => null !== $this->message, 'message_class_name' => $this->message, + 'has_transport_name' => null !== $this->transportName, + 'transport_name' => $this->transportName, ], ); diff --git a/src/Resources/skeleton/scheduler/Schedule.tpl.php b/src/Resources/skeleton/scheduler/Schedule.tpl.php index e22be4f2e..1c34b991b 100644 --- a/src/Resources/skeleton/scheduler/Schedule.tpl.php +++ b/src/Resources/skeleton/scheduler/Schedule.tpl.php @@ -4,7 +4,7 @@ -#[AsSchedule] +#[AsSchedule('')] final class implements ScheduleProviderInterface { public function __construct( diff --git a/tests/Maker/MakeScheduleTest.php b/tests/Maker/MakeScheduleTest.php index 126d3ca5c..841d44856 100644 --- a/tests/Maker/MakeScheduleTest.php +++ b/tests/Maker/MakeScheduleTest.php @@ -24,9 +24,26 @@ protected function getMakerClass(): string public function getTestDetails(): \Generator { + yield 'it_generates_a_schedule_with_transport_name' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $output = $runner->runMaker([ + 'dummy', // use transport name "dummy" + '', // use default schedule name "MainSchedule" + ]); + + $this->assertStringContainsString('Success', $output); + + self::assertFileEquals( + \dirname(__DIR__).'/fixtures/make-schedule/expected/DefaultScheduleWithTransportName.php', + $runner->getPath('src/Scheduler/MainSchedule.php') + ); + }), + ]; + yield 'it_generates_a_schedule' => [$this->createMakerTest() ->run(function (MakerTestRunner $runner) { $output = $runner->runMaker([ + '', // use default transport name '', // use default schedule name "MainSchedule" ]); @@ -48,6 +65,7 @@ public function getTestDetails(): \Generator }) ->run(function (MakerTestRunner $runner) { $output = $runner->runMaker([ + '', // Use the default transport name 0, // Select "Empty Schedule" 'MySchedule', // Go with the default name "MainSchedule" ]); @@ -70,6 +88,7 @@ public function getTestDetails(): \Generator }) ->run(function (MakerTestRunner $runner) { $output = $runner->runMaker([ + '', // Use the default transport name 1, // Select "MyMessage" from choice '', // Go with the default name "MessageFixtureSchedule" ]); diff --git a/tests/fixtures/make-schedule/expected/DefaultScheduleWithTransportName.php b/tests/fixtures/make-schedule/expected/DefaultScheduleWithTransportName.php new file mode 100644 index 000000000..e5a7e5a5e --- /dev/null +++ b/tests/fixtures/make-schedule/expected/DefaultScheduleWithTransportName.php @@ -0,0 +1,29 @@ +add( + // @TODO - Create a Message to schedule + // RecurringMessage::every('1 hour', new App\Message\Message()), + ) + ->stateful($this->cache) + ; + } +}