/** * @dataProvider employeeProvider */ public function testSerializeEmployee(Employee $employee) { $serializedEmployee = Utils::invokeMethod(new EmployeeController(), 'serializeEmployee', array($employee)); $this->assertInternalType('array', $serializedEmployee); $this->assertEquals($employee->getFirstname(), $serializedEmployee['firstname']); $this->assertEquals($employee->getUser()->getEmail(), $serializedEmployee['email']); $this->assertEquals($employee->getUser()->hasRole('ROLE_TEAM_LEADER'), $serializedEmployee['isTeamLeader']); $this->assertEquals($employee->getUser()->hasRole('ROLE_MANAGER'), $serializedEmployee['isManager']); }
private function resolveSerializedEmployee(Employee $employee, array $serializedEmployee = array()) { $resolver = new OptionsResolver(); $resolver->setDefaults(array('id' => $employee->getId(), 'firstname' => $employee->getFirstname(), 'lastname' => $employee->getLastname(), 'email' => $employee->getUser()->getEmail(), 'isTeamLeader' => $employee->getUser()->hasRole('ROLE_TEAM_LEADER'), 'isManager' => $employee->getUser()->hasRole('ROLE_MANAGER'))); try { return $resolver->resolve($serializedEmployee); } catch (\InvalidArgumentException $e) { throw new BadRequestHttpException($e->getMessage()); } }