Пример #1
0
 public function testCdb()
 {
     $w1 = new CdbWriter_PHP('php.cdb');
     $w2 = new CdbWriter_DBA('dba.cdb');
     $data = array();
     for ($i = 0; $i < 1000; $i++) {
         $key = $this->randomString();
         $value = $this->randomString();
         $w1->set($key, $value);
         $w2->set($key, $value);
         if (!isset($data[$key])) {
             $data[$key] = $value;
         }
     }
     $w1->close();
     $w2->close();
     $this->assertEquals(md5_file('dba.cdb'), md5_file('php.cdb'), 'same hash');
     $r1 = new CdbReader_PHP('php.cdb');
     $r2 = new CdbReader_DBA('dba.cdb');
     foreach ($data as $key => $value) {
         if ($key === '') {
             // Known bug
             continue;
         }
         $v1 = $r1->get($key);
         $v2 = $r2->get($key);
         $v1 = $v1 === false ? '(not found)' : $v1;
         $v2 = $v2 === false ? '(not found)' : $v2;
         #cdbAssert( 'Mismatch', $key, $v1, $v2 );
         $this->cdbAssert("PHP error", $key, $v1, $value);
         $this->cdbAssert("DBA error", $key, $v2, $value);
     }
     unlink('dba.cdb');
     unlink('php.cdb');
 }
Пример #2
0
 /**
  * @group medium
  */
 public function testCdb()
 {
     $dir = wfTempDir();
     if (!is_writable($dir)) {
         $this->markTestSkipped("Temp dir isn't writable");
     }
     $phpcdbfile = $this->getNewTempFile();
     $dbacdbfile = $this->getNewTempFile();
     $w1 = new CdbWriter_PHP($phpcdbfile);
     $w2 = new CdbWriter_DBA($dbacdbfile);
     $data = array();
     for ($i = 0; $i < 1000; $i++) {
         $key = $this->randomString();
         $value = $this->randomString();
         $w1->set($key, $value);
         $w2->set($key, $value);
         if (!isset($data[$key])) {
             $data[$key] = $value;
         }
     }
     $w1->close();
     $w2->close();
     $this->assertEquals(md5_file($phpcdbfile), md5_file($dbacdbfile), 'same hash');
     $r1 = new CdbReader_PHP($phpcdbfile);
     $r2 = new CdbReader_DBA($dbacdbfile);
     foreach ($data as $key => $value) {
         if ($key === '') {
             // Known bug
             continue;
         }
         $v1 = $r1->get($key);
         $v2 = $r2->get($key);
         $v1 = $v1 === false ? '(not found)' : $v1;
         $v2 = $v2 === false ? '(not found)' : $v2;
         # cdbAssert( 'Mismatch', $key, $v1, $v2 );
         $this->cdbAssert("PHP error", $key, $v1, $value);
         $this->cdbAssert("DBA error", $key, $v2, $value);
     }
 }