/** * Test User getters and setters. */ public function testGettersAndSetters() { // Setup. $data = $this->shiftData; $shift = new Shift(); // Set. $shift->setId($data['id']); $shift->setManagerId($data['manager_id']); $shift->setEmployeeId($data['employee_id']); $shift->setBreak($data['break']); $shift->setStartTime($data['start_time']); $shift->setEndTime($data['end_time']); $shift->setCreatedAt($data['created_at']); $shift->setUpdatedAt($data['updated_at']); // Test get. $this->assertEquals($data['id'], $shift->getId()); $this->assertEquals($data['manager_id'], $shift->getManagerId()); $this->assertEquals($data['employee_id'], $shift->getEmployeeId()); $this->assertEquals($data['break'], $shift->getBreak()); $this->assertInstanceOf('DateTime', $shift->getStartTime()); $this->assertEquals($data['start_time'], $shift->getStartTime()); $this->assertInstanceOf('DateTime', $shift->getEndTime()); $this->assertEquals($data['end_time'], $shift->getEndTime()); $this->assertInstanceOf('DateTime', $shift->getCreatedAt()); $this->assertEquals($data['created_at'], $shift->getCreatedAt()); $this->assertInstanceOf('DateTime', $shift->getUpdatedAt()); $this->assertEquals($data['updated_at'], $shift->getUpdatedAt()); }
/** * @param array $data * @return bool * @throws \Doctrine\ORM\ORMException * @throws \Doctrine\ORM\OptimisticLockException * @throws \Doctrine\ORM\TransactionRequiredException */ public function save(array $data) { $response = new StandardResponse(); if (isset($data['id'])) { $shift = $this->em->find('App\\Entity\\Shift', (int) $data['id']); } else { $shift = new Shift(); $shift->setCreatedAt(new \DateTime()); } $shift->setManagerId($data['manager_id']); $shift->setEmployeeId($data['employee_id']); $shift->setBreak($data['break']); $shift->setStartTime($data['start_time']); $shift->setEndTime($data['end_time']); $shift->setUpdatedAt(new \DateTime()); $this->em->persist($shift); try { $response->setSuccess(true); $response->setMessage('You have successfully saved the shift.'); $this->flush(); } catch (\Exception $e) { } return $response->getObjectVars(); }