/**
  * {@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;
 }
 /**
  * Search in HRT.
  *
  * @param int $currentAgentSchemeNumber
  * @param SearchIndividualApplicationsCriteria $criteria
  * @param int $offset
  * @param int $limit
  * @return array Simple array of 'records' containing an array of ReferencingApplicationFindResult and
  *               'totalRecords' containing an integer of all possible records findable with the current criteria
  */
 private function searchInHrt($currentAgentSchemeNumber, SearchIndividualApplicationsCriteria $criteria, $offset, $limit)
 {
     if ($this->debugMode) {
         error_log('--- Search in HRT method invoked ---');
     }
     $records = array();
     $hrtReferenceManager = new \Manager_ReferencingLegacy_Munt();
     $hrtCriteria = array('refno' => $criteria->getReferenceNumber(), 'firstname' => $criteria->getApplicantFirstName(), 'lastname' => $criteria->getApplicantLastName(), 'address' => $criteria->getPropertyAddress(), 'town' => $criteria->getPropertyTown(), 'postcode' => $criteria->getPropertyPostcode(), 'state' => $criteria->getApplicationStatus(), 'type' => $criteria->getProductType());
     $hrtRows = $hrtReferenceManager->searchLegacyReferences($currentAgentSchemeNumber, $hrtCriteria, \Model_Referencing_SearchResult::STARTDATE_DESC, 0, $limit, $offset);
     foreach ($hrtRows->results as $hrtRow) {
         $status = self::APPLICATION_STATUS_INCOMPLETE;
         if ('Complete' == ucfirst(strtolower(trim($hrtRow['resulttx'])))) {
             $status = self::APPLICATION_STATUS_COMPLETE;
         }
         $model = new ReferencingApplicationFindResult();
         $model->setReferenceNumber($hrtRow['RefNo'])->setReferencingApplicationUuId($hrtRow['RefNo'])->setApplicantFirstName($hrtRow['firstname'])->setApplicantLastName($hrtRow['lastname'])->setStreet($hrtRow['address1'])->setCreatedAt($hrtRow['start_time'])->setStatusId($status)->setDataSource(self::DATA_SOURCE_HRT);
         $records[] = $model;
     }
     // Get total records by passing in a zero for both offset and limit
     $hrtRecordCount = $hrtReferenceManager->searchLegacyReferences($currentAgentSchemeNumber, $hrtCriteria, null, 0, 0, 0);
     $totalRecords = (int) $hrtRecordCount->totalNumberOfResults;
     return array('records' => $records, 'totalRecords' => $totalRecords);
 }
 /**
  * @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'));
 }