@@ -24,15 +24,22 @@ public function testConfigure()
2424 public function runProvider ()
2525 {
2626 return [
27+ ['test-handler ' ],
2728 ['test-handler ' , 'test-workload ' ],
2829 ['test-handler-1 ' , 'test-workload-1 ' ],
30+ ['test-handler ' , 'test-workload ' , '1 * * * * ' ],
31+ ['test-handler ' , 'test-workload ' , '1 * * * * ' , '+1 week ' ],
32+ ['test-handler ' , 'test-workload ' , '1 * * * * ' , '+1 week ' , 'test-key ' ],
33+ ['test-handler ' , 'test-workload ' , '1 * * * * ' , null , 'test-key ' ],
34+ ['test-handler ' , 'test-workload ' , null , null , 'test-key ' ],
35+ ['test-handler ' , 'test-workload ' , null , '+1 week ' , 'test-key ' ],
2936 ];
3037 }
3138
3239 /**
3340 * @dataProvider runProvider
3441 */
35- public function testRun ($ handler , $ workload )
42+ public function testRun ($ handler , $ workload = null , $ cronExpression = null , $ endDateString = null , $ key = null )
3643 {
3744 $ taskBuilder = $ this ->prophesize (TaskBuilderInterface::class);
3845
@@ -46,14 +53,34 @@ public function testRun($handler, $workload)
4653
4754 $ input ->getArgument ('handler ' )->willReturn ($ handler );
4855 $ input ->getArgument ('workload ' )->willReturn ($ workload );
56+ $ input ->getOption ('cron-expression ' )->willReturn ($ cronExpression );
57+ $ input ->getOption ('end-date ' )->willReturn ($ endDateString );
58+ $ input ->getOption ('key ' )->willReturn ($ key );
4959
5060 $ scheduler = $ this ->prophesize (SchedulerInterface::class);
5161 $ command = new ScheduleTaskCommand ('task:schedule:task ' , $ scheduler ->reveal ());
5262
5363 $ scheduler ->createTask ($ handler , $ workload )->shouldBeCalledTimes (1 )->willReturn ($ taskBuilder ->reveal ());
5464
55- $ command ->run ($ input ->reveal (), $ output ->reveal ());
65+ if ($ key !== null ) {
66+ $ taskBuilder ->setKey ($ key )->shouldBeCalled ();
67+ } else {
68+ $ taskBuilder ->setKey (Argument::any ())->shouldNotBeCalled ();
69+ }
70+ if ($ cronExpression !== null ) {
71+ $ endDate = null ;
72+ if ($ endDateString !== null ) {
73+ $ endDate = new \DateTime ($ endDateString );
74+ }
5675
76+ $ taskBuilder ->cron ($ cronExpression , Argument::type (\DateTime::class), $ endDate )->shouldBeCalled ()
77+ ->willReturn ($ taskBuilder ->reveal ());
78+ } else {
79+ $ taskBuilder ->cron (Argument::any (), Argument::any (), Argument::any ())->shouldNotBeCalled ()
80+ ->willReturn ($ taskBuilder ->reveal ());
81+ }
5782 $ taskBuilder ->schedule ()->shouldBeCalledTimes (1 );
83+
84+ $ command ->run ($ input ->reveal (), $ output ->reveal ());
5885 }
5986}
0 commit comments