Return promise from StatementPool::prepare(); update tests
This commit is contained in:
parent
04fc107cc0
commit
480e90cba8
@ -27,14 +27,14 @@ abstract class StatementPool implements Statement
|
||||
private $prepare;
|
||||
|
||||
/**
|
||||
* Performs any necessary actions to the statement to prepare it for execution, returning the same or a new
|
||||
* Statement object if necessary.
|
||||
* Performs any necessary actions to the statement to prepare it for execution, returning a promise for the same or
|
||||
* a new Statement object if necessary.
|
||||
*
|
||||
* @param Statement $statement
|
||||
*
|
||||
* @return Statement
|
||||
* @return Promise<Statement>
|
||||
*/
|
||||
abstract protected function prepare(Statement $statement): Statement;
|
||||
abstract protected function prepare(Statement $statement): Promise;
|
||||
|
||||
/**
|
||||
* @param ResultSet $resultSet
|
||||
@ -97,7 +97,8 @@ abstract class StatementPool implements Statement
|
||||
\assert($statement instanceof Statement);
|
||||
|
||||
try {
|
||||
$statement = $this->prepare($statement);
|
||||
$statement = yield $this->prepare($statement);
|
||||
\assert($statement instanceof Statement);
|
||||
$result = yield $statement->execute($params);
|
||||
} catch (\Throwable $exception) {
|
||||
$this->push($statement);
|
||||
|
@ -8,6 +8,7 @@ use Amp\PHPUnit\TestCase;
|
||||
use Amp\Sql\Pool;
|
||||
use Amp\Sql\Statement;
|
||||
use Amp\Sql\StatementPool;
|
||||
use Amp\Success;
|
||||
|
||||
class StatementPoolTest extends TestCase
|
||||
{
|
||||
@ -35,6 +36,11 @@ class StatementPoolTest extends TestCase
|
||||
->setConstructorArgs([$pool, $statement, $this->createCallback(0)])
|
||||
->getMockForAbstractClass();
|
||||
|
||||
$statementPool->method('prepare')
|
||||
->willReturnCallback(function (Statement $statement) {
|
||||
return new Success($statement);
|
||||
});
|
||||
|
||||
$this->assertTrue($statementPool->isAlive());
|
||||
$this->assertSame(\time(), $statementPool->getLastUsedAt());
|
||||
|
||||
@ -71,6 +77,11 @@ class StatementPoolTest extends TestCase
|
||||
->setConstructorArgs([$pool, $statement, $this->createCallback(1)])
|
||||
->getMockForAbstractClass();
|
||||
|
||||
$statementPool->method('prepare')
|
||||
->willReturnCallback(function (Statement $statement) {
|
||||
return new Success($statement);
|
||||
});
|
||||
|
||||
$this->assertTrue($statementPool->isAlive());
|
||||
$this->assertSame(\time(), $statementPool->getLastUsedAt());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user