예제 #1
0
파일: BackendTest.php 프로젝트: bmdevel/bav
 /**
  * Tests loading all agencies
  * 
  * @dataProvider provideBackends
  */
 public function testAgencies(DataBackend $backend)
 {
     foreach (self::$referenceBackend->getAllBanks() as $referenceBank) {
         $testedBank = $backend->getBank($referenceBank->getBankID());
         $referenceAgencies = array();
         foreach ($referenceBank->getAgencies() as $agency) {
             $referenceAgencies[$agency->getID()] = $agency;
         }
         foreach ($testedBank->getAgencies() as $agency) {
             $referenceAgency = $referenceAgencies[$agency->getID()];
             $this->assertEqualAgency($referenceAgency, $agency);
         }
     }
 }
예제 #2
0
 /**
  * @see DataBackend::update()
  * @throws DataBackendException
  */
 public function update()
 {
     $useTA = false;
     try {
         $fileUtil = new FileUtil();
         $fileBackend = new FileDataBackend(tempnam($fileUtil->getTempDirectory(), 'bav'));
         $fileBackend->install();
         $insertBank = $this->pdo->prepare("INSERT INTO {$this->prefix}bank\n                    (id, validator, mainAgency)\n                    VALUES(:bankID, :validator, :mainAgency)");
         $insertAgency = $this->pdo->prepare("INSERT INTO {$this->prefix}agency\n                    (id, name, postcode, city, shortTerm, pan, bic, bank)\n                    VALUES (:id, :name, :postcode, :city, :shortTerm, :pan, :bic, :bank)");
         try {
             $this->pdo->beginTransaction();
             $useTA = true;
         } catch (\PDOException $e) {
             trigger_error("Your DBS doesn't support transactions. Your data may be corrupted.");
         }
         $this->pdo->exec("DELETE FROM {$this->prefix}agency");
         $this->pdo->exec("DELETE FROM {$this->prefix}bank");
         foreach ($fileBackend->getAllBanks() as $bank) {
             try {
                 $insertBank->execute(array(":bankID" => $bank->getBankID(), ":validator" => $bank->getValidationType(), ":mainAgency" => $bank->getMainAgency()->getID()));
                 $agencies = $bank->getAgencies();
                 $agencies[] = $bank->getMainAgency();
                 foreach ($agencies as $agency) {
                     $insertAgency->execute(array(":id" => $agency->getID(), ":name" => $agency->getName(), ":postcode" => $agency->getPostcode(), ":city" => $agency->getCity(), ":shortTerm" => $agency->getShortTerm(), ":bank" => $bank->getBankID(), ":pan" => $agency->hasPAN() ? $agency->getPAN() : null, ":bic" => $agency->hasBIC() ? $agency->getBIC() : null));
                 }
             } catch (NoMainAgencyException $e) {
                 trigger_error("Skipping bank {$e->getBank()->getBankID()} without any main agency.");
             }
         }
         // Update modification timestamp
         $modificationStmt = $this->pdo->prepare("UPDATE {$this->prefix}meta SET value=:value WHERE name=:name");
         $modificationStmt->execute(array(":name" => MetaData::LASTMODIFIED, ":value" => time()));
         if ($useTA) {
             $this->pdo->commit();
             $useTA = false;
         }
         $fileBackend->uninstall();
     } catch (Exception $e) {
         try {
             if ($useTA) {
                 $this->pdo->rollback();
             }
             throw $e;
         } catch (\PDOException $e2) {
             throw new DataBackendIOException(get_class($e) . ": {$e->getMessage()}\nadditionally: {$e2->getMessage()}");
         }
     }
 }