Example #1
0
 public function testExecutePersist()
 {
     $fileIn = tempnam(sys_get_temp_dir(), 'PgOidIn');
     file_put_contents($fileIn, 'content');
     $lo = new PgLargeObject($fileIn);
     $this->assertTrue($lo->isNew());
     $this->assertTrue($lo->isChanged());
     $this->assertFalse($lo->isDeleted());
     $this->assertSame($lo->getFilePath(), $fileIn);
     $task = new Persist($this->entityManager->recordManager);
     $task->setObject($lo);
     $this->assertTrue($task->execute($this->db));
     $this->assertFalse($lo->isNew());
     $this->assertFalse($lo->isChanged());
     $this->assertFalse($lo->isDeleted());
     $this->assertNull($lo->getFilePath());
     // the task has been inserted correctly
     $this->assertTrue(is_numeric($lo->getOid()));
     $this->db->query(new PgQuery('BEGIN'));
     $fileOut = tempnam(sys_get_temp_dir(), 'PgOidOut');
     pg_lo_export($this->db->resource->get(), $lo->getOid(), $fileOut);
     $this->db->query(new PgQuery('COMMIT'));
     $this->assertFileEquals($fileIn, $fileOut);
     pg_lo_unlink($this->db->resource->get(), $lo->getOid());
 }
Example #2
0
 /**
  * Get entity PgLargeObject
  * @param PgLargeObject $value
  * @return mixed
  */
 public static function get_PgLargeObject(&$value, Base $entity)
 {
     if ($value instanceof PgLargeObject) {
         return $value->isDeleted() ? null : $value;
     }
     if (is_intish($value)) {
         $value = new Oid($value, $entity->r()->db);
     }
     return !is_null($value) ? new PgLargeObject($value) : null;
 }
Example #3
0
 public function testMd5Database()
 {
     $contents = "spanner";
     $oid = $this->makePgLO($contents);
     $type = new PgLargeObject($oid);
     $this->assertSame($type->md5(), md5($contents));
 }