Skip to content

Commit

Permalink
Flush changes to database in TaskController::putAction
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasnatter committed May 31, 2021
1 parent 21dbfff commit d5c62c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Controller/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public function getCountAction(Request $request): Response
{
$entityClass = (string) $request->query->get('entityClass');
$entityId = (string) $request->query->get('entityId');
$locale = $request->query->get('locale');
$locale = (string) $request->query->get('locale');

return $this->handleView($this->view([
'count' => $this->automationTaskRepository->countFutureTasks($entityClass, $entityId, $locale),
Expand Down Expand Up @@ -354,6 +354,7 @@ public function putAction(string $id, Request $request): Response
$task->setSchedule($dateTime);
$task = $this->taskManager->update($task);

$this->entityManager->merge($task);
$this->entityManager->flush();

return $this->handleView($this->view($task));
Expand Down
14 changes: 14 additions & 0 deletions Tests/Functional/Controller/TaskControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,15 @@ public function testPost(
$this->assertArrayHasKey('id', $responseData);
$this->assertEquals($handlerClass, $responseData['handlerClass']);
$this->assertEquals($date->format('Y-m-d\TH:i:s'), $responseData['schedule']);
$this->assertNotNull($responseData['taskId']);
$this->assertEquals($locale, $responseData['locale']);

$taskManager = $this->getContainer()->get('sulu_automation.tasks.manager');
$task = $taskManager->findById($responseData['id']);
$this->assertEquals($handlerClass, $task->getHandlerClass());
$this->assertEqualsWithDelta($date, $task->getSchedule(), 1);
$this->assertNotNull($task->getTaskId());

return $responseData;
}

Expand Down Expand Up @@ -325,7 +332,14 @@ public function testPut(
$this->assertEquals($postData['id'], $responseData['id']);
$this->assertEquals($handlerClass, $responseData['handlerClass']);
$this->assertEquals($date->format('Y-m-d\TH:i:s'), $responseData['schedule']);
$this->assertNotNull($responseData['taskId']);
$this->assertEquals(FirstHandler::TITLE, $responseData['taskName']);

$taskManager = $this->getContainer()->get('sulu_automation.tasks.manager');
$task = $taskManager->findById($postData['id']);
$this->assertEquals($handlerClass, $task->getHandlerClass());
$this->assertEqualsWithDelta($date, $task->getSchedule(), 1);
$this->assertNotNull($task->getTaskId());
}

public function testGet()
Expand Down

0 comments on commit d5c62c0

Please sign in to comment.