/**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $this->client = self::createClient();
     $this->entityManager = self::$kernel->getContainer()->get('doctrine')->getManager();
     /** @var $taskRepo EntityRepository */
     $taskRepo = $this->entityManager->getRepository(Task::class);
     $taskRepo->createQueryBuilder('task')->delete()->getQuery()->execute();
     $today = new \DateTime();
     $this->task1 = Task::create('Task name 1', $today, $today, '#000000');
     $this->entityManager->persist($this->task1);
     $twoDaysAgo = (new \DateTime())->modify('-2 days');
     $this->task2 = Task::create('Task name 2', $twoDaysAgo, $today, '#fafafa');
     $this->entityManager->persist($this->task2);
     $twoInTheFuture = (new \DateTime())->modify('+2 days');
     $this->task3 = Task::create('Task name 3', $twoDaysAgo, $twoInTheFuture, '#ff0000');
     $this->entityManager->persist($this->task3);
     $this->entityManager->flush();
 }
示例#2
0
 protected function processRequest(Request $request, Task &$task)
 {
     $response = new JsonResponse();
     $requestContent = json_decode($request->getContent(), true);
     if (!isset($requestContent['task'])) {
         return $response->setStatusCode(400)->setContent($this->serialize(['error' => ['params' => 'Malformed request, missing parameters']]));
     }
     $taskParams = $requestContent['task'];
     $task->setName($taskParams['name']);
     $task->setStartDate(new \DateTime($taskParams['startDate']));
     $task->setEndDate(new \DateTime($taskParams['endDate']));
     $task->setBandColor($taskParams['bandColor']);
     $errors = $this->get('validator')->validate($task);
     if (count($errors) > 0) {
         return $response->setStatusCode(400)->setContent($this->serialize(['error' => $errors]));
     }
     $this->getDoctrine()->getManager()->persist($task);
     $this->getDoctrine()->getManager()->flush();
     $response->setStatusCode(200);
     return $response->setContent($this->serialize(['task' => $task]));
 }