Handle fetch mode deprecation of DBAL 2.11.
This commit is contained in:
parent
9f52228d86
commit
1385213a9a
@ -226,7 +226,7 @@ trait PdoTrait
|
||||
$stmt->bindValue(':time', time(), \PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
return (bool) $stmt->fetchColumn();
|
||||
return (bool) (method_exists($stmt, 'fetchOne') ? $stmt->fetchOne() : $stmt->fetchColumn());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -203,7 +203,7 @@ class PdoStore implements StoreInterface
|
||||
$stmt->bindValue(':token', $this->getUniqueToken($key));
|
||||
$stmt->execute();
|
||||
|
||||
return (bool) $stmt->fetchColumn();
|
||||
return (bool) (method_exists($stmt, 'fetchOne') ? $stmt->fetchOne() : $stmt->fetchColumn());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,7 +12,8 @@
|
||||
namespace Symfony\Component\Messenger\Tests\Transport\Doctrine;
|
||||
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use Doctrine\DBAL\Driver\Statement;
|
||||
use Doctrine\DBAL\Driver\ResultStatement;
|
||||
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use Doctrine\DBAL\Schema\AbstractSchemaManager;
|
||||
@ -142,11 +143,16 @@ class ConnectionTest extends TestCase
|
||||
return $queryBuilder;
|
||||
}
|
||||
|
||||
private function getStatementMock($expectedResult): Statement
|
||||
private function getStatementMock($expectedResult): ResultStatement
|
||||
{
|
||||
$stmt = $this->createMock(Statement::class);
|
||||
$mockedInterface = interface_exists(ForwardCompatibleResultStatement::class)
|
||||
? ForwardCompatibleResultStatement::class
|
||||
: ResultStatement::class;
|
||||
|
||||
$stmt = $this->createMock($mockedInterface);
|
||||
|
||||
$stmt->expects($this->once())
|
||||
->method('fetch')
|
||||
->method(method_exists($mockedInterface, 'fetchAssociative') ? 'fetchAssociative' : 'fetch')
|
||||
->willReturn($expectedResult);
|
||||
|
||||
return $stmt;
|
||||
@ -306,9 +312,12 @@ class ConnectionTest extends TestCase
|
||||
'headers' => json_encode(['type' => DummyMessage::class]),
|
||||
];
|
||||
|
||||
$stmt = $this->createMock(Statement::class);
|
||||
$mockedInterface = interface_exists(ForwardCompatibleResultStatement::class)
|
||||
? ForwardCompatibleResultStatement::class
|
||||
: ResultStatement::class;
|
||||
$stmt = $this->createMock($mockedInterface);
|
||||
$stmt->expects($this->once())
|
||||
->method('fetchAll')
|
||||
->method(method_exists($mockedInterface, 'fetchAllAssociative') ? 'fetchAllAssociative' : 'fetchAll')
|
||||
->willReturn([$message1, $message2]);
|
||||
|
||||
$driverConnection
|
||||
|
@ -64,15 +64,14 @@ class DoctrineIntegrationTest extends TestCase
|
||||
{
|
||||
$this->connection->send('{"message": "Hi i am delayed"}', ['type' => DummyMessage::class], 600000);
|
||||
|
||||
$available_at = $this->driverConnection->createQueryBuilder()
|
||||
$stmt = $this->driverConnection->createQueryBuilder()
|
||||
->select('m.available_at')
|
||||
->from('messenger_messages', 'm')
|
||||
->where('m.body = :body')
|
||||
->setParameter(':body', '{"message": "Hi i am delayed"}')
|
||||
->execute()
|
||||
->fetchColumn();
|
||||
->execute();
|
||||
|
||||
$available_at = new \DateTime($available_at);
|
||||
$available_at = new \DateTime(method_exists($stmt, 'fetchOne') ? $stmt->fetchOne() : $stmt->fetchColumn());
|
||||
|
||||
$now = new \DateTime();
|
||||
$now->modify('+60 seconds');
|
||||
|
@ -159,11 +159,12 @@ class Connection
|
||||
->setMaxResults(1);
|
||||
|
||||
// use SELECT ... FOR UPDATE to lock table
|
||||
$doctrineEnvelope = $this->executeQuery(
|
||||
$stmt = $this->executeQuery(
|
||||
$query->getSQL().' '.$this->driverConnection->getDatabasePlatform()->getWriteLockSQL(),
|
||||
$query->getParameters(),
|
||||
$query->getParameterTypes()
|
||||
)->fetch();
|
||||
);
|
||||
$doctrineEnvelope = method_exists($stmt, 'fetchAssociative') ? $stmt->fetchAssociative() : $stmt->fetch();
|
||||
|
||||
if (false === $doctrineEnvelope) {
|
||||
$this->driverConnection->commit();
|
||||
@ -249,7 +250,9 @@ class Connection
|
||||
->select('COUNT(m.id) as message_count')
|
||||
->setMaxResults(1);
|
||||
|
||||
return $this->executeQuery($queryBuilder->getSQL(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes())->fetchColumn();
|
||||
$stmt = $this->executeQuery($queryBuilder->getSQL(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());
|
||||
|
||||
return method_exists($stmt, 'fetchOne') ? $stmt->fetchOne() : $stmt->fetchColumn();
|
||||
}
|
||||
|
||||
public function findAll(int $limit = null): array
|
||||
@ -259,7 +262,8 @@ class Connection
|
||||
$queryBuilder->setMaxResults($limit);
|
||||
}
|
||||
|
||||
$data = $this->executeQuery($queryBuilder->getSQL(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes())->fetchAll();
|
||||
$stmt = $this->executeQuery($queryBuilder->getSQL(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());
|
||||
$data = method_exists($stmt, 'fetchAllAssociative') ? $stmt->fetchAllAssociative() : $stmt->fetchAll();
|
||||
|
||||
return array_map(function ($doctrineEnvelope) {
|
||||
return $this->decodeEnvelopeHeaders($doctrineEnvelope);
|
||||
@ -271,9 +275,8 @@ class Connection
|
||||
$queryBuilder = $this->createQueryBuilder()
|
||||
->where('m.id = ?');
|
||||
|
||||
$data = $this->executeQuery($queryBuilder->getSQL(), [
|
||||
$id,
|
||||
])->fetch();
|
||||
$stmt = $this->executeQuery($queryBuilder->getSQL(), [$id]);
|
||||
$data = method_exists($stmt, 'fetchAssociative') ? $stmt->fetchAssociative() : $stmt->fetch();
|
||||
|
||||
return false === $data ? null : $this->decodeEnvelopeHeaders($data);
|
||||
}
|
||||
|
Reference in New Issue
Block a user