1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-27 02:52:40 +00:00
Arsse/tests/cases/Db/PostgreSQL/TestDriver.php

61 lines
1.8 KiB
PHP
Raw Normal View History

<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\Db\PostgreSQL;
/**
* @group slow
2018-12-14 00:56:07 +00:00
* @covers \JKingWeb\Arsse\Db\PostgreSQL\Driver<extended>
2021-03-02 16:11:04 +00:00
* @covers \JKingWeb\Arsse\Db\PostgreSQL\Dispatch
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestDriver extends \JKingWeb\Arsse\TestCase\Db\BaseDriver {
use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQL;
protected $create = "CREATE TABLE arsse_test(id bigserial primary key)";
protected $lock = ["BEGIN", "LOCK TABLE arsse_meta IN EXCLUSIVE MODE NOWAIT"];
protected $setVersion = "UPDATE arsse_meta set value = '#' where key = 'schema_version'";
2019-10-16 18:42:43 +00:00
public function tearDown(): void {
try {
$this->drv->exec("ROLLBACK");
} catch (\Throwable $e) {
}
parent::tearDown();
}
2019-10-16 18:42:43 +00:00
public static function tearDownAfterClass(): void {
if (static::$interface) {
static::dbRaze(static::$interface);
@pg_close(static::$interface);
static::$interface = null;
}
parent::tearDownAfterClass();
}
protected function exec($q): bool {
$q = (!is_array($q)) ? [$q] : $q;
foreach ($q as $query) {
set_error_handler(function($code, $msg) {
throw new \Exception($msg);
});
try {
pg_query(static::$interface, $query);
} finally {
restore_error_handler();
}
}
return true;
}
protected function query(string $q) {
if ($r = pg_query_params(static::$interface, $q, [])) {
return pg_fetch_result($r, 0, 0);
} else {
return;
}
}
}