8000 Correctly use doctrine/dbal v3+ · symfony/symfony@4a51827 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a51827

Browse files
Correctly use doctrine/dbal v3+
1 parent e1050c9 commit 4a51827

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

src/Symfony/Component/Lock/Store/PdoStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
use Doctrine\DBAL\Connection;
1515
use Doctrine\DBAL\DBALException;
16+
use Doctrine\DBAL\Driver\Result;
1617
use Doctrine\DBAL\DriverManager;
17-
use Doctrine\DBAL\Result;
1818
use Doctrine\DBAL\Schema\Schema;
1919
use Symfony\Component\Lock\Exception\InvalidArgumentException;
2020
use Symfony\Component\Lock\Exception\InvalidTtlException;

src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Messenger\Tests\Transport\Doctrine;
1313

1414
use Doctrine\DBAL\DBALException;
15+
use Doctrine\DBAL\Driver\Result;
1516
use Doctrine\DBAL\Platforms\AbstractPlatform;
1617
use Doctrine\DBAL\Query\QueryBuilder;
1718
use Doctrine\DBAL\Schema\AbstractSchemaManager;
@@ -29,7 +30,7 @@ public function testGetAMessageWillChangeItsStatus()
2930
$queryBuilder = $this->getQueryBuilderMock();
3031
$driverConnection = $this->getDBALConnectionMock();
3132
$schemaSynchronizer = $this->getSchemaSynchronizerMock();
32-
$stmt = $this->getStatementMock([
33+
$stmt = $this->getResultMock([
3334
'id' => 1,
3435
'body' => '{"message":"Hi"}',
3536
'headers' => json_encode(['type' => DummyMessage::class]),
@@ -63,7 +64,7 @@ public function testGetWithNoPendingMessageWillReturnNull()
6364
$queryBuilder = $this->getQueryBuilderMock();
6465
$driverConnection = $this->getDBALConnectionMock();
6566
$schemaSynchronizer = $this->getSchemaSynchronizerMock();
66-
$stmt = $this->getStatementMock(false);
67+
$stmt = $this->getResultMock(false);
6768

6869
$queryBuilder
6970
->method('getParameters')
@@ -142,12 +143,12 @@ private function getQueryBuilderMock()
142143
return $queryBuilder;
143144
}
144145

145-
private function getStatementMock($expectedResult)
146+
private function getResultMock($expectedResult)
146147
{
147-
$stmt = $this->createMock(Statement::class);
148+
$stmt = $this->createMock(interface_exists(Result::class) ? Result::class : Statement::class);
148149

149150
$stmt->expects($this->once())
150-
->method(method_exists(Statement::class, 'fetchAssociative') ? 'fetchAssociative' : 'fetch')
151+
->method(interface_exists(Result::class) ? 'fetchAssociative' : 'fetch')
151152
->willReturn($expectedResult);
152153

153154
return $stmt;
@@ -262,7 +263,7 @@ public function testFind()
262263
$driverConnection = $this->getDBALConnectionMock();
263264
$schemaSynchronizer = $this->getSchemaSynchronizerMock();
264265
$id = 1;
265-
$stmt = $this->getStatem 8000 entMock([
266+
$stmt = $this->getResultMock([
266267
'id' => $id,
267268
'body' => '{"message":"Hi"}',
268269
'headers' => json_encode(['type' => DummyMessage::class]),
@@ -307,9 +308,9 @@ public function testFindAll()
307308
'headers' => json_encode(['type' => DummyMessage::class]),
308309
];
309310

310-
$stmt = $this->createMock(Statement::class);
311+
$stmt = $this->createMock(interface_exists(Result::class) ? Result::class : Statement::class);
311312
$stmt->expects($this->once())
312-
->method(method_exists(Statement::class, 'fetchAllAssociative') ? 'fetchAllAssociative' : 'fetchAll')
313+
->method(interface_exists(Result::class) ? 'fetchAllAssociative' : 'fetchAll')
313314
->willReturn([$message1, $message2]);
314315

315316
$driverConnection

src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineIntegrationTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Messenger\Tests\Transport\Doctrine;
1313

14+
use Doctrine\DBAL\Driver\Result;
1415
use Doctrine\DBAL\DriverManager;
1516
use Doctrine\DBAL\Version;
1617
use PHPUnit\Framework\TestCase;
@@ -71,7 +72,7 @@ public function testSendWithDelay()
7172
->setParameter(':body', '{"message": "Hi i am delayed"}')
7273
->execute();
7374

74-
$available_at = new \DateTime(method_exists($stmt, 'fetchOne') ? $stmt->fetchOne() : $stmt->fetchColumn());
75+
$available_at = new \DateTime($stmt instanceof Result ? $stmt->fetchOne() : $stmt->fetchColumn());
7576

7677
$now = new \DateTime();
7778
$now->modify('+60 seconds');

src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\DBAL\Connection as DBALConnection;
1515
use Doctrine\DBAL\DBALException;
16+
use Doctrine\DBAL\Driver\Result;
1617
use Doctrine\DBAL\Exception\TableNotFoundException;
1718
use Doctrine\DBAL\Query\QueryBuilder;
1819
use Doctrine\DBAL\Schema\Schema;
@@ -163,7 +164,7 @@ public function get(): ?array
163164
$query->getParameters(),
164165
$query->getParameterTypes()
165166
);
166-
$doctrineEnvelope = method_exists($stmt, 'fetchAssociative') ? $stmt->fetchAssociative() : $stmt->fetch();
167+
$doctrineEnvelope = $stmt instanceof Result ? $stmt->fetchAssociative() : $stmt->fetch();
167168

168169
if (false === $doctrineEnvelope) {
169170
$this->driverConnection->commit();
@@ -251,7 +252,7 @@ public function getMessageCount(): int
251252

252253
$stmt = $this->executeQuery($queryBuilder->getSQL(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());
253254

254-
return method_exists($stmt, 'fetchOne') ? $stmt->fetchOne() : $stmt->fetchColumn();
255+
return $stmt instanceof Result ? $stmt->fetchOne() : $stmt->fetchColumn();
255256
}
256257

257258
public function findAll(int $limit = null): array
@@ -262,7 +263,7 @@ public function findAll(int $limit = null): array
262263
}
263264

264265
$stmt = $this->executeQuery($queryBuilder->getSQL(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes());
265-
$data = method_exists($stmt, 'fetchAllAssociative') ? $stmt->fetchAllAssociative() : $stmt->fetchAll();
266+
$data = $stmt instanceof Result ? $stmt->fetchAllAssociative() : $stmt->fetchAll();
266267

267268
return array_map(function ($doctrineEnvelope) {
268269
return $this->decodeEnvelopeHeaders($doctrineEnvelope);
@@ -275,7 +276,7 @@ public function find($id): ?array
275276
->where('m.id = ?');
276277

277278
$stmt = $this->executeQuery($queryBuilder->getSQL(), [$id]);
278-
$data = method_exists($stmt, 'fetchAssociative') ? $stmt->fetchAssociative() : $stmt->fetch();
279+
$data = $stmt instanceof Result ? $stmt->fetchAssociative() : $stmt->fetch();
279280

280281
return false === $data ? null : $this->decodeEnvelopeHeaders($data);
281282
}

0 commit comments

Comments
 (0)
0