/** * Testing getAttachment */ public function testGetAttachment() { $empNumber = 121; $attachments = array(); foreach ($this->testCase['EmployeeAttachment'] as $values) { $attachment = new EmployeeAttachment(); $attachment->fromArray($values); $attachments[] = $attachment; } $attachment = $attachments[0]; $attachmentId = $attachment->getAttachId(); $mockDao = $this->getMock('EmployeeDao'); $mockDao->expects($this->once())->method('getAttachment')->with($empNumber, $attachmentId)->will($this->returnValue($attachment)); $this->employeeService->setEmployeeDao($mockDao); $result = $this->employeeService->getAttachment($empNumber, $attachmentId); $this->assertEquals($attachment, $result); $mockDao = $this->getMock('EmployeeDao'); $mockDao->expects($this->once())->method('getAttachment')->with($empNumber, $attachmentId)->will($this->throwException(new DaoException())); $this->employeeService->setEmployeeDao($mockDao); try { $result = $this->employeeService->getAttachment($empNumber, $attachmentId); $this->fail("Exception expected"); } catch (Exception $e) { } }