setName('Test Customer'); $project = new Project(); $project->setName('Test Project'); $project->setCustomer($customer); $activity = new Activity(); $activity->setName('Test'); $activity->setProject($project); $entity = new Timesheet(); $entity->setUser(new User()); $entity->setActivity($activity); return $entity; } public function testValidationEndNotEarlierThanBegin() { $entity = $this->getEntity(); $begin = new \DateTime(); $end = clone $begin; $end = $end->modify('-1 second'); $entity->setBegin($begin); $entity->setEnd($end); $this->assertHasViolationForField($entity, 'end'); // allow same begin and end $entity = $this->getEntity(); $begin = new \DateTime(); $end = clone $begin; $entity->setBegin($begin); $entity->setEnd($end); $this->assertHasViolationForField($entity, []); } public function testDurationMustBeGreatorOrEqualThanZero() { $entity = $this->getEntity(); $begin = new \DateTime(); $end = clone $begin; $entity->setBegin($begin); $entity->setEnd($end); $entity->setDuration(-1); $this->assertHasViolationForField($entity, 'duration'); // allow zero duration $entity = $this->getEntity(); $begin = new \DateTime(); $end = clone $begin; $entity->setBegin($begin); $entity->setEnd($end); $entity->setDuration(0); $this->assertHasViolationForField($entity, []); } }