예제 #1
0
 /**
  * Save employee contract
  */
 public function save()
 {
     $empNumber = $this->getValue('empNumber');
     $seqNo = $this->getValue('seqNo');
     $dependent = false;
     if (empty($seqNo)) {
         $q = Doctrine_Query::create()->select('MAX(d.seqno)')->from('EmpDependent d')->where('d.emp_number = ?', $empNumber);
         $result = $q->execute(array(), Doctrine::HYDRATE_ARRAY);
         if (count($result) != 1) {
             throw new PIMServiceException('MAX(seqno) failed.');
         }
         $seqNo = is_null($result[0]['MAX']) ? 1 : $result[0]['MAX'] + 1;
     } else {
         $dependent = Doctrine::getTable('EmpDependent')->find(array('emp_number' => $empNumber, 'seqno' => $seqNo));
         if ($dependent == false) {
             throw new PIMServiceException('Invalid dependent');
         }
     }
     if ($dependent === false) {
         $dependent = new EmpDependent();
         $dependent->emp_number = $empNumber;
         $dependent->seqno = $seqNo;
     }
     $dependent->name = $this->getValue('name');
     $dependent->relationship = $this->getValue('relationship');
     $dependent->relationship_type = $this->getValue('relationshipType');
     $dependent->date_of_birth = $this->getValue('dateOfBirth');
     $dependent->save();
 }
예제 #2
0
 /**
  * Testing getDependents
  */
 public function testGetDependents()
 {
     $empNumber = 111;
     $dependents = array();
     $dependent = new EmpDependent();
     $dependent->setEmpNumber(111);
     $dependent->setSeqno(1);
     $dependent->setName('Anthony Perera');
     $dependent->setRelationshipType('child');
     $dependents[0] = $dependent;
     $dependent = new EmpDependent();
     $dependent->setEmpNumber(111);
     $dependent->setSeqno(2);
     $dependent->setName('Anton Perera');
     $dependent->setRelationshipType('child');
     $dependents[1] = $dependent;
     $mockDao = $this->getMock('EmployeeDao');
     $mockDao->expects($this->once())->method('getDependents')->with($empNumber)->will($this->returnValue($dependents));
     $this->employeeService->setEmployeeDao($mockDao);
     $result = $this->employeeService->getDependents($empNumber);
     $this->assertEquals($dependents, $result);
     $mockDao = $this->getMock('EmployeeDao');
     $mockDao->expects($this->once())->method('getDependents')->with($empNumber)->will($this->throwException(new DaoException()));
     $this->employeeService->setEmployeeDao($mockDao);
     try {
         $result = $this->employeeService->getDependents($empNumber);
         $this->fail("Exception expected");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof PIMServiceException);
     }
 }
예제 #3
0
 /**
  * Testing getDependents
  */
 public function testGetDependents()
 {
     $empNumber = 111;
     $dependents = array();
     $dependent = new EmpDependent();
     $dependent->setEmpNumber(111);
     $dependent->setSeqno(1);
     $dependent->setName('Anthony Perera');
     $dependent->setRelationshipType('child');
     $dependents[0] = $dependent;
     $dependent = new EmpDependent();
     $dependent->setEmpNumber(111);
     $dependent->setSeqno(2);
     $dependent->setName('Anton Perera');
     $dependent->setRelationshipType('child');
     $dependents[1] = $dependent;
     $mockDao = $this->getMock('EmployeeDao');
     $mockDao->expects($this->once())->method('getEmployeeDependents')->with($empNumber)->will($this->returnValue($dependents));
     $this->employeeService->setEmployeeDao($mockDao);
     $result = $this->employeeService->getEmployeeDependents($empNumber);
     $this->assertEquals($dependents, $result);
 }