/**
  * {@inheritdoc}
  */
 public function verify($referenceNumber, $data = array())
 {
     if (!array_key_exists('current_asn', $data)) {
         throw new \LogicException('current_asn key does not exist in $data array');
     }
     // Query IRIS to find a Reference of the given value for this Agent.
     // If IRIS did not return a result, apply an invalid reference number constraint.
     $this->searchCriteria->setReferenceNumber($referenceNumber);
     $result = $this->irisReferenceSearchClient->search($data['current_asn'], $this->searchCriteria, 0, 1);
     if (0 == $result->getTotalRecords()) {
         return false;
     }
     // Believe it or not, IRIS may have returned the wrong result.
     // If the user entered 12, meaning to enter 123, IRIS will return all 12* references.
     // Therefore, double check the reference number from IRIS against the one we searched for.
     $result = current($result->getRecords());
     if ($result->getReferenceNumber() != $referenceNumber) {
         return false;
     }
     // Convert the result into a ReferencingApplication model as it contains data that we will want in the session.
     $referencingApplication = $this->getReferencingApplication($result);
     // Put the reference into the session for other subscribers, to prevent duplicate lookups.
     $this->sessionHolder->putReferenceInSession($referencingApplication, $data['current_asn']);
     return true;
 }
 /**
  * @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'));
 }