2016-12-30 06:21:17 +01:00
|
|
|
<?php
|
2016-09-14 16:27:39 +02:00
|
|
|
|
|
|
|
namespace Amp\Postgres\Test;
|
|
|
|
|
2017-11-06 01:12:12 +01:00
|
|
|
use Amp\Postgres\Link;
|
2017-06-21 05:17:53 +02:00
|
|
|
use Amp\Postgres\PqConnection;
|
2016-09-14 16:27:39 +02:00
|
|
|
|
2016-09-20 07:47:16 +02:00
|
|
|
/**
|
|
|
|
* @requires extension pq
|
|
|
|
*/
|
2017-11-06 01:14:22 +01:00
|
|
|
class PqConnectionTest extends AbstractConnectionTest {
|
2016-09-14 16:27:39 +02:00
|
|
|
/** @var resource PostgreSQL connection resource. */
|
|
|
|
protected $handle;
|
|
|
|
|
2017-11-06 01:12:12 +01:00
|
|
|
public function createLink(string $connectionString): Link {
|
2016-09-14 16:27:39 +02:00
|
|
|
$this->handle = new \pq\Connection($connectionString);
|
2017-11-06 01:37:15 +01:00
|
|
|
$this->handle->nonblocking = true;
|
|
|
|
$this->handle->unbuffered = true;
|
2017-05-16 06:28:37 +02:00
|
|
|
|
2017-05-26 23:26:25 +02:00
|
|
|
$this->handle->exec("DROP TABLE IF EXISTS test");
|
|
|
|
|
2016-09-14 16:27:39 +02:00
|
|
|
$result = $this->handle->exec("CREATE TABLE test (domain VARCHAR(63), tld VARCHAR(63), PRIMARY KEY (domain, tld))");
|
2017-05-16 06:28:37 +02:00
|
|
|
|
2016-09-14 16:27:39 +02:00
|
|
|
if (!$result) {
|
|
|
|
$this->fail('Could not create test table.');
|
|
|
|
}
|
2017-05-16 06:28:37 +02:00
|
|
|
|
2016-09-14 16:27:39 +02:00
|
|
|
foreach ($this->getData() as $row) {
|
|
|
|
$result = $this->handle->execParams("INSERT INTO test VALUES (\$1, \$2)", $row);
|
2017-05-16 06:28:37 +02:00
|
|
|
|
2016-09-14 16:27:39 +02:00
|
|
|
if (!$result) {
|
|
|
|
$this->fail('Could not insert test data.');
|
|
|
|
}
|
|
|
|
}
|
2017-05-16 06:28:37 +02:00
|
|
|
|
2016-09-14 16:27:39 +02:00
|
|
|
return new PqConnection($this->handle);
|
|
|
|
}
|
2017-05-16 06:28:37 +02:00
|
|
|
|
2016-09-14 16:27:39 +02:00
|
|
|
public function tearDown() {
|
|
|
|
$this->handle->exec("ROLLBACK");
|
|
|
|
$this->handle->exec("DROP TABLE test");
|
|
|
|
}
|
|
|
|
}
|