/** * @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)); }
/** * @test */ public function reference_is_put_into_session_when_found() { // Assert that putReferenceInSession is called on a MockSessionHolder $firstReferenceFound = new ReferencingApplicationFindResult(); $firstReferenceFound->setReferenceNumber('HLT999'); $searchCriteria = new SearchIndividualApplicationsCriteria(); $searchCriteria->setReferenceNumber('HLT999'); $this->mockSearchClient->expects($this->once())->method('search')->with('1234567', $searchCriteria)->willReturn($this->mockSearchResults); $this->mockSearchResults->expects($this->once())->method('getTotalRecords')->willReturn(1); $this->mockSearchResults->expects($this->once())->method('getRecords')->willReturn(array($firstReferenceFound, new ReferencingApplicationFindResult())); $this->mockReferencingApplicationClient->expects($this->once())->method('getReferencingApplication')->willReturn(new ReferencingApplication()); $mockSessionHolder = $this->getMockBuilder('RRP\\Utility\\SessionReferenceHolder')->disableOriginalConstructor()->setMethods(array('putReferenceInSession'))->getMock(); $mockSessionHolder->expects($this->once())->method('putReferenceInSession')->with(new ReferencingApplication()); $constraint = new ReferenceBelongsToAgentConstraint($this->mockClientRegistry, $this->mockSearchClient, $searchCriteria, $mockSessionHolder); $constraint->verify('HLT999', array('current_asn' => '1234567')); }