diff --git a/src/Command/DebugTasksCommand.php b/src/Command/DebugTasksCommand.php
index 4de05e8..3cbd9dc 100644
--- a/src/Command/DebugTasksCommand.php
+++ b/src/Command/DebugTasksCommand.php
@@ -65,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$page = $input->getOption('page');
$pageSize = $input->getOption('page-size');
- $executions = $this->taskExecutionRepository->findAll($page, $pageSize);
+ $executions = $this->taskExecutionRepository->findAllPaginated($page, $pageSize);
$table = new Table($output);
$table->setHeaders(['uuid', 'status', 'handler', 'schedule time', 'end time', 'duration']);
@@ -76,8 +76,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$execution->getUuid(),
$execution->getStatus(),
$execution->getHandlerClass(),
- $execution->getScheduleTime()->format(\DateTime::RFC3339),
- !$execution->getEndTime() ? '' : $execution->getEndTime()->format(\DateTime::RFC3339),
+ $execution->getScheduleTime()->format(\DateTimeImmutable::RFC3339),
+ !$execution->getEndTime() ? '' : $execution->getEndTime()->format(\DateTimeImmutable::RFC3339),
(round($execution->getDuration(), 6) * 1000000) . 'ms',
]
);
diff --git a/src/Command/ScheduleSystemTasksCommand.php b/src/Command/ScheduleSystemTasksCommand.php
index 808e0ad..6a34388 100644
--- a/src/Command/ScheduleSystemTasksCommand.php
+++ b/src/Command/ScheduleSystemTasksCommand.php
@@ -177,7 +177,7 @@ private function disableSystemTask($systemKey)
*/
public function disableTask(TaskInterface $task)
{
- $task->setInterval($task->getInterval(), $task->getFirstExecution(), new \DateTime());
+ $task->setInterval($task->getInterval(), $task->getFirstExecution(), new \DateTimeImmutable());
return $this->abortPending($task);
}
diff --git a/src/Command/ScheduleTaskCommand.php b/src/Command/ScheduleTaskCommand.php
index 16a2fc7..e96da6d 100644
--- a/src/Command/ScheduleTaskCommand.php
+++ b/src/Command/ScheduleTaskCommand.php
@@ -83,14 +83,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (null !== $cronExpression) {
$endDate = null;
if (null !== $endDateString) {
- $endDate = new \DateTime($endDateString);
+ $endDate = new \DateTimeImmutable($endDateString);
}
- $taskBuilder->cron($cronExpression, new \DateTime(), $endDate);
+ $taskBuilder->cron($cronExpression, new \DateTimeImmutable(), $endDate);
}
if (null !== $executionDateString) {
- $taskBuilder->executeAt(new \DateTime($executionDateString));
+ $taskBuilder->executeAt(new \DateTimeImmutable($executionDateString));
}
$taskBuilder->schedule();
diff --git a/src/Entity/Task.php b/src/Entity/Task.php
index 9dbafa2..d6793f1 100644
--- a/src/Entity/Task.php
+++ b/src/Entity/Task.php
@@ -52,7 +52,7 @@ public function getInterval()
/**
* {@inheritdoc}
*/
- public function setInterval(CronExpression $interval, \DateTime $firstExecution = null, \DateTime $lastExecution = null)
+ public function setInterval(CronExpression $interval, \DateTimeImmutable $firstExecution = null, \DateTimeImmutable $lastExecution = null)
{
parent::setInterval($interval, $firstExecution, $lastExecution);
diff --git a/src/Entity/TaskExecutionRepository.php b/src/Entity/TaskExecutionRepository.php
index 3bb6db5..7236008 100644
--- a/src/Entity/TaskExecutionRepository.php
+++ b/src/Entity/TaskExecutionRepository.php
@@ -26,7 +26,7 @@ class TaskExecutionRepository extends EntityRepository implements TaskExecutionR
/**
* {@inheritdoc}
*/
- public function create(TaskInterface $task, \DateTime $scheduleTime)
+ public function create(TaskInterface $task, \DateTimeImmutable $scheduleTime)
{
return new TaskExecution($task, $task->getHandlerClass(), $scheduleTime, $task->getWorkload());
}
@@ -36,8 +36,8 @@ public function create(TaskInterface $task, \DateTime $scheduleTime)
*/
public function save(TaskExecutionInterface $execution)
{
- $this->_em->persist($execution);
- $this->_em->flush($execution);
+ $this->getEntityManager()->persist($execution);
+ $this->getEntityManager()->flush($execution);
return $this;
}
@@ -47,8 +47,8 @@ public function save(TaskExecutionInterface $execution)
*/
public function remove(TaskExecutionInterface $execution)
{
- $this->_em->remove($execution);
- $this->_em->flush($execution);
+ $this->getEntityManager()->remove($execution);
+ $this->getEntityManager()->flush($execution);
return $this;
}
@@ -56,7 +56,7 @@ public function remove(TaskExecutionInterface $execution)
/**
* {@inheritdoc}
*/
- public function findAll($page = 1, $pageSize = null)
+ public function findAllPaginated(int $page = 1, ?int $pageSize = null): array
{
$query = $this->createQueryBuilder('e')
->innerJoin('e.task', 't')
@@ -129,13 +129,13 @@ public function findByTaskUuid($taskUuid)
/**
* {@inheritdoc}
*/
- public function findNextScheduled(\DateTime $dateTime = null, array $skippedExecutions = [])
+ public function findNextScheduled(\DateTimeImmutable $dateTime = null, array $skippedExecutions = [])
{
$queryBuilder = $this->createQueryBuilder('e')
->innerJoin('e.task', 't')
->where('e.status = :status')
->andWhere('e.scheduleTime < :date')
- ->setParameter('date', $dateTime ?: new \DateTime())
+ ->setParameter('date', $dateTime ?: new \DateTimeImmutable())
->setParameter('status', TaskStatus::PLANNED)
->setMaxResults(1);
diff --git a/src/Entity/TaskRepository.php b/src/Entity/TaskRepository.php
index 7cf7fb7..bc93005 100644
--- a/src/Entity/TaskRepository.php
+++ b/src/Entity/TaskRepository.php
@@ -11,7 +11,6 @@
namespace Task\TaskBundle\Entity;
-use DateTime;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NoResultException;
use Task\TaskInterface;
@@ -44,8 +43,8 @@ public function findByUuid($uuid)
*/
public function save(TaskInterface $task)
{
- $this->_em->persist($task);
- $this->_em->flush($task);
+ $this->getEntityManager()->persist($task);
+ $this->getEntityManager()->flush($task);
return $this;
}
@@ -55,8 +54,8 @@ public function save(TaskInterface $task)
*/
public function remove(TaskInterface $task)
{
- $this->_em->remove($task);
- $this->_em->flush($task);
+ $this->getEntityManager()->remove($task);
+ $this->getEntityManager()->flush($task);
return $this;
}
@@ -64,7 +63,7 @@ public function remove(TaskInterface $task)
/**
* {@inheritdoc}
*/
- public function findAll($page = 1, $pageSize = null): array
+ public function findAllPaginated(int $page = 1, ?int $pageSize = null): array
{
$query = $this->createQueryBuilder('t')
->getQuery();
@@ -82,17 +81,17 @@ public function findAll($page = 1, $pageSize = null): array
*/
public function findEndBeforeNow()
{
- return $this->findEndBefore(new \DateTime());
+ return $this->findEndBefore(new \DateTimeImmutable());
}
/**
* Returns task where last-execution is before given date-time.
*
- * @param \DateTime $dateTime
+ * @param \DateTimeImmutable $dateTime
*
* @return TaskInterface[]
*/
- public function findEndBefore(\DateTime $dateTime)
+ public function findEndBefore(\DateTimeImmutable $dateTime)
{
return $this->createQueryBuilder('t')
->where('t.lastExecution IS NULL OR t.lastExecution > :dateTime')
diff --git a/src/Resources/config/doctrine/Task.orm.xml b/src/Resources/config/doctrine/Task.orm.xml
index 93a6c12..5402595 100644
--- a/src/Resources/config/doctrine/Task.orm.xml
+++ b/src/Resources/config/doctrine/Task.orm.xml
@@ -15,10 +15,10 @@
-
-
+
+
-
+
diff --git a/src/Resources/config/doctrine/TaskExecution.orm.xml b/src/Resources/config/doctrine/TaskExecution.orm.xml
index 54ece00..f76bb2b 100644
--- a/src/Resources/config/doctrine/TaskExecution.orm.xml
+++ b/src/Resources/config/doctrine/TaskExecution.orm.xml
@@ -14,19 +14,18 @@
-
+
-
-
-
+
+
+
-
+
-
diff --git a/tests/Functional/BaseCommandTestCase.php b/tests/Functional/BaseCommandTestCase.php
index 344de77..cf40ee8 100644
--- a/tests/Functional/BaseCommandTestCase.php
+++ b/tests/Functional/BaseCommandTestCase.php
@@ -102,7 +102,7 @@ protected function createTask($workload, CronExpression $cronExpression = null,
{
$task = $this->taskRepository->create($handlerClass, $workload);
if ($cronExpression) {
- $task->setInterval($cronExpression, new \DateTime(), new \DateTime('+1 year'));
+ $task->setInterval($cronExpression, new \DateTimeImmutable(), new \DateTimeImmutable('+1 year'));
}
$this->taskRepository->save($task);
@@ -113,12 +113,12 @@ protected function createTask($workload, CronExpression $cronExpression = null,
* Create task-execution.
*
* @param TaskInterface $task
- * @param \DateTime $scheduleTime
+ * @param \DateTimeImmutable $scheduleTime
* @param string $status
*
* @return TaskExecutionInterface
*/
- protected function createTaskExecution(TaskInterface $task, \DateTime $scheduleTime, $status = TaskStatus::PLANNED)
+ protected function createTaskExecution(TaskInterface $task, \DateTimeImmutable $scheduleTime, $status = TaskStatus::PLANNED)
{
$execution = $this->taskExecutionRepository->create($task, $scheduleTime);
$execution->setStatus($status);
diff --git a/tests/Functional/BaseDatabaseTestCase.php b/tests/Functional/BaseDatabaseTestCase.php
index 4380eb6..38f7164 100644
--- a/tests/Functional/BaseDatabaseTestCase.php
+++ b/tests/Functional/BaseDatabaseTestCase.php
@@ -73,12 +73,12 @@ protected function createTask($handlerClass = TestHandler::class)
* Create a new task-execution.
*
* @param TaskInterface $task
- * @param \DateTime $scheduleTime
+ * @param \DateTimeImmutable $scheduleTime
* @param string $status
*
* @return TaskExecution
*/
- protected function createTaskExecution(TaskInterface $task, \DateTime $scheduleTime, $status = TaskStatus::PLANNED)
+ protected function createTaskExecution(TaskInterface $task, \DateTimeImmutable $scheduleTime, $status = TaskStatus::PLANNED)
{
$execution = new TaskExecution($task, $task->getHandlerClass(), $scheduleTime);
$execution->setStatus($status);
diff --git a/tests/Functional/Command/DebugTasksCommandTest.php b/tests/Functional/Command/DebugTasksCommandTest.php
index cd87182..33fe3a5 100644
--- a/tests/Functional/Command/DebugTasksCommandTest.php
+++ b/tests/Functional/Command/DebugTasksCommandTest.php
@@ -26,8 +26,8 @@ public function testExecute()
/** @var TaskExecutionInterface[] $executions */
$executions = [
- $this->createTaskExecution($task, new \DateTime('-1 hour'), TaskStatus::COMPLETED),
- $this->createTaskExecution($task, new \DateTime('-2 hour'), TaskStatus::COMPLETED),
+ $this->createTaskExecution($task, new \DateTimeImmutable('-1 hour'), TaskStatus::COMPLETED),
+ $this->createTaskExecution($task, new \DateTimeImmutable('-2 hour'), TaskStatus::COMPLETED),
];
$executions[0]->setResult(strrev($executions[0]->getWorkload()));
@@ -59,9 +59,9 @@ public function testExecutePaginated()
/** @var TaskExecutionInterface[] $executions */
$executions = [
- $this->createTaskExecution($task, new \DateTime('-1 hour')),
- $this->createTaskExecution($task, new \DateTime('-2 hour')),
- $this->createTaskExecution($task, new \DateTime('+1 hour')),
+ $this->createTaskExecution($task, new \DateTimeImmutable('-1 hour')),
+ $this->createTaskExecution($task, new \DateTimeImmutable('-2 hour')),
+ $this->createTaskExecution($task, new \DateTimeImmutable('+1 hour')),
];
if (self::$kernel->getContainer()->has('doctrine')) {
diff --git a/tests/Functional/Command/RunCommandTest.php b/tests/Functional/Command/RunCommandTest.php
index 252cd55..ececabc 100644
--- a/tests/Functional/Command/RunCommandTest.php
+++ b/tests/Functional/Command/RunCommandTest.php
@@ -31,9 +31,9 @@ public function testExecute()
/** @var TaskExecutionInterface[] $executions */
$executions = [
- $this->createTaskExecution($singleTask, new \DateTime('-1 hour')),
- $this->createTaskExecution($laterTask, new \DateTime('+1 hour')),
- $this->createTaskExecution($intervalTask, new \DateTime('-2 hour')),
+ $this->createTaskExecution($singleTask, new \DateTimeImmutable('-1 hour')),
+ $this->createTaskExecution($laterTask, new \DateTimeImmutable('+1 hour')),
+ $this->createTaskExecution($intervalTask, new \DateTimeImmutable('-2 hour')),
];
$this->commandTester->execute(
@@ -61,7 +61,7 @@ public function testExecute()
$this->assertGreaterThan(0, $execution->getDuration());
$this->assertGreaterThanOrEqual($execution->getStartTime(), $execution->getEndTime());
- $result = $this->taskExecutionRepository->findAll(2, 3);
+ $result = $this->taskExecutionRepository->findAllPaginated(2, 3);
$this->assertCount(1, $result);
$task = $result[0]->getTask();
@@ -89,9 +89,9 @@ public function testExecuteWithFail()
/** @var TaskExecutionInterface[] $executions */
$executions = [
- $this->createTaskExecution($singleTask, new \DateTime('-1 hour')),
- $this->createTaskExecution($laterTask, new \DateTime('+1 hour')),
- $this->createTaskExecution($intervalTask, new \DateTime('-2 hour')),
+ $this->createTaskExecution($singleTask, new \DateTimeImmutable('-1 hour')),
+ $this->createTaskExecution($laterTask, new \DateTimeImmutable('+1 hour')),
+ $this->createTaskExecution($intervalTask, new \DateTimeImmutable('-2 hour')),
];
$this->commandTester->execute(
@@ -119,7 +119,7 @@ public function testExecuteWithFail()
$this->assertGreaterThan(0, $execution->getDuration());
$this->assertGreaterThanOrEqual($execution->getStartTime(), $execution->getEndTime());
- $result = $this->taskExecutionRepository->findAll(2, 3);
+ $result = $this->taskExecutionRepository->findAllPaginated(2, 3);
$this->assertCount(1, $result);
$task = $result[0]->getTask();
diff --git a/tests/Functional/Command/ScheduleTaskCommandTest.php b/tests/Functional/Command/ScheduleTaskCommandTest.php
index 2dd3360..e6d0995 100644
--- a/tests/Functional/Command/ScheduleTaskCommandTest.php
+++ b/tests/Functional/Command/ScheduleTaskCommandTest.php
@@ -77,14 +77,14 @@ public function testExecuteWithWorkloadAndInterval()
public function testExecuteWithWorkloadAndIntervalAndEndDate()
{
- $date = new \DateTime('+1 day');
+ $date = new \DateTimeImmutable('+1 day');
$this->commandTester->execute(
[
'command' => $this->command->getName(),
'handlerClass' => TestHandler::class,
'workload' => 'Test workload 1',
'--cron-expression' => '0 * * * *',
- '--end-date' => $date->format(\DateTime::RFC3339),
+ '--end-date' => $date->format(\DateTimeImmutable::RFC3339),
]
);
@@ -99,7 +99,7 @@ public function testExecuteWithWorkloadAndIntervalAndEndDate()
public function testExecuteWithExecutionDate()
{
- $date = new \DateTime('+1 day');
+ $date = new \DateTimeImmutable('+1 day');
$this->commandTester->execute(
[
'command' => $this->command->getName(),
diff --git a/tests/Functional/Entity/TaskExecutionRepositoryTest.php b/tests/Functional/Entity/TaskExecutionRepositoryTest.php
index 6ecc982..0a94fa2 100644
--- a/tests/Functional/Entity/TaskExecutionRepositoryTest.php
+++ b/tests/Functional/Entity/TaskExecutionRepositoryTest.php
@@ -85,7 +85,7 @@ public function testFindAllPaginated()
$executions[$execution->getUuid()] = $execution;
}
- $result = $this->taskExecutionRepository->findAll(1, 2);
+ $result = $this->taskExecutionRepository->findAllPaginated(1, 2);
$this->assertCount(2, $result);
foreach ($result as $item) {
@@ -93,7 +93,7 @@ public function testFindAllPaginated()
unset($executions[$item->getUuid()]);
}
- $result = $this->taskExecutionRepository->findAll(2, 2);
+ $result = $this->taskExecutionRepository->findAllPaginated(2, 2);
$this->assertCount(1, $result);
foreach ($result as $item) {
@@ -152,7 +152,7 @@ public function testFindScheduledPast()
$task = $this->createTask();
$this->taskRepository->save($task);
- $execution = $this->save($task, new \DateTime('-1 hour'));
+ $execution = $this->save($task, new \DateTimeImmutable('-1 hour'));
$result = $this->taskExecutionRepository->findNextScheduled();
$this->assertEquals($execution->getUuid(), $result->getUuid());
@@ -163,7 +163,7 @@ public function testFindScheduledFuture()
$task = $this->createTask();
$this->taskRepository->save($task);
- $this->save($task, new \DateTime('+1 hour'));
+ $this->save($task, new \DateTimeImmutable('+1 hour'));
$this->assertNull($this->taskExecutionRepository->findNextScheduled());
}
@@ -173,7 +173,7 @@ public function testFindScheduledSkipped()
$task = $this->createTask();
$this->taskRepository->save($task);
- $this->save($task, new \DateTime('+1 hour'));
+ $this->save($task, new \DateTimeImmutable('+1 hour'));
$this->assertNull($this->taskExecutionRepository->findNextScheduled());
}
@@ -182,15 +182,15 @@ public function testFindScheduledSkipped()
* Save a new execution to database.
*
* @param TaskInterface $task
- * @param \DateTime $scheduleTime
+ * @param \DateTimeImmutable $scheduleTime
* @param string $status
*
* @return TaskExecutionInterface
*/
- private function save(TaskInterface $task = null, \DateTime $scheduleTime = null, $status = TaskStatus::PLANNED)
+ private function save(TaskInterface $task = null, \DateTimeImmutable $scheduleTime = null, $status = TaskStatus::PLANNED)
{
if (!$scheduleTime) {
- $scheduleTime = new \DateTime();
+ $scheduleTime = new \DateTimeImmutable();
}
if (!$task) {
diff --git a/tests/Unit/Command/ScheduleSystemTasksCommandTest.php b/tests/Unit/Command/ScheduleSystemTasksCommandTest.php
index 6a53b51..7df9b47 100644
--- a/tests/Unit/Command/ScheduleSystemTasksCommandTest.php
+++ b/tests/Unit/Command/ScheduleSystemTasksCommandTest.php
@@ -158,7 +158,7 @@ public function testExecuteDisable()
$task = $this->prophesize(Task::class);
$task->getInterval()->willReturn(CronExpression::factory('* * * * *'));
- $task->getFirstExecution()->willReturn(new \DateTime());
+ $task->getFirstExecution()->willReturn(new \DateTimeImmutable());
$task->getSystemKey()->willReturn('testing');
$task->setInterval(
@@ -166,7 +166,7 @@ public function testExecuteDisable()
$task->reveal()->getFirstExecution(),
Argument::that(
function ($date) {
- return $date <= new \DateTime('+1 Minute');
+ return $date <= new \DateTimeImmutable('+1 Minute');
}
)
)->shouldBeCalled();
@@ -204,7 +204,7 @@ public function testExecuteUpdate()
$task->getHandlerClass()->willReturn(TestHandler::class);
$task->getWorkload()->willReturn('test');
$task->getInterval()->willReturn(CronExpression::factory('@daily'));
- $task->getFirstExecution()->willReturn(new \DateTime());
+ $task->getFirstExecution()->willReturn(new \DateTimeImmutable());
$task->setInterval(CronExpression::factory('* * * * *'), $task->reveal()->getFirstExecution())->shouldBeCalled(
);
@@ -244,7 +244,7 @@ public function testExecuteUpdateNotSupported()
$task->getHandlerClass()->willReturn('not-existing');
$task->getWorkload()->willReturn('new-workload');
$task->getInterval()->willReturn(CronExpression::factory('@daily'));
- $task->getFirstExecution()->willReturn(new \DateTime());
+ $task->getFirstExecution()->willReturn(new \DateTimeImmutable());
$task->setInterval(Argument::cetera())->shouldNotBeCalled();
@@ -267,7 +267,7 @@ public function testExecuteRemove()
$task = $this->prophesize(Task::class);
$task->getInterval()->willReturn(CronExpression::factory('* * * * *'));
- $task->getFirstExecution()->willReturn(new \DateTime());
+ $task->getFirstExecution()->willReturn(new \DateTimeImmutable());
$task->getSystemKey()->willReturn('testing');
$task->setInterval(
@@ -275,7 +275,7 @@ public function testExecuteRemove()
$task->reveal()->getFirstExecution(),
Argument::that(
function ($date) {
- return $date <= new \DateTime('+1 Minute');
+ return $date <= new \DateTimeImmutable('+1 Minute');
}
)
)->shouldBeCalled();