mirror of
https://github.com/danog/postgres.git
synced 2024-11-26 12:04:50 +01:00
Upgrade to PHP 7.1
This commit is contained in:
parent
d88ec8cd35
commit
7e676aaf50
@ -3,16 +3,14 @@ sudo: false
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
- 7.4snapshot
|
||||
- 7.4
|
||||
- nightly
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: 7.4snapshot
|
||||
- php: nightly
|
||||
fast_finish: true
|
||||
|
||||
|
@ -19,16 +19,17 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.0",
|
||||
"php": "^7.1",
|
||||
"amphp/amp": "^2",
|
||||
"amphp/sql": "^1",
|
||||
"amphp/sql-common": "^1"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-pgsql": "*",
|
||||
"ext-pq": "*",
|
||||
"amphp/phpunit-util": "^1.1.2",
|
||||
"phpunit/phpunit": "^7 || ^6",
|
||||
"amphp/php-cs-fixer-config": "dev-master",
|
||||
"phpstan/phpstan": "^0.9"
|
||||
"phpunit/phpunit": "^8 | ^7",
|
||||
"amphp/php-cs-fixer-config": "dev-master"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@ -44,11 +45,6 @@
|
||||
"Amp\\Postgres\\Test\\": "test"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"platform": {
|
||||
"php": "7.0.0"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"check": [
|
||||
"@cs",
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use Amp\CallableMaker;
|
||||
use Amp\CancellationToken;
|
||||
use Amp\Deferred;
|
||||
use Amp\Promise;
|
||||
@ -13,8 +12,6 @@ use function Amp\call;
|
||||
|
||||
abstract class Connection implements Link, Handle
|
||||
{
|
||||
use CallableMaker;
|
||||
|
||||
/** @var Handle */
|
||||
private $handle;
|
||||
|
||||
@ -27,7 +24,7 @@ abstract class Connection implements Link, Handle
|
||||
*
|
||||
* @return Promise<Connection>
|
||||
*/
|
||||
abstract public static function connect(ConnectionConfig $connectionConfig, CancellationToken $token = null): Promise;
|
||||
abstract public static function connect(ConnectionConfig $connectionConfig, ?CancellationToken $token = null): Promise;
|
||||
|
||||
/**
|
||||
* @param Handle $handle
|
||||
@ -63,7 +60,7 @@ abstract class Connection implements Link, Handle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
final public function close()
|
||||
final public function close(): void
|
||||
{
|
||||
if ($this->handle) {
|
||||
$this->handle->close();
|
||||
@ -100,7 +97,7 @@ abstract class Connection implements Link, Handle
|
||||
/**
|
||||
* Releases the transaction lock.
|
||||
*/
|
||||
private function release()
|
||||
private function release(): void
|
||||
{
|
||||
\assert($this->busy !== null);
|
||||
|
||||
@ -209,7 +206,7 @@ abstract class Connection implements Link, Handle
|
||||
|
||||
$this->busy = new Deferred;
|
||||
|
||||
return new ConnectionTransaction($this->handle, $this->callableFromInstanceMethod("release"), $isolation);
|
||||
return new ConnectionTransaction($this->handle, \Closure::fromCallable([$this, 'release']), $isolation);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ final class ConnectionTransaction implements Transaction
|
||||
*
|
||||
* Closes and commits all changes in the transaction.
|
||||
*/
|
||||
public function close()
|
||||
public function close(): void
|
||||
{
|
||||
if ($this->handle) {
|
||||
$this->commit(); // Invokes $this->release callback.
|
||||
|
@ -10,14 +10,14 @@ REGEX;
|
||||
|
||||
/**
|
||||
* @param string $sql SQL statement with named and unnamed placeholders.
|
||||
* @param array $names Array of parameter positions mapped to names and/or indexed locations.
|
||||
* @param array $names [Output] Array of parameter positions mapped to names and/or indexed locations.
|
||||
*
|
||||
* @return string SQL statement with Postgres-style placeholders
|
||||
*/
|
||||
function parseNamedParams(string $sql, array &$names = null): string
|
||||
function parseNamedParams(string $sql, ?array &$names): string
|
||||
{
|
||||
$names = [];
|
||||
return \preg_replace_callback(STATEMENT_PARAM_REGEX, function (array $matches) use (&$names) {
|
||||
return \preg_replace_callback(STATEMENT_PARAM_REGEX, function (array $matches) use (&$names): string {
|
||||
static $index = 0, $unnamed = 0, $numbered = 1;
|
||||
|
||||
if (isset($matches[4])) {
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use Amp\CallableMaker;
|
||||
use Amp\CancellationToken;
|
||||
use Amp\Deferred;
|
||||
use Amp\Failure;
|
||||
@ -13,8 +12,6 @@ use Amp\Sql\ConnectionException;
|
||||
|
||||
final class PgSqlConnection extends Connection implements Link
|
||||
{
|
||||
use CallableMaker;
|
||||
|
||||
/**
|
||||
* @param ConnectionConfig $connectionConfig
|
||||
* @param CancellationToken $token
|
||||
@ -23,7 +20,7 @@ final class PgSqlConnection extends Connection implements Link
|
||||
*
|
||||
* @throws \Error If pecl-ev is used as a loop extension.
|
||||
*/
|
||||
public static function connect(ConnectionConfig $connectionConfig, CancellationToken $token = null): Promise
|
||||
public static function connect(ConnectionConfig $connectionConfig, ?CancellationToken $token = null): Promise
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
if (Loop::get()->getHandle() instanceof \EvLoop) {
|
||||
@ -72,7 +69,7 @@ final class PgSqlConnection extends Connection implements Link
|
||||
$token = $token ?? new NullCancellationToken();
|
||||
$id = $token->subscribe([$deferred, "fail"]);
|
||||
|
||||
$promise->onResolve(function ($exception) use ($connection, $poll, $await, $id, $token) {
|
||||
$promise->onResolve(function ($exception) use ($connection, $poll, $await, $id, $token): void {
|
||||
if ($exception) {
|
||||
\pg_close($connection);
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use Amp\CallableMaker;
|
||||
use Amp\Deferred;
|
||||
use Amp\Emitter;
|
||||
use Amp\Loop;
|
||||
@ -16,8 +15,6 @@ use function Amp\call;
|
||||
|
||||
final class PgSqlHandle implements Handle
|
||||
{
|
||||
use CallableMaker;
|
||||
|
||||
const DIAGNOSTIC_CODES = [
|
||||
\PGSQL_DIAG_SEVERITY => "severity",
|
||||
\PGSQL_DIAG_SQLSTATE => "sqlstate",
|
||||
@ -48,9 +45,6 @@ final class PgSqlHandle implements Handle
|
||||
/** @var \Amp\Emitter[] */
|
||||
private $listeners = [];
|
||||
|
||||
/** @var callable */
|
||||
private $unlisten;
|
||||
|
||||
/** @var Struct[] */
|
||||
private $statements = [];
|
||||
|
||||
@ -74,7 +68,7 @@ final class PgSqlHandle implements Handle
|
||||
$deferred = &$this->deferred;
|
||||
$listeners = &$this->listeners;
|
||||
|
||||
$this->poll = Loop::onReadable($socket, static function ($watcher) use (&$deferred, &$lastUsedAt, &$listeners, &$handle) {
|
||||
$this->poll = Loop::onReadable($socket, static function ($watcher) use (&$deferred, &$lastUsedAt, &$listeners, &$handle): void {
|
||||
$lastUsedAt = \time();
|
||||
|
||||
if (!\pg_consume_input($handle)) {
|
||||
@ -123,7 +117,7 @@ final class PgSqlHandle implements Handle
|
||||
}
|
||||
});
|
||||
|
||||
$this->await = Loop::onWritable($socket, static function ($watcher) use (&$deferred, &$listeners, &$handle) {
|
||||
$this->await = Loop::onWritable($socket, static function ($watcher) use (&$deferred, &$listeners, &$handle): void {
|
||||
$flush = \pg_flush($handle);
|
||||
if ($flush === 0) {
|
||||
return; // Not finished sending data, listen again.
|
||||
@ -147,8 +141,6 @@ final class PgSqlHandle implements Handle
|
||||
|
||||
Loop::disable($this->poll);
|
||||
Loop::disable($this->await);
|
||||
|
||||
$this->unlisten = $this->callableFromInstanceMethod("unlisten");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -162,7 +154,7 @@ final class PgSqlHandle implements Handle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function close()
|
||||
public function close(): void
|
||||
{
|
||||
if ($this->deferred) {
|
||||
$deferred = $this->deferred;
|
||||
@ -175,7 +167,7 @@ final class PgSqlHandle implements Handle
|
||||
$this->handle = null;
|
||||
}
|
||||
|
||||
private function free()
|
||||
private function free(): void
|
||||
{
|
||||
if (\is_resource($this->handle)) {
|
||||
\pg_close($this->handle);
|
||||
@ -458,7 +450,7 @@ final class PgSqlHandle implements Handle
|
||||
}
|
||||
|
||||
Loop::enable($this->poll);
|
||||
return new ConnectionListener($emitter->iterate(), $channel, $this->unlisten);
|
||||
return new ConnectionListener($emitter->iterate(), $channel, \Closure::fromCallable([$this, 'unlisten']));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ final class Pool extends ConnectionPool implements Link
|
||||
int $maxConnections = self::DEFAULT_MAX_CONNECTIONS,
|
||||
int $idleTimeout = self::DEFAULT_IDLE_TIMEOUT,
|
||||
bool $resetConnections = true,
|
||||
Connector $connector = null
|
||||
?Connector $connector = null
|
||||
) {
|
||||
parent::__construct($config, $maxConnections, $idleTimeout, $connector);
|
||||
|
||||
|
@ -35,7 +35,7 @@ final class PooledListener implements Listener
|
||||
return $this->listener->advance();
|
||||
}
|
||||
|
||||
public function getCurrent()
|
||||
public function getCurrent(): Notification
|
||||
{
|
||||
return $this->listener->getCurrent();
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ final class PqConnection extends Connection implements Link
|
||||
*
|
||||
* @return Promise<PqConnection>
|
||||
*/
|
||||
public static function connect(ConnectionConfig $connectionConfig, CancellationToken $token = null): Promise
|
||||
public static function connect(ConnectionConfig $connectionConfig, ?CancellationToken $token = null): Promise
|
||||
{
|
||||
$connectionString = \str_replace(";", " ", $connectionConfig->getConnectionString());
|
||||
|
||||
@ -63,7 +63,7 @@ final class PqConnection extends Connection implements Link
|
||||
$token = $token ?? new NullCancellationToken();
|
||||
$id = $token->subscribe([$deferred, "fail"]);
|
||||
|
||||
$promise->onResolve(function () use ($poll, $await, $id, $token) {
|
||||
$promise->onResolve(function () use ($poll, $await, $id, $token): void {
|
||||
$token->unsubscribe($id);
|
||||
Loop::cancel($poll);
|
||||
Loop::cancel($await);
|
||||
@ -92,7 +92,7 @@ final class PqConnection extends Connection implements Link
|
||||
/**
|
||||
* Sets result sets to be fully buffered in local memory.
|
||||
*/
|
||||
public function shouldBufferResults()
|
||||
public function shouldBufferResults(): void
|
||||
{
|
||||
$this->handle->shouldBufferResults();
|
||||
}
|
||||
@ -100,7 +100,7 @@ final class PqConnection extends Connection implements Link
|
||||
/**
|
||||
* Sets result sets to be streamed from the database server.
|
||||
*/
|
||||
public function shouldNotBufferResults()
|
||||
public function shouldNotBufferResults(): void
|
||||
{
|
||||
$this->handle->shouldNotBufferResults();
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use Amp\CallableMaker;
|
||||
use Amp\Coroutine;
|
||||
use Amp\Deferred;
|
||||
use Amp\Emitter;
|
||||
@ -19,8 +18,6 @@ use function Amp\coroutine;
|
||||
|
||||
final class PqHandle implements Handle
|
||||
{
|
||||
use CallableMaker;
|
||||
|
||||
/** @var \pq\Connection PostgreSQL connection object. */
|
||||
private $handle;
|
||||
|
||||
@ -42,15 +39,6 @@ final class PqHandle implements Handle
|
||||
/** @var Struct[] */
|
||||
private $statements = [];
|
||||
|
||||
/** @var callable */
|
||||
private $fetch;
|
||||
|
||||
/** @var callable */
|
||||
private $unlisten;
|
||||
|
||||
/** @var callable */
|
||||
private $release;
|
||||
|
||||
/** @var int */
|
||||
private $lastUsedAt;
|
||||
|
||||
@ -69,7 +57,7 @@ final class PqHandle implements Handle
|
||||
$deferred = &$this->deferred;
|
||||
$listeners = &$this->listeners;
|
||||
|
||||
$this->poll = Loop::onReadable($this->handle->socket, static function ($watcher) use (&$deferred, &$lastUsedAt, &$listeners, &$handle) {
|
||||
$this->poll = Loop::onReadable($this->handle->socket, static function ($watcher) use (&$deferred, &$lastUsedAt, &$listeners, &$handle): void {
|
||||
$lastUsedAt = \time();
|
||||
|
||||
if ($handle->poll() === pq\Connection::POLLING_FAILED) {
|
||||
@ -103,7 +91,7 @@ final class PqHandle implements Handle
|
||||
}
|
||||
});
|
||||
|
||||
$this->await = Loop::onWritable($this->handle->socket, static function ($watcher) use (&$deferred, &$listeners, &$handle) {
|
||||
$this->await = Loop::onWritable($this->handle->socket, static function ($watcher) use (&$deferred, &$listeners, &$handle): void {
|
||||
try {
|
||||
if (!$handle->flush()) {
|
||||
return; // Not finished sending data, continue polling for writability.
|
||||
@ -126,10 +114,6 @@ final class PqHandle implements Handle
|
||||
|
||||
Loop::disable($this->poll);
|
||||
Loop::disable($this->await);
|
||||
|
||||
$this->fetch = coroutine($this->callableFromInstanceMethod("fetch"));
|
||||
$this->unlisten = $this->callableFromInstanceMethod("unlisten");
|
||||
$this->release = $this->callableFromInstanceMethod("release");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,7 +143,7 @@ final class PqHandle implements Handle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function close()
|
||||
public function close(): void
|
||||
{
|
||||
if ($this->deferred) {
|
||||
$deferred = $this->deferred;
|
||||
@ -172,7 +156,7 @@ final class PqHandle implements Handle
|
||||
$this->free();
|
||||
}
|
||||
|
||||
private function free()
|
||||
private function free(): void
|
||||
{
|
||||
Loop::cancel($this->poll);
|
||||
Loop::cancel($this->await);
|
||||
@ -239,7 +223,11 @@ final class PqHandle implements Handle
|
||||
|
||||
case pq\Result::SINGLE_TUPLE:
|
||||
$this->busy = new Deferred;
|
||||
$result = new PqUnbufferedResultSet($this->fetch, $result, $this->release);
|
||||
$result = new PqUnbufferedResultSet(
|
||||
coroutine(\Closure::fromCallable([$this, 'fetch'])),
|
||||
$result,
|
||||
\Closure::fromCallable([$this, 'release'])
|
||||
);
|
||||
return $result;
|
||||
|
||||
case pq\Result::NONFATAL_ERROR:
|
||||
@ -289,7 +277,7 @@ final class PqHandle implements Handle
|
||||
}
|
||||
}
|
||||
|
||||
private function release()
|
||||
private function release(): void
|
||||
{
|
||||
\assert(
|
||||
$this->busy instanceof Deferred && $this->busy !== $this->deferred,
|
||||
@ -465,7 +453,7 @@ final class PqHandle implements Handle
|
||||
}
|
||||
|
||||
Loop::enable($this->poll);
|
||||
return new ConnectionListener($emitter->iterate(), $channel, $this->unlisten);
|
||||
return new ConnectionListener($emitter->iterate(), $channel, \Closure::fromCallable([$this, 'unlisten']));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ use Amp\Sql\Connector;
|
||||
|
||||
const LOOP_CONNECTOR_IDENTIFIER = Connector::class . "\\Postgres";
|
||||
|
||||
function connector(Connector $connector = null): Connector
|
||||
function connector(?Connector $connector = null): Connector
|
||||
{
|
||||
if ($connector === null) {
|
||||
$connector = Loop::getState(LOOP_CONNECTOR_IDENTIFIER);
|
||||
|
@ -27,7 +27,7 @@ abstract class AbstractLinkTest extends AsyncTestCase
|
||||
/**
|
||||
* @return array Start test data for database.
|
||||
*/
|
||||
public function getData()
|
||||
public function getData(): array
|
||||
{
|
||||
return [
|
||||
['amphp', 'org'],
|
||||
@ -44,7 +44,7 @@ abstract class AbstractLinkTest extends AsyncTestCase
|
||||
*/
|
||||
abstract public function createLink(string $connectionString): Link;
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->connection = $this->createLink('host=localhost user=postgres');
|
||||
@ -100,11 +100,10 @@ abstract class AbstractLinkTest extends AsyncTestCase
|
||||
$this->assertSame(1, $result->getAffectedRowCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Amp\Sql\QueryError
|
||||
*/
|
||||
public function testQueryWithEmptyQuery(): Promise
|
||||
{
|
||||
$this->expectException(QueryError::class);
|
||||
|
||||
/** @var \Amp\Sql\CommandResult $result */
|
||||
return $this->connection->query('');
|
||||
}
|
||||
|
@ -11,12 +11,12 @@ class ArrayParserTest extends TestCase
|
||||
/** @var \Amp\Postgres\Internal\ArrayParser */
|
||||
private $parser;
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->parser = new ArrayParser;
|
||||
}
|
||||
|
||||
public function testSingleDimensionalArray()
|
||||
public function testSingleDimensionalArray(): void
|
||||
{
|
||||
$array = ["one", "two", "three"];
|
||||
$string = '{' . \implode(',', $array) . '}';
|
||||
@ -24,7 +24,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->assertSame($array, $this->parser->parse($string));
|
||||
}
|
||||
|
||||
public function testMultiDimensionalArray()
|
||||
public function testMultiDimensionalArray(): void
|
||||
{
|
||||
$array = ["one", "two", ["three", "four"], "five"];
|
||||
$string = '{one, two, {three, four}, five}';
|
||||
@ -32,7 +32,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->assertSame($array, $this->parser->parse($string));
|
||||
}
|
||||
|
||||
public function testQuotedStrings()
|
||||
public function testQuotedStrings(): void
|
||||
{
|
||||
$array = ["one", "two", ["three", "four"], "five"];
|
||||
$string = '{"one", "two", {"three", "four"}, "five"}';
|
||||
@ -40,7 +40,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->assertSame($array, $this->parser->parse($string));
|
||||
}
|
||||
|
||||
public function testAlternateDelimiter()
|
||||
public function testAlternateDelimiter(): void
|
||||
{
|
||||
$array = ["1,2,3", "3,4,5"];
|
||||
$string = '{1,2,3;3,4,5}';
|
||||
@ -48,7 +48,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->assertSame($array, $this->parser->parse($string, null, ';'));
|
||||
}
|
||||
|
||||
public function testEscapedQuoteDelimiter()
|
||||
public function testEscapedQuoteDelimiter(): void
|
||||
{
|
||||
$array = ['va"lue1', 'value"2'];
|
||||
$string = '{"va\\"lue1", "value\\"2"}';
|
||||
@ -56,7 +56,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->assertSame($array, $this->parser->parse($string, null, ','));
|
||||
}
|
||||
|
||||
public function testNullValue()
|
||||
public function testNullValue(): void
|
||||
{
|
||||
$array = ["one", null, "three"];
|
||||
$string = '{one, NULL, three}';
|
||||
@ -64,7 +64,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->assertSame($array, $this->parser->parse($string));
|
||||
}
|
||||
|
||||
public function testQuotedNullValue()
|
||||
public function testQuotedNullValue(): void
|
||||
{
|
||||
$array = ["one", "NULL", "three"];
|
||||
$string = '{one, "NULL", three}';
|
||||
@ -72,7 +72,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->assertSame($array, $this->parser->parse($string));
|
||||
}
|
||||
|
||||
public function testCast()
|
||||
public function testCast(): void
|
||||
{
|
||||
$array = [1, 2, 3];
|
||||
$string = '{' . \implode(',', $array) . '}';
|
||||
@ -84,7 +84,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->assertSame($array, $this->parser->parse($string, $cast));
|
||||
}
|
||||
|
||||
public function testCastWithNull()
|
||||
public function testCastWithNull(): void
|
||||
{
|
||||
$array = [1, 2, null, 3];
|
||||
$string = '{1,2,NULL,3}';
|
||||
@ -96,7 +96,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->assertSame($array, $this->parser->parse($string, $cast));
|
||||
}
|
||||
|
||||
public function testCastWithMultidimensionalArray()
|
||||
public function testCastWithMultidimensionalArray(): void
|
||||
{
|
||||
$array = [1, 2, [3, 4], [5], 6, 7, [[8, 9], 10]];
|
||||
$string = '{1,2,{3,4},{5},6,7,{{8,9},10}}';
|
||||
@ -108,7 +108,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->assertSame($array, $this->parser->parse($string, $cast));
|
||||
}
|
||||
|
||||
public function testRandomWhitespace()
|
||||
public function testRandomWhitespace(): void
|
||||
{
|
||||
$array = [1, 2, [3, 4], [5], 6, 7, [[8, 9], 10]];
|
||||
$string = " {1, 2, { 3 ,\r 4 },{ 5} \n\t ,6 , 7, { {8,\t 9}, 10} } \n";
|
||||
@ -120,7 +120,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->assertSame($array, $this->parser->parse($string, $cast));
|
||||
}
|
||||
|
||||
public function testEscapedBackslashesInQuotedValue()
|
||||
public function testEscapedBackslashesInQuotedValue(): void
|
||||
{
|
||||
$array = ["test\\ing", "esca\\ped\\"];
|
||||
$string = '{"test\\\\ing", "esca\\\\ped\\\\"}';
|
||||
@ -128,7 +128,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->assertSame($array, $this->parser->parse($string));
|
||||
}
|
||||
|
||||
public function testEmptyArray()
|
||||
public function testEmptyArray(): void
|
||||
{
|
||||
$array = [];
|
||||
$string = '{}';
|
||||
@ -136,7 +136,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->assertSame($array, $this->parser->parse($string));
|
||||
}
|
||||
|
||||
public function testArrayContainingEmptyArray()
|
||||
public function testArrayContainingEmptyArray(): void
|
||||
{
|
||||
$array = [[], [1], []];
|
||||
$string = '{{},{1},{}}';
|
||||
@ -148,7 +148,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->assertSame($array, $this->parser->parse($string, $cast));
|
||||
}
|
||||
|
||||
public function testArrayWithEmptyString()
|
||||
public function testArrayWithEmptyString(): void
|
||||
{
|
||||
$array = [''];
|
||||
$string = '{""}';
|
||||
@ -156,7 +156,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->assertSame($array, $this->parser->parse($string));
|
||||
}
|
||||
|
||||
public function testMalformedNestedArray()
|
||||
public function testMalformedNestedArray(): void
|
||||
{
|
||||
$this->expectException(ParseException::class);
|
||||
$this->expectExceptionMessage('Unexpected end of data');
|
||||
@ -165,7 +165,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->parser->parse($string);
|
||||
}
|
||||
|
||||
public function testEmptyString()
|
||||
public function testEmptyString(): void
|
||||
{
|
||||
$this->expectException(ParseException::class);
|
||||
$this->expectExceptionMessage('Unexpected end of data');
|
||||
@ -174,7 +174,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->parser->parse($string);
|
||||
}
|
||||
|
||||
public function testNoOpeningBracket()
|
||||
public function testNoOpeningBracket(): void
|
||||
{
|
||||
$this->expectException(ParseException::class);
|
||||
$this->expectExceptionMessage('Missing opening bracket');
|
||||
@ -183,7 +183,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->parser->parse($string);
|
||||
}
|
||||
|
||||
public function testNoClosingBracket()
|
||||
public function testNoClosingBracket(): void
|
||||
{
|
||||
$this->expectException(ParseException::class);
|
||||
$this->expectExceptionMessage('Unexpected end of data');
|
||||
@ -192,7 +192,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->parser->parse($string);
|
||||
}
|
||||
|
||||
public function testExtraClosingBracket()
|
||||
public function testExtraClosingBracket(): void
|
||||
{
|
||||
$this->expectException(ParseException::class);
|
||||
$this->expectExceptionMessage('Data left in buffer after parsing');
|
||||
@ -201,7 +201,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->parser->parse($string);
|
||||
}
|
||||
|
||||
public function testTrailingData()
|
||||
public function testTrailingData(): void
|
||||
{
|
||||
$this->expectException(ParseException::class);
|
||||
$this->expectExceptionMessage('Data left in buffer after parsing');
|
||||
@ -210,7 +210,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->parser->parse($string);
|
||||
}
|
||||
|
||||
public function testMissingQuote()
|
||||
public function testMissingQuote(): void
|
||||
{
|
||||
$this->expectException(ParseException::class);
|
||||
$this->expectExceptionMessage('Could not find matching quote in quoted value');
|
||||
@ -219,7 +219,7 @@ class ArrayParserTest extends TestCase
|
||||
$this->parser->parse($string);
|
||||
}
|
||||
|
||||
public function testInvalidDelimiter()
|
||||
public function testInvalidDelimiter(): void
|
||||
{
|
||||
$this->expectException(ParseException::class);
|
||||
$this->expectExceptionMessage('Invalid delimiter');
|
||||
|
@ -7,7 +7,7 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ConnectionConfigTest extends TestCase
|
||||
{
|
||||
public function testBasicSyntax()
|
||||
public function testBasicSyntax(): void
|
||||
{
|
||||
$config = ConnectionConfig::fromString("host=localhost port=5434 user=postgres password=test db=test");
|
||||
|
||||
@ -18,7 +18,7 @@ class ConnectionConfigTest extends TestCase
|
||||
$this->assertSame($config->getDatabase(), "test");
|
||||
}
|
||||
|
||||
public function testAlternativeSyntax()
|
||||
public function testAlternativeSyntax(): void
|
||||
{
|
||||
$config = ConnectionConfig::fromString("host=localhost;port=5434;user=postgres;password=test;db=test");
|
||||
|
||||
@ -29,14 +29,14 @@ class ConnectionConfigTest extends TestCase
|
||||
$this->assertSame($config->getDatabase(), "test");
|
||||
}
|
||||
|
||||
public function testNoHost()
|
||||
public function testNoHost(): void
|
||||
{
|
||||
$this->expectException(\Error::class);
|
||||
$this->expectExceptionMessage("Host must be provided in connection string");
|
||||
$config = ConnectionConfig::fromString("user=postgres");
|
||||
}
|
||||
|
||||
public function testInvalidString()
|
||||
public function testInvalidString(): void
|
||||
{
|
||||
$this->expectException(\Error::class);
|
||||
$this->expectExceptionMessage("Host must be provided in connection string");
|
||||
|
@ -7,7 +7,7 @@ use function Amp\Postgres\encode;
|
||||
|
||||
class EncodeTest extends TestCase
|
||||
{
|
||||
public function testSingleDimensionalStringArray()
|
||||
public function testSingleDimensionalStringArray(): void
|
||||
{
|
||||
$array = ["one", "two", "three"];
|
||||
$string = '{"one","two","three"}';
|
||||
@ -15,7 +15,7 @@ class EncodeTest extends TestCase
|
||||
$this->assertSame($string, encode($array));
|
||||
}
|
||||
|
||||
public function testMultiDimensionalStringArray()
|
||||
public function testMultiDimensionalStringArray(): void
|
||||
{
|
||||
$array = ["one", "two", ["three", "four"], "five"];
|
||||
$string = '{"one","two",{"three","four"},"five"}';
|
||||
@ -23,7 +23,7 @@ class EncodeTest extends TestCase
|
||||
$this->assertSame($string, encode($array));
|
||||
}
|
||||
|
||||
public function testQuotedStrings()
|
||||
public function testQuotedStrings(): void
|
||||
{
|
||||
$array = ["one", "two", ["three", "four"], "five"];
|
||||
$string = '{"one","two",{"three","four"},"five"}';
|
||||
@ -31,7 +31,7 @@ class EncodeTest extends TestCase
|
||||
$this->assertSame($string, encode($array));
|
||||
}
|
||||
|
||||
public function testEscapedQuoteDelimiter()
|
||||
public function testEscapedQuoteDelimiter(): void
|
||||
{
|
||||
$array = ['va"lue1', 'value"2'];
|
||||
$string = '{"va\\"lue1","value\\"2"}';
|
||||
@ -39,7 +39,7 @@ class EncodeTest extends TestCase
|
||||
$this->assertSame($string, encode($array));
|
||||
}
|
||||
|
||||
public function testNullValue()
|
||||
public function testNullValue(): void
|
||||
{
|
||||
$array = ["one", null, "three"];
|
||||
$string = '{"one",NULL,"three"}';
|
||||
@ -47,7 +47,7 @@ class EncodeTest extends TestCase
|
||||
$this->assertSame($string, encode($array));
|
||||
}
|
||||
|
||||
public function testSingleDimensionalIntegerArray()
|
||||
public function testSingleDimensionalIntegerArray(): void
|
||||
{
|
||||
$array = [1, 2, 3];
|
||||
$string = '{' . \implode(',', $array) . '}';
|
||||
@ -55,7 +55,7 @@ class EncodeTest extends TestCase
|
||||
$this->assertSame($string, encode($array));
|
||||
}
|
||||
|
||||
public function testIntegerArrayWithNull()
|
||||
public function testIntegerArrayWithNull(): void
|
||||
{
|
||||
$array = [1, 2, null, 3];
|
||||
$string = '{1,2,NULL,3}';
|
||||
@ -63,7 +63,7 @@ class EncodeTest extends TestCase
|
||||
$this->assertSame($string, encode($array));
|
||||
}
|
||||
|
||||
public function testMultidimensionalIntegerArray()
|
||||
public function testMultidimensionalIntegerArray(): void
|
||||
{
|
||||
$array = [1, 2, [3, 4], [5], 6, 7, [[8, 9], 10]];
|
||||
$string = '{1,2,{3,4},{5},6,7,{{8,9},10}}';
|
||||
@ -71,7 +71,7 @@ class EncodeTest extends TestCase
|
||||
$this->assertSame($string, encode($array));
|
||||
}
|
||||
|
||||
public function testEscapedBackslashesInQuotedValue()
|
||||
public function testEscapedBackslashesInQuotedValue(): void
|
||||
{
|
||||
$array = ["test\\ing", "esca\\ped\\"];
|
||||
$string = '{"test\\\\ing","esca\\\\ped\\\\"}';
|
||||
@ -79,7 +79,7 @@ class EncodeTest extends TestCase
|
||||
$this->assertSame($string, encode($array));
|
||||
}
|
||||
|
||||
public function testObjectWithoutToStringMethod()
|
||||
public function testObjectWithoutToStringMethod(): void
|
||||
{
|
||||
$this->expectException(\Error::class);
|
||||
$this->expectExceptionMessage('Object without a __toString() method in array');
|
||||
|
@ -11,7 +11,7 @@ use function Amp\Postgres\connect;
|
||||
|
||||
class FunctionsTest extends AsyncTestCase
|
||||
{
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -42,7 +42,7 @@ class PgSqlConnectionTest extends AbstractConnectionTest
|
||||
return new PgSqlConnection($this->handle, $socket);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
\pg_get_result($this->handle); // Consume any leftover results from test.
|
||||
\pg_query($this->handle, "ROLLBACK");
|
||||
|
@ -66,7 +66,7 @@ class PgSqlPoolTest extends AbstractLinkTest
|
||||
return $pool;
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
foreach ($this->handles as $handle) {
|
||||
\pg_get_result($handle); // Consume any leftover results from test.
|
||||
|
@ -41,7 +41,7 @@ class PqConnectionTest extends AbstractConnectionTest
|
||||
return new PqConnection($this->handle);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
$this->handle->exec("ROLLBACK");
|
||||
$this->handle->exec("DROP TABLE test");
|
||||
@ -73,26 +73,24 @@ class PqConnectionTest extends AbstractConnectionTest
|
||||
/**
|
||||
* @depends testBufferedResults
|
||||
*/
|
||||
public function testUnbufferedResults()
|
||||
public function testUnbufferedResults(): \Generator
|
||||
{
|
||||
Loop::run(function () {
|
||||
\assert($this->connection instanceof PqConnection);
|
||||
$this->connection->shouldNotBufferResults();
|
||||
\assert($this->connection instanceof PqConnection);
|
||||
$this->connection->shouldNotBufferResults();
|
||||
|
||||
$this->assertFalse($this->connection->isBufferingResults());
|
||||
$this->assertFalse($this->connection->isBufferingResults());
|
||||
|
||||
$result = yield $this->connection->query("SELECT * FROM test");
|
||||
\assert($result instanceof PqUnbufferedResultSet);
|
||||
$result = yield $this->connection->query("SELECT * FROM test");
|
||||
\assert($result instanceof PqUnbufferedResultSet);
|
||||
|
||||
$this->assertSame(2, $result->getFieldCount());
|
||||
$this->assertSame(2, $result->getFieldCount());
|
||||
|
||||
$data = $this->getData();
|
||||
$data = $this->getData();
|
||||
|
||||
for ($i = 0; yield $result->advance(); ++$i) {
|
||||
$row = $result->getCurrent();
|
||||
$this->assertSame($data[$i][0], $row['domain']);
|
||||
$this->assertSame($data[$i][1], $row['tld']);
|
||||
}
|
||||
});
|
||||
for ($i = 0; yield $result->advance(); ++$i) {
|
||||
$row = $result->getCurrent();
|
||||
$this->assertSame($data[$i][0], $row['domain']);
|
||||
$this->assertSame($data[$i][1], $row['tld']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ class PqPoolTest extends AbstractLinkTest
|
||||
return $pool;
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
$this->handles[0]->exec("ROLLBACK");
|
||||
$this->handles[0]->exec("DROP TABLE test");
|
||||
|
Loading…
Reference in New Issue
Block a user