public function load(ObjectManager $manager)
 {
     $log = StressLog::create($this->getReference('test-user'));
     $log->setLevel(6);
     $manager->persist($log);
     $log = StressLog::create($this->getReference('test-user'));
     $log->setLevel(3);
     $manager->persist($log);
     $manager->flush();
 }
Пример #2
0
 protected function createLog(array $texts, $level = null, \DateTime $time = null)
 {
     if ($level === null) {
         $level = 5;
     }
     if ($time === null) {
         $time = new \DateTime();
     }
     $log = StressLog::create($this->user);
     $log->setFactorTexts($texts);
     $log->setLevel($level);
     $log->setCreatedAt($time);
     return $log;
 }
 /**
  * @Route("/new", name="newLog")
  * @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')")
  */
 public function newAction(Request $request)
 {
     $log = StressLog::create($this->getUser());
     $form = $this->createForm(StressLogForm::class, $log);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($log);
         $em->flush();
         return $this->redirectToRoute('showLog', array('id' => $log->getId()));
     }
     /** @var TagManager $tagManager */
     $tagManager = $this->get('app.tag_manager');
     return $this->render('stresslog/new.html.twig', array('form' => $form->createView(), 'suggestedFactors' => $tagManager->getSuggestions($this->getUser())));
 }
Пример #4
0
 public function testSetFactorsIgnoresDuplicates()
 {
     $this->log->setFactorTexts(array('one'));
     $factor_before = $this->log->getFactors()->first();
     $this->log->setFactorTexts(array('one', 'two'));
     $this->assertCount(2, $this->log->getFactors());
     $factor_after = null;
     foreach ($this->log->getFactors() as $factor) {
         if ($factor->getText() == 'one') {
             $factor_after = $factor;
             break;
         }
     }
     // The original factor object is preserved,
     // instead of being overwritten by a new one with the same value.
     $this->assertSame($factor_before, $factor_after);
 }
 public function testFindByTime()
 {
     /** @var StressLogRepository $repo */
     $repo = $this->em->getRepository('AppBundle:StressLog');
     // Add test fixtures.
     $log1 = StressLog::create($this->user);
     $log1->setLocaltime(new \DateTime('2001-02-03 04:05:06'));
     $this->em->persist($log1);
     $log2 = StressLog::create($this->user);
     $log2->setLocaltime(new \DateTime('2002-02-03 04:05:06'));
     $this->em->persist($log2);
     $this->em->flush();
     $logs = $repo->findFiltered($this->user, array('from' => new \DateTime('2002-01-01 00:00:00'), 'to' => new \DateTime('2002-12-31 00:00:00')));
     $this->assertEquals(1, count($logs));
     $this->assertEquals($logs[0]->getId(), $log2->getId());
     $logs = $repo->findFiltered($this->user, array('to' => new \DateTime('2001-12-31 00:00:00')));
     $this->assertEquals(1, count($logs));
     $this->assertEquals($logs[0]->getId(), $log1->getId());
 }