Merge branch '5.0' into 5.1

* 5.0:
  Correctly use doctrine/dbal v3+
  Correctly use doctrine/dbal v3+
This commit is contained in:
Nicolas Grekas 2020-06-09 16:15:34 +02:00
commit 374e23b967
8 changed files with 24 additions and 20 deletions

View File

@ -12,6 +12,7 @@
namespace Symfony\Bridge\Doctrine\Security\RememberMe;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentToken;
@ -63,7 +64,7 @@ class DoctrineTokenProvider implements TokenProviderInterface
$paramValues = ['series' => $series];
$paramTypes = ['series' => \PDO::PARAM_STR];
$stmt = $this->conn->executeQuery($sql, $paramValues, $paramTypes);
$row = method_exists($stmt, 'fetchAssociative') ? $stmt->fetchAssociative() : $stmt->fetch(\PDO::FETCH_ASSOC);
$row = $stmt instanceof Result ? $stmt->fetchAssociative() : $stmt->fetch(\PDO::FETCH_ASSOC);
if ($row) {
return new PersistentToken($row['class'], $row['username'], $series, $row['value'], new \DateTime($row['last_used']));

View File

@ -11,12 +11,13 @@
namespace Symfony\Component\Cache\Adapter;
use Doctrine\DBAL\Abstraction\Result;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Result as DriverResult;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception\TableNotFoundException;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
@ -259,7 +260,7 @@ class PdoAdapter extends AbstractAdapter implements PruneableInterface
$stmt->bindValue(':time', time(), \PDO::PARAM_INT);
$result = $stmt->execute();
return (bool) ($result instanceof Result ? $result->fetchOne() : $stmt->fetchColumn());
return (bool) ($result instanceof DriverResult ? $result->fetchOne() : $stmt->fetchColumn());
}
/**
@ -401,7 +402,7 @@ class PdoAdapter extends AbstractAdapter implements PruneableInterface
}
$result = $stmt->execute();
}
if (null === $driver && !($result instanceof Result ? $result : $stmt)->rowCount()) {
if (null === $driver && !($result instanceof DriverResult ? $result : $stmt)->rowCount()) {
try {
$insertStmt->execute();
} catch (DBALException $e) {

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Cache\Tests\Traits;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Driver\Result;
trait PdoPruneableTrait
{

View File

@ -13,8 +13,8 @@ namespace Symfony\Component\Lock\Store;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\Lock\Exception\InvalidArgumentException;
use Symfony\Component\Lock\Exception\InvalidTtlException;

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
@ -30,7 +31,7 @@ class ConnectionTest extends TestCase
$queryBuilder = $this->getQueryBuilderMock();
$driverConnection = $this->getDBALConnectionMock();
$schemaSynchronizer = $this->getSchemaSynchronizerMock();
$stmt = $this->getStatementMock([
$stmt = $this->getResultMock([
'id' => 1,
'body' => '{"message":"Hi"}',
'headers' => json_encode(['type' => DummyMessage::class]),
@ -64,7 +65,7 @@ class ConnectionTest extends TestCase
$queryBuilder = $this->getQueryBuilderMock();
$driverConnection = $this->getDBALConnectionMock();
$schemaSynchronizer = $this->getSchemaSynchronizerMock();
$stmt = $this->getStatementMock(false);
$stmt = $this->getResultMock(false);
$queryBuilder
->method('getParameters')
@ -143,12 +144,12 @@ class ConnectionTest extends TestCase
return $queryBuilder;
}
private function getStatementMock($expectedResult)
private function getResultMock($expectedResult)
{
$stmt = $this->createMock(Statement::class);
$stmt = $this->createMock(interface_exists(Result::class) ? Result::class : Statement::class);
$stmt->expects($this->once())
->method(method_exists(Statement::class, 'fetchAssociative') ? 'fetchAssociative' : 'fetch')
->method(interface_exists(Result::class) ? 'fetchAssociative' : 'fetch')
->willReturn($expectedResult);
return $stmt;
@ -265,7 +266,7 @@ class ConnectionTest extends TestCase
$driverConnection = $this->getDBALConnectionMock();
$schemaSynchronizer = $this->getSchemaSynchronizerMock();
$id = 1;
$stmt = $this->getStatementMock([
$stmt = $this->getResultMock([
'id' => $id,
'body' => '{"message":"Hi"}',
'headers' => json_encode(['type' => DummyMessage::class]),
@ -310,9 +311,9 @@ class ConnectionTest extends TestCase
'headers' => json_encode(['type' => DummyMessage::class]),
];
$stmt = $this->createMock(Statement::class);
$stmt = $this->createMock(interface_exists(Result::class) ? Result::class : Statement::class);
$stmt->expects($this->once())
->method(method_exists(Statement::class, 'fetchAllAssociative') ? 'fetchAllAssociative' : 'fetchAll')
->method(interface_exists(Result::class) ? 'fetchAllAssociative' : 'fetchAll')
->willReturn([$message1, $message2]);
$driverConnection

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Version;
use PHPUnit\Framework\TestCase;
@ -71,7 +72,7 @@ class DoctrineIntegrationTest extends TestCase
->setParameter(':body', '{"message": "Hi i am delayed"}')
->execute();
$available_at = new \DateTime(method_exists($stmt, 'fetchOne') ? $stmt->fetchOne() : $stmt->fetchColumn());
$available_at = new \DateTime($stmt instanceof Result ? $stmt->fetchOne() : $stmt->fetchColumn());
$now = new \DateTime();
$now->modify('+60 seconds');

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Messenger\Bridge\Doctrine\Transport;
use Doctrine\DBAL\Connection as DBALConnection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Exception\TableNotFoundException;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Schema\Schema;
@ -174,7 +175,7 @@ class Connection implements ResetInterface
$query->getParameters(),
$query->getParameterTypes()
);
$doctrineEnvelope = method_exists($stmt, 'fetchAssociative') ? $stmt->fetchAssociative() : $stmt->fetch();
$doctrineEnvelope = $stmt instanceof Result ? $stmt->fetchAssociative() : $stmt->fetch();
if (false === $doctrineEnvelope) {
$this->driverConnection->commit();
@ -266,7 +267,7 @@ class Connection implements ResetInterface
$stmt = $this->executeQuery($queryBuilder->getSQL(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());
return method_exists($stmt, 'fetchOne') ? $stmt->fetchOne() : $stmt->fetchColumn();
return $stmt instanceof Result ? $stmt->fetchOne() : $stmt->fetchColumn();
}
public function findAll(int $limit = null): array
@ -277,7 +278,7 @@ class Connection implements ResetInterface
}
$stmt = $this->executeQuery($queryBuilder->getSQL(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());
$data = method_exists($stmt, 'fetchAllAssociative') ? $stmt->fetchAllAssociative() : $stmt->fetchAll();
$data = $stmt instanceof Result ? $stmt->fetchAllAssociative() : $stmt->fetchAll();
return array_map(function ($doctrineEnvelope) {
return $this->decodeEnvelopeHeaders($doctrineEnvelope);
@ -290,7 +291,7 @@ class Connection implements ResetInterface
->where('m.id = ?');
$stmt = $this->executeQuery($queryBuilder->getSQL(), [$id]);
$data = method_exists($stmt, 'fetchAssociative') ? $stmt->fetchAssociative() : $stmt->fetch();
$data = $stmt instanceof Result ? $stmt->fetchAssociative() : $stmt->fetch();
return false === $data ? null : $this->decodeEnvelopeHeaders($data);
}

View File

@ -22,7 +22,6 @@
},
"require-dev": {
"doctrine/dbal": "^2.6|^3.0",
"doctrine/orm": "^2.6.3",
"doctrine/persistence": "^1.3",
"symfony/property-access": "^4.4|^5.0",
"symfony/serializer": "^4.4|^5.0"