diff --git a/Command/ListCommand.php b/Command/ListCommand.php index 8e8b3dd..340c205 100644 --- a/Command/ListCommand.php +++ b/Command/ListCommand.php @@ -4,6 +4,8 @@ * All rights reserved. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\Command; use Rewieer\TaskSchedulerBundle\Task\Scheduler; @@ -28,14 +30,14 @@ public function __construct(Scheduler $scheduler) protected function configure(): void { $this - ->setName("ts:list") - ->setDescription("List the existing tasks") - ->setHelp("This command display the list of registered tasks.") + ->setName('ts:list') + ->setDescription('List the existing tasks') + ->setHelp('This command display the list of registered tasks.') ->addOption( - "show-run-dates", + 'show-run-dates', null, InputOption::VALUE_OPTIONAL, - "Show next run dates (default value: " . self::NUMBER_OF_RUN_DATES . ")", + 'Show next run dates (default value: ' . self::NUMBER_OF_RUN_DATES . ')', false ); } @@ -46,10 +48,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $showRunDates = $numberOfRunDates !== false; $table = new Table($output); - $tableHeaders = ["ID", "Class"]; + $tableHeaders = ['ID', 'Class']; if ($showRunDates) { - $tableHeaders[] = "Next " . $numberOfRunDates . " run dates"; + $tableHeaders[] = 'Next ' . $numberOfRunDates . ' run dates'; } $table->setHeaders($tableHeaders); diff --git a/Command/RunCommand.php b/Command/RunCommand.php index 0be2883..17b1b85 100644 --- a/Command/RunCommand.php +++ b/Command/RunCommand.php @@ -5,6 +5,8 @@ * All rights reserved. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\Command; use Exception; @@ -28,21 +30,21 @@ public function __construct(Scheduler $scheduler) protected function configure(): void { $this - ->setName("ts:run") - ->setDescription("Run due tasks") + ->setName('ts:run') + ->setDescription('Run due tasks') ->setHelp(<<<'EOF' This command actually run the tasks that are due at the moment the command is called. This command should not be called manually. Check the documentation to learn how to set CRON jobs. EOF ) - ->addArgument("id", InputArgument::OPTIONAL, "The ID of the task. Check ts:list for IDs") - ->addOption("class", "c", InputOption::VALUE_OPTIONAL, "the class name of the task (without namespace)"); + ->addArgument('id', InputArgument::OPTIONAL, 'The ID of the task. Check ts:list for IDs') + ->addOption('class', 'c', InputOption::VALUE_OPTIONAL, 'the class name of the task (without namespace)'); } protected function execute(InputInterface $input, OutputInterface $output): int { - $id = $input->getArgument("id"); - $class = $input->getOption("class"); + $id = $input->getArgument('id'); + $class = $input->getOption('class'); if (!$id && !$class) { $this->scheduler->run(); @@ -54,13 +56,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int return self::SUCCESS; } } - throw new Exception("There are no tasks corresponding to this class name"); + throw new Exception('There are no tasks corresponding to this class name'); } else { $tasks = $this->scheduler->getTasks(); $id = (int)$id; if (array_key_exists($id - 1, $tasks) === false) { - throw new Exception("There are no tasks corresponding to this ID"); + throw new Exception('There are no tasks corresponding to this ID'); } $this->scheduler->runTask($tasks[$id - 1]); diff --git a/DependencyInjection/Compiler/EventDispatcherPass.php b/DependencyInjection/Compiler/EventDispatcherPass.php index a49fc77..5483eae 100644 --- a/DependencyInjection/Compiler/EventDispatcherPass.php +++ b/DependencyInjection/Compiler/EventDispatcherPass.php @@ -6,6 +6,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; @@ -16,7 +18,7 @@ * Class TaskPass * @package Rewieer\TaskSchedulerBundle\DependencyInjection\Compiler * - * Adds services tagged with "ts.task" to the scheduler + * Adds services tagged with 'ts.task' to the scheduler */ class EventDispatcherPass implements CompilerPassInterface { @@ -26,7 +28,7 @@ public function process(ContainerBuilder $container): void $tasks = $container->findTaggedServiceIds('ts.event_subscriber'); foreach ($tasks as $id => $tags) { - $definition->addMethodCall("addSubscriber", [new Reference($id)]); + $definition->addMethodCall('addSubscriber', [new Reference($id)]); } } } diff --git a/DependencyInjection/Compiler/TaskPass.php b/DependencyInjection/Compiler/TaskPass.php index 2864d77..90fb697 100644 --- a/DependencyInjection/Compiler/TaskPass.php +++ b/DependencyInjection/Compiler/TaskPass.php @@ -6,6 +6,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; @@ -16,7 +18,7 @@ * Class TaskPass * @package Rewieer\TaskSchedulerBundle\DependencyInjection\Compiler * - * Adds services tagged with "ts.task" to the scheduler + * Adds services tagged with 'ts.task' to the scheduler */ class TaskPass implements CompilerPassInterface { @@ -26,7 +28,7 @@ public function process(ContainerBuilder $container): void $tasks = $container->findTaggedServiceIds('ts.task'); foreach ($tasks as $id => $tags) { - $definition->addMethodCall("addTask", [new Reference($id)]); + $definition->addMethodCall('addTask', [new Reference($id)]); } } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index e772d63..76638a7 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -6,6 +6,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\TreeBuilder; diff --git a/DependencyInjection/RewieerTaskSchedulerExtension.php b/DependencyInjection/RewieerTaskSchedulerExtension.php index 0cabf13..e1d5260 100644 --- a/DependencyInjection/RewieerTaskSchedulerExtension.php +++ b/DependencyInjection/RewieerTaskSchedulerExtension.php @@ -6,6 +6,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\DependencyInjection; use Rewieer\TaskSchedulerBundle\Task\TaskInterface; diff --git a/Event/EventDispatcher.php b/Event/EventDispatcher.php index 3d3071c..4231d71 100644 --- a/Event/EventDispatcher.php +++ b/Event/EventDispatcher.php @@ -6,6 +6,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\Event; class EventDispatcher diff --git a/Event/EventSubscriberInterface.php b/Event/EventSubscriberInterface.php index 242cd7e..147ecf6 100644 --- a/Event/EventSubscriberInterface.php +++ b/Event/EventSubscriberInterface.php @@ -6,6 +6,7 @@ * file that was distributed with this source code. */ +declare(strict_types=1); namespace Rewieer\TaskSchedulerBundle\Event; diff --git a/Services/SchedulerLogger.php b/Services/SchedulerLogger.php index 710f37b..da3a747 100644 --- a/Services/SchedulerLogger.php +++ b/Services/SchedulerLogger.php @@ -6,6 +6,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\Services; use DateTime; @@ -33,40 +35,40 @@ public function __construct(LoggerInterface $logger) public function onStart(): void { $this->start = microtime(true); - $this->logger->info(sprintf("[%s] Starting...", (new Datetime())->format("d/m/y H:i:s"))); + $this->logger->info(sprintf('[%s] Starting...', (new Datetime())->format('d/m/y H:i:s'))); } public function beforeTaskRuns(TaskInterface $task): void { $this->current = microtime(true); - $this->logger->info(sprintf("Running %s", get_class($task))); + $this->logger->info(sprintf('Running %s', get_class($task))); } public function afterTaskRuns(TaskInterface $task): void { $time = microtime(true) - $this->current; - $this->logger->info(sprintf("Finished %s in %fs", get_class($task), $time)); + $this->logger->info(sprintf('Finished %s in %fs', get_class($task), $time)); } public function onEnd(): void { $time = microtime(true) - $this->start; - $this->logger->info(sprintf("Finished ! Took %fs", $time)); + $this->logger->info(sprintf('Finished ! Took %fs', $time)); } public function onSkip(TaskInterface $task): void { - $this->logger->info(sprintf("Skipped %s", get_class($task))); + $this->logger->info(sprintf('Skipped %s', get_class($task))); } public static function getEvents(): array { return [ - SchedulerEvents::ON_START => "onStart", - SchedulerEvents::BEFORE_TASK_RUNS => "beforeTaskRuns", - SchedulerEvents::AFTER_TASK_RUNS => "afterTaskRuns", - SchedulerEvents::ON_SKIP => "onSkip", - SchedulerEvents::ON_END => "onEnd", + SchedulerEvents::ON_START => 'onStart', + SchedulerEvents::BEFORE_TASK_RUNS => 'beforeTaskRuns', + SchedulerEvents::AFTER_TASK_RUNS => 'afterTaskRuns', + SchedulerEvents::ON_SKIP => 'onSkip', + SchedulerEvents::ON_END => 'onEnd', ]; } } diff --git a/Task/AbstractScheduledTask.php b/Task/AbstractScheduledTask.php index 68b27dc..f59e931 100644 --- a/Task/AbstractScheduledTask.php +++ b/Task/AbstractScheduledTask.php @@ -6,6 +6,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\Task; use DateTimeInterface; diff --git a/Task/Schedule.php b/Task/Schedule.php index 06e380f..ec299f7 100644 --- a/Task/Schedule.php +++ b/Task/Schedule.php @@ -7,6 +7,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\Task; use Cron\CronExpression; @@ -25,7 +27,7 @@ class Schedule * Schedule constructor. * @param string $expr the default cron */ - public function __construct(string $expr = "* * * * *") + public function __construct(string $expr = '* * * * *') { $this->cron = new CronExpression($expr, new FieldFactory()); } @@ -69,7 +71,7 @@ public function daysOfMonth($days): self */ public function daily(): self { - $this->cron->setPart(CronExpression::DAY, "*"); + $this->cron->setPart(CronExpression::DAY, '*'); return $this; } @@ -112,15 +114,15 @@ public function everyHours(int $hours = 1): self } /** - * Generic function to update a cron part as an "everyX" pattern - * such as "every 3 hours" or "every 10 minutes" + * Generic function to update a cron part as an 'everyX' pattern + * such as 'every 3 hours' or 'every 10 minutes' */ public function everyX(int $time = 1, int $part = CronExpression::MINUTE): self { if ($time === 0 || $time === 1) { - $expr = "*"; + $expr = '*'; } else { - $expr = "*/" . (string)$time; + $expr = '*/' . (string)$time; } $this->cron->setPart($part, $expr); @@ -138,7 +140,7 @@ public function getExpression(): string } /** - * Allows setting entire expression in string format like "0 * 2,7,12 * 7" + * Allows setting entire expression in string format like '0 * 2,7,12 * 7' * Exposes CronExpressions method directly */ public function setExpression(string $value): self diff --git a/Task/Scheduler.php b/Task/Scheduler.php index 13c8b2e..d5968c0 100644 --- a/Task/Scheduler.php +++ b/Task/Scheduler.php @@ -6,9 +6,10 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\Task; -use DateTimeInterface; use Rewieer\TaskSchedulerBundle\Event\EventDispatcher; class Scheduler @@ -34,7 +35,7 @@ public function addTask(TaskInterface $task): void $this->tasks[] = $task; } - public function run($currentTime = "now"): void + public function run($currentTime = 'now'): void { $this->dispatcher->dispatch(SchedulerEvents::ON_START); diff --git a/Task/SchedulerEvents.php b/Task/SchedulerEvents.php index f60d450..4f2d452 100644 --- a/Task/SchedulerEvents.php +++ b/Task/SchedulerEvents.php @@ -6,13 +6,15 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\Task; class SchedulerEvents { - public const ON_START = "onStart"; // called when the scheduler starts to loop through tasks - public const BEFORE_TASK_RUNS = "beforeTaskRuns"; // called before a task gets executed - public const AFTER_TASK_RUNS = "afterTaskRuns"; // called after a task gets executed - public const ON_SKIP = "onSkip"; // called when the task is skipped - public const ON_END = "onEnd"; // called after the scheduler runs all the tasks + public const ON_START = 'onStart'; // called when the scheduler starts to loop through tasks + public const BEFORE_TASK_RUNS = 'beforeTaskRuns'; // called before a task gets executed + public const AFTER_TASK_RUNS = 'afterTaskRuns'; // called after a task gets executed + public const ON_SKIP = 'onSkip'; // called when the task is skipped + public const ON_END = 'onEnd'; // called after the scheduler runs all the tasks } diff --git a/Task/TaskInterface.php b/Task/TaskInterface.php index 0913746..9f89e2a 100644 --- a/Task/TaskInterface.php +++ b/Task/TaskInterface.php @@ -6,6 +6,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\Task; use DateTimeInterface; diff --git a/Tests/Command/ListCommandTest.php b/Tests/Command/ListCommandTest.php index ecbf18b..f0c6707 100644 --- a/Tests/Command/ListCommandTest.php +++ b/Tests/Command/ListCommandTest.php @@ -6,6 +6,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\Tests\Command; use Rewieer\TaskSchedulerBundle\Command\ListCommand; @@ -27,46 +29,46 @@ public function testListCommand(): void $container = $this->loadContainer(); /** @var Scheduler $scheduler */ - $scheduler = $container->get("ts.scheduler"); + $scheduler = $container->get('ts.scheduler'); $scheduler->addTask(new TaskMock()); $application = new Application(); $application->add(new ListCommand($scheduler)); - $command = $application->find("ts:list"); + $command = $application->find('ts:list'); $commandTester = new CommandTester($command); $commandTester->execute([ - "command" => $command->getName(), + 'command' => $command->getName(), ]); $output = $commandTester->getDisplay(); - $this->assertStringNotContainsString("run dates", $output); - $this->assertStringContainsString("| 1 | Rewieer\TaskSchedulerBundle\Tests\TaskMock |", $output); + $this->assertStringNotContainsString('run dates', $output); + $this->assertStringContainsString('| 1 | Rewieer\TaskSchedulerBundle\Tests\TaskMock |', $output); } public function testListCommandWithOption(): void { $container = $this->loadContainer(); - $scheduler = $container->get("ts.scheduler"); + $scheduler = $container->get('ts.scheduler'); $scheduler->addTask(new TaskMock()); $application = new Application(); /** @var Scheduler $scheduler */ $application->add(new ListCommand($scheduler)); - $command = $application->find("ts:list"); + $command = $application->find('ts:list'); $commandTester = new CommandTester($command); $commandTester->execute([ - "command" => $command->getName(), - "--show-run-dates" => 42, + 'command' => $command->getName(), + '--show-run-dates' => 42, ]); $output = $commandTester->getDisplay(); - $this->assertStringContainsString("42 run dates", $output); + $this->assertStringContainsString('42 run dates', $output); $this->assertStringContainsString( - "| 1 | Rewieer\TaskSchedulerBundle\Tests\TaskMock | nextRunDate, anotherRunDate", + '| 1 | Rewieer\TaskSchedulerBundle\Tests\TaskMock | nextRunDate, anotherRunDate', $output ); } diff --git a/Tests/Command/RunCommandTest.php b/Tests/Command/RunCommandTest.php index 33164b6..216c854 100644 --- a/Tests/Command/RunCommandTest.php +++ b/Tests/Command/RunCommandTest.php @@ -6,6 +6,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\Tests\Command; use Rewieer\TaskSchedulerBundle\Command\RunCommand; @@ -26,16 +28,16 @@ public function testRunCommand(): void { $container = $this->loadContainer(); /** @var Scheduler $scheduler */ - $scheduler = $container->get("ts.scheduler"); + $scheduler = $container->get('ts.scheduler'); $scheduler->addTask(new TaskMock()); $application = new Application(); $application->add(new RunCommand($scheduler)); - $command = $application->find("ts:run"); + $command = $application->find('ts:run'); $commandTester = new CommandTester($command); $commandTester->execute([ - "command" => $command->getName(), + 'command' => $command->getName(), ]); $this->assertEquals(1, TaskMock::$runCount); @@ -46,7 +48,7 @@ public function testRunCommandWithId(): void $container = $this->loadContainer(); /** @var Scheduler $scheduler */ - $scheduler = $container->get("ts.scheduler"); + $scheduler = $container->get('ts.scheduler'); $t1 = new TaskMock(); $t2 = new TaskMock(); @@ -56,12 +58,12 @@ public function testRunCommandWithId(): void $application = new Application(); $application->add(new RunCommand($scheduler)); - $command = $application->find("ts:run"); + $command = $application->find('ts:run'); $commandTester = new CommandTester($command); $commandTester->execute([ - "command" => $command->getName(), - "id" => 1, + 'command' => $command->getName(), + 'id' => 1, ]); $this->assertEquals(1, TaskMock::$runCount); @@ -74,7 +76,7 @@ public function testRunCommandWithClassName(): void $container = $this->loadContainer(); /** @var Scheduler $scheduler */ - $scheduler = $container->get("ts.scheduler"); + $scheduler = $container->get('ts.scheduler'); $t1 = new TaskMock(); $t2 = new TaskMock(); @@ -84,12 +86,12 @@ public function testRunCommandWithClassName(): void $application = new Application(); $application->add(new RunCommand($scheduler)); - $command = $application->find("ts:run"); + $command = $application->find('ts:run'); $commandTester = new CommandTester($command); $commandTester->execute([ - "command" => $command->getName(), - "--class" => "TaskMock", + 'command' => $command->getName(), + '--class' => 'TaskMock', ]); diff --git a/Tests/DependencyInjection/Compiler/EventDispatcherPassTest.php b/Tests/DependencyInjection/Compiler/EventDispatcherPassTest.php index 55e05ed..9c40b2c 100644 --- a/Tests/DependencyInjection/Compiler/EventDispatcherPassTest.php +++ b/Tests/DependencyInjection/Compiler/EventDispatcherPassTest.php @@ -6,6 +6,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\Tests\DependencyInjection\Compiler; use Rewieer\TaskSchedulerBundle\DependencyInjection\Compiler\EventDispatcherPass; @@ -20,18 +22,18 @@ public function testLoadingPass(): void $container = $this->loadContainer(); $def = new Definition(EventSubscriberMock::class); - $def->addTag("ts.event_subscriber"); + $def->addTag('ts.event_subscriber'); $def->setPublic(true); - $container->setDefinition("mock.event_subscriber", $def); + $container->setDefinition('mock.event_subscriber', $def); $pass = new EventDispatcherPass(); $pass->process($container); $container->compile(); - $dispatcher = $container->get("ts.event_dispatcher"); + $dispatcher = $container->get('ts.event_dispatcher'); $this->assertEquals([ - $container->get("ts.scheduler_logger"), - $container->get("mock.event_subscriber") + $container->get('ts.scheduler_logger'), + $container->get('mock.event_subscriber') ], $dispatcher->getSubscribers()); } } diff --git a/Tests/DependencyInjection/Compiler/Task.php b/Tests/DependencyInjection/Compiler/Task.php index 25802ef..9ab4ad5 100644 --- a/Tests/DependencyInjection/Compiler/Task.php +++ b/Tests/DependencyInjection/Compiler/Task.php @@ -1,5 +1,7 @@ loadContainer(); $def = new Definition(Task::class); - $def->addTag("ts.task"); - $container->setDefinition("mock.task", $def); + $def->addTag('ts.task'); + $container->setDefinition('mock.task', $def); $pass = new TaskPass(); $pass->process($container); $container->compile(); - $scheduler = $container->get("ts.scheduler"); + $scheduler = $container->get('ts.scheduler'); $scheduler->run(); $this->assertEquals(1, Task::$runCount); diff --git a/Tests/DependencyInjection/ContainerAwareTest.php b/Tests/DependencyInjection/ContainerAwareTest.php index a537a16..b8e632f 100644 --- a/Tests/DependencyInjection/ContainerAwareTest.php +++ b/Tests/DependencyInjection/ContainerAwareTest.php @@ -6,6 +6,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\Tests\DependencyInjection; use Monolog\Logger; @@ -18,7 +20,7 @@ abstract class ContainerAwareTest extends TestCase public function loadContainer($config = []): ContainerBuilder { $container = new ContainerBuilder(); - $container->set("logger", new Logger("")); + $container->set('logger', new Logger('')); $extension = new RewieerTaskSchedulerExtension(); $extension->load($config, $container); diff --git a/Tests/Event/DummySubscriber.php b/Tests/Event/DummySubscriber.php index 9ac2e9f..4b73729 100644 --- a/Tests/Event/DummySubscriber.php +++ b/Tests/Event/DummySubscriber.php @@ -1,5 +1,7 @@ "callFoo", + 'foo' => 'callFoo', ]; } } diff --git a/Tests/Event/EventDispatcherTest.php b/Tests/Event/EventDispatcherTest.php index ca5352c..dfe290f 100644 --- a/Tests/Event/EventDispatcherTest.php +++ b/Tests/Event/EventDispatcherTest.php @@ -6,6 +6,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\Tests\Event; use PHPUnit\Framework\TestCase; @@ -19,7 +21,7 @@ public function testEventDispatcher(): void $subscriber = new DummySubscriber(); $dispatcher->addSubscriber($subscriber); - $dispatcher->dispatch("foo", [1, 2, 3]); + $dispatcher->dispatch('foo', [1, 2, 3]); $this->assertEquals([1, 2, 3], $subscriber->args); } } diff --git a/Tests/EventSubscriberMock.php b/Tests/EventSubscriberMock.php index ec3eb19..f9f1309 100644 --- a/Tests/EventSubscriberMock.php +++ b/Tests/EventSubscriberMock.php @@ -6,6 +6,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Rewieer\TaskSchedulerBundle\Tests; use Rewieer\TaskSchedulerBundle\Event\EventSubscriberInterface; @@ -17,37 +19,37 @@ class EventSubscriberMock implements EventSubscriberInterface public function onStart(): void { - self::$stack["onStart"] = func_get_args(); + self::$stack['onStart'] = func_get_args(); } public function beforeTaskRuns(): void { - self::$stack["beforeTaskRuns"] = func_get_args(); + self::$stack['beforeTaskRuns'] = func_get_args(); } public function afterTaskRuns(): void { - self::$stack["afterTaskRuns"] = func_get_args(); + self::$stack['afterTaskRuns'] = func_get_args(); } public function onEnd(): void { - self::$stack["onEnd"] = func_get_args(); + self::$stack['onEnd'] = func_get_args(); } public function onSkip(): void { - self::$stack["onSkip"] = func_get_args(); + self::$stack['onSkip'] = func_get_args(); } public static function getEvents(): array { return [ - SchedulerEvents::ON_START => "onStart", - SchedulerEvents::BEFORE_TASK_RUNS => "beforeTaskRuns", - SchedulerEvents::AFTER_TASK_RUNS => "afterTaskRuns", - SchedulerEvents::ON_SKIP => "onSkip", - SchedulerEvents::ON_END => "onEnd", + SchedulerEvents::ON_START => 'onStart', + SchedulerEvents::BEFORE_TASK_RUNS => 'beforeTaskRuns', + SchedulerEvents::AFTER_TASK_RUNS => 'afterTaskRuns', + SchedulerEvents::ON_SKIP => 'onSkip', + SchedulerEvents::ON_END => 'onEnd', ]; } } diff --git a/Tests/Services/SchedulerLoggerTest.php b/Tests/Services/SchedulerLoggerTest.php index 73f5e67..6244933 100644 --- a/Tests/Services/SchedulerLoggerTest.php +++ b/Tests/Services/SchedulerLoggerTest.php @@ -1,5 +1,7 @@ assertEquals( $schedule->getExpression(), - "* * * * *" + '* * * * *' ); } @@ -33,7 +35,7 @@ public function testHours(): void $this->assertEquals( $schedule->getExpression(), - "* 12 * * *" + '* 12 * * *' ); } @@ -44,7 +46,7 @@ public function testMinutes(): void $this->assertEquals( $schedule->getExpression(), - "12 * * * *" + '12 * * * *' ); } @@ -55,7 +57,7 @@ public function testEveryXMinutes(): void $this->assertEquals( $schedule->getExpression(), - "*/5 * * * *" + '*/5 * * * *' ); } @@ -66,72 +68,72 @@ public function testEveryXHours(): void $this->assertEquals( $schedule->getExpression(), - "* */5 * * *" + '* */5 * * *' ); } public function testDaily(): void { - $schedule = new Schedule("1 2 3 4 5"); + $schedule = new Schedule('1 2 3 4 5'); $schedule->daily(); $this->assertEquals( $schedule->getExpression(), - "1 2 * 4 5" + '1 2 * 4 5' ); } public function testMonths(): void { - $schedule = new Schedule("1 2 3 4 5"); + $schedule = new Schedule('1 2 3 4 5'); $schedule->months('7-9'); $this->assertEquals( $schedule->getExpression(), - "1 2 3 7-9 5" + '1 2 3 7-9 5' ); } public function testDaysOfWeek(): void { - $schedule = new Schedule("1 2 3 4 5"); + $schedule = new Schedule('1 2 3 4 5'); $schedule->daysOfWeek('mon'); $this->assertEquals( $schedule->getExpression(), - "1 2 * 4 mon" + '1 2 * 4 mon' ); } public function testDaysOfMonth(): void { - $schedule = new Schedule("1 2 3 4 5"); + $schedule = new Schedule('1 2 3 4 5'); $schedule->daysOfMonth('7,8,9'); $this->assertEquals( $schedule->getExpression(), - "1 2 7,8,9 4 *" + '1 2 7,8,9 4 *' ); } public function testSetExpression(): void { - $schedule = new Schedule("* * * * *"); - $schedule->setExpression("0 * * * *"); + $schedule = new Schedule('* * * * *'); + $schedule->setExpression('0 * * * *'); $this->assertEquals( $schedule->getExpression(), - "0 * * * *" + '0 * * * *' ); } public function testSetExpressionAllowedValues(): void { - $schedule = new Schedule("* * 2,7,12 * *"); - $schedule->setExpression("0 8-12 2,7,12 oct sat,sun"); + $schedule = new Schedule('* * 2,7,12 * *'); + $schedule->setExpression('0 8-12 2,7,12 oct sat,sun'); $this->assertEquals( - "0 8-12 2,7,12 oct sat,sun", + '0 8-12 2,7,12 oct sat,sun', $schedule->getExpression() ); } @@ -146,7 +148,7 @@ public function testSetPartExpression(): void $schedule->setPart(CronExpression::WEEKDAY, 'sat,sun'); $this->assertEquals( - "0 8-12 2,7,12 oct sat,sun", + '0 8-12 2,7,12 oct sat,sun', $schedule->getExpression() ); } diff --git a/Tests/Task/ScheduledTask.php b/Tests/Task/ScheduledTask.php index d8178e6..4f48893 100644 --- a/Tests/Task/ScheduledTask.php +++ b/Tests/Task/ScheduledTask.php @@ -1,5 +1,7 @@ addTask(new Task()); $scheduler->addTask(new ScheduledTask()); - $scheduler->run("2015-06-21 03:50:00"); + $scheduler->run('2015-06-21 03:50:00'); $this->assertEquals(1, Task::$runCount); $this->assertEquals(1, ScheduledTask::$runCount); @@ -54,11 +56,11 @@ public function testCallingDispatcher(): void $scheduler->addTask($task); $scheduler->run(); - $this->assertEquals([], EventSubscriberMock::$stack["onStart"]); - $this->assertEquals([$task], EventSubscriberMock::$stack["beforeTaskRuns"]); - $this->assertEquals([$task], EventSubscriberMock::$stack["afterTaskRuns"]); - $this->assertArrayNotHasKey("onSkip", EventSubscriberMock::$stack); - $this->assertEquals([], EventSubscriberMock::$stack["onEnd"]); + $this->assertEquals([], EventSubscriberMock::$stack['onStart']); + $this->assertEquals([$task], EventSubscriberMock::$stack['beforeTaskRuns']); + $this->assertEquals([$task], EventSubscriberMock::$stack['afterTaskRuns']); + $this->assertArrayNotHasKey('onSkip', EventSubscriberMock::$stack); + $this->assertEquals([], EventSubscriberMock::$stack['onEnd']); } public function testCallingDispatcherOnSkip(): void @@ -73,10 +75,10 @@ public function testCallingDispatcherOnSkip(): void $scheduler->addTask($task); $scheduler->run(); - $this->assertEquals([], EventSubscriberMock::$stack["onStart"]); - $this->assertArrayNotHasKey("beforeTaskRuns", EventSubscriberMock::$stack); - $this->assertArrayNotHasKey("afterTaskRuns", EventSubscriberMock::$stack); - $this->assertEquals([$task], EventSubscriberMock::$stack["onSkip"]); - $this->assertEquals([], EventSubscriberMock::$stack["onEnd"]); + $this->assertEquals([], EventSubscriberMock::$stack['onStart']); + $this->assertArrayNotHasKey('beforeTaskRuns', EventSubscriberMock::$stack); + $this->assertArrayNotHasKey('afterTaskRuns', EventSubscriberMock::$stack); + $this->assertEquals([$task], EventSubscriberMock::$stack['onSkip']); + $this->assertEquals([], EventSubscriberMock::$stack['onEnd']); } } diff --git a/Tests/Task/Task.php b/Tests/Task/Task.php index 1427289..da91a6d 100644 --- a/Tests/Task/Task.php +++ b/Tests/Task/Task.php @@ -1,5 +1,7 @@ - . + . - + - - + + - - + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + +