/** * Pre test set up. */ public function setUp() { // IndividualApplicationSearch mock $this->mockSearchClient = $this->getMockBuilder('Iris\\IndividualApplication\\Search\\IndividualApplicationSearch')->disableOriginalConstructor()->setMethods(array('search'))->getMock(); // ReferencingApplicationFindResults mock $this->mockSearchResults = $this->getMockBuilder('Barbondev\\IRISSDK\\IndividualApplication\\ReferencingApplication\\Model\\ReferencingApplicationFindResults')->setMethods(array('getTotalRecords', 'getRecords'))->getMock(); // Mock ClientRegistry->getAgentContext()->getReferencingApplicationClient()->getReferencingApplication() to return $reference. $this->mockClientRegistry = $this->getMockBuilder('Barbondev\\IRISSDK\\Common\\ClientRegistry\\ClientRegistry')->setMethods(array('getAgentContext'))->getMock(); $mockAgentContext = $this->getMockBuilder('Barbondev\\IRISSDK\\Common\\ClientRegistry\\Context\\AgentContext')->setMethods(array('getReferencingApplicationClient'))->getMock(); $this->mockReferencingApplicationClient = $this->getMockBuilder('Barbondev\\IRISSDK\\IndividualApplication\\ReferencingApplication\\ReferencingApplicationClient')->disableOriginalConstructor()->setMethods(array('getReferencingApplication'))->getMock(); $this->mockClientRegistry->expects($this->any())->method('getAgentContext')->willReturn($mockAgentContext); $mockAgentContext->expects($this->any())->method('getReferencingApplicationClient')->willReturn($this->mockReferencingApplicationClient); }
/** * @test * @covers RrpGuarantorReferenceCreator::getGuarantor * @covers RrpGuarantorReferenceCreator::createGuarantor */ public function guarantor_is_only_retrieved_from_web_service_once_on_consecutive_calls() { $reference = new ReferencingApplication(); $rrpReference = new RentRecoveryPlusReference(); $rrpReference->setParent($reference); // Prepare the first call which will talk to web service $mockResult = new Collection(array(new ReferencingApplication())); $this->mockReferencingApplicationClient->expects($this->once())->method('getReferencingApplicationGuarantors')->willReturn($mockResult); $rrpGuarantorReferenceCreator = new RrpGuarantorReferenceCreator($this->mockClientRegistry, $this->mockDecisionDetailsRetriever); $rrpGuarantorReferenceCreator->getGuarantor($rrpReference); // Second time around, assert that we don't talk to web service, and still return a RentRecoveryPlusReference $this->mockClientRegistry->expects($this->never())->method($this->anything()); $this->assertInstanceOf('RRP\\Model\\RentRecoveryPlusReference', $rrpGuarantorReferenceCreator->getGuarantor($rrpReference)); }