Skip to content

Commit b543f97

Browse files
committed
Run high-deps tests with ORM 3 and DBAL 4
1 parent 7aaa92a commit b543f97

File tree

10 files changed

+93
-37
lines changed

10 files changed

+93
-37
lines changed

src/Symfony/Bridge/Doctrine/Test/TestRepositoryFactory.php

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Test;
1313

1414
use Doctrine\ORM\EntityManagerInterface;
15+
use Doctrine\ORM\EntityRepository;
1516
use Doctrine\ORM\Mapping\ClassMetadata;
1617
use Doctrine\ORM\Repository\RepositoryFactory;
1718
use Doctrine\Persistence\ObjectRepository;
@@ -23,17 +24,14 @@
2324
*/
2425
class TestRepositoryFactory implements RepositoryFactory
2526
{
27+
use GetRepositoryTrait;
28+
2629
/**
2730
* @var ObjectRepository[]
2831
*/
2932
private $repositoryList = [];
3033

31-
/**
32-
* {@inheritdoc}
33-
*
34-
* @return ObjectRepository
35-
*/
36-
public function getRepository(EntityManagerInterface $entityManager, $entityName)
34+
private function doGetRepository(EntityManagerInterface $entityManager, string $entityName): ObjectRepository
3735
{
3836
if (__CLASS__ === static::class) {
3937
trigger_deprecation('symfony/doctrine-bridge', '5.3', '"%s" is deprecated and will be removed in 6.0.', __CLASS__);
@@ -73,3 +71,26 @@ private function getRepositoryHash(EntityManagerInterface $entityManager, string
7371
return $entityManager->getClassMetadata($entityName)->getName().spl_object_hash($entityManager);
7472
}
7573
}
74+
75+
if ((new \ReflectionMethod(RepositoryFactory::class, 'getRepository'))->hasReturnType()) {
76+
/** @internal */
77+
trait GetRepositoryTrait {
78+
public function getRepository(EntityManagerInterface $entityManager, string $entityName): EntityRepository
79+
{
80+
return $this->doGetRepository($entityName, $entityName);
81+
}
82+
}
83+
} else {
84+
/** @internal */
85+
trait GetRepositoryTrait {
86+
/**
87+
* {@inheritdoc}
88+
*
89+
* @return ObjectRepository
90+
*/
91+
public function getRepository(EntityManagerInterface $entityManager, $entityName)
92+
{
93+
return $this->doGetRepository($entityName, $entityName);
94+
}
95+
}
96+
}

src/Symfony/Bridge/Doctrine/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
"doctrine/annotations": "^1.10.4|^2",
4747
"doctrine/collections": "^1.0|^2.0",
4848
"doctrine/data-fixtures": "^1.1",
49-
"doctrine/dbal": "^2.13.1|^3.0",
50-
"doctrine/orm": "^2.7.4",
49+
"doctrine/dbal": "^2.13.1|^3|^4",
50+
"doctrine/orm": "^2.7.4|^3",
5151
"psr/log": "^1|^2|^3"
5252
},
5353
"conflict": {

src/Symfony/Component/Cache/Tests/Fixtures/DriverWrapper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\DBAL\Driver;
1616
use Doctrine\DBAL\Platforms\AbstractPlatform;
1717
use Doctrine\DBAL\Schema\AbstractSchemaManager;
18+
use Doctrine\DBAL\ServerVersionProvider;
1819

1920
class DriverWrapper implements Driver
2021
{
@@ -31,9 +32,9 @@ public function connect(array $params, $username = null, $password = null, array
3132
return $this->driver->connect($params, $username, $password, $driverOptions);
3233
}
3334

34-
public function getDatabasePlatform(): AbstractPlatform
35+
public function getDatabasePlatform(ServerVersionProvider $versionProvider = null): AbstractPlatform
3536
{
36-
return $this->driver->getDatabasePlatform();
37+
return $this->driver->getDatabasePlatform($versionProvider);
3738
}
3839

3940
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager

src/Symfony/Component/Cache/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"require-dev": {
3535
"cache/integration-tests": "dev-master",
3636
"doctrine/cache": "^1.6|^2.0",
37-
"doctrine/dbal": "^2.13.1|^3.0",
37+
"doctrine/dbal": "^2.13.1|^3|^4",
3838
"predis/predis": "^1.1",
3939
"psr/simple-cache": "^1.0|^2.0",
4040
"symfony/config": "^4.4|^5.0|^6.0",

src/Symfony/Component/Lock/Tests/Store/DoctrineDbalStoreTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,22 @@ public function testCreatesTableInTransaction(string $platform)
150150
$store->save($key);
151151
}
152152

153-
public static function providePlatforms()
153+
public static function providePlatforms(): \Generator
154154
{
155155
yield [\Doctrine\DBAL\Platforms\PostgreSQLPlatform::class];
156-
yield [\Doctrine\DBAL\Platforms\PostgreSQL94Platform::class];
156+
157+
// DBAL < 4
158+
if (class_exists(\Doctrine\DBAL\Platforms\PostgreSQL94Platform::class)) {
159+
yield [\Doctrine\DBAL\Platforms\PostgreSQL94Platform::class];
160+
}
161+
157162
yield [\Doctrine\DBAL\Platforms\SqlitePlatform::class];
158163
yield [\Doctrine\DBAL\Platforms\SQLServerPlatform::class];
159-
yield [\Doctrine\DBAL\Platforms\SQLServer2012Platform::class];
164+
165+
// DBAL < 4
166+
if (class_exists(\Doctrine\DBAL\Platforms\SQLServer2012Platform::class)) {
167+
yield [\Doctrine\DBAL\Platforms\SQLServer2012Platform::class];
168+
}
160169
}
161170

162171
public function testTableCreationInTransactionNotSupported()

src/Symfony/Component/Lock/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"symfony/polyfill-php80": "^1.16"
2323
},
2424
"require-dev": {
25-
"doctrine/dbal": "^2.13|^3.0",
25+
"doctrine/dbal": "^2.13|^3|^4",
2626
"predis/predis": "~1.0"
2727
},
2828
"conflict": {

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

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
use Doctrine\DBAL\Platforms\AbstractPlatform;
2020
use Doctrine\DBAL\Platforms\MariaDBPlatform;
2121
use Doctrine\DBAL\Platforms\MySQL57Platform;
22+
use Doctrine\DBAL\Platforms\MySQLPlatform;
2223
use Doctrine\DBAL\Platforms\OraclePlatform;
2324
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
25+
use Doctrine\DBAL\Platforms\SQLServerPlatform;
2426
use Doctrine\DBAL\Query\QueryBuilder;
2527
use Doctrine\DBAL\Result;
2628
use Doctrine\DBAL\Schema\AbstractSchemaManager;
@@ -98,7 +100,7 @@ public function testItThrowsATransportExceptionIfItCannotAcknowledgeMessage()
98100
{
99101
$this->expectException(TransportException::class);
100102
$driverConnection = $this->getDBALConnectionMock();
101-
$driverConnection->method('delete')->willThrowException(new DBALException());
103+
$driverConnection->method('delete')->willThrowException($this->createStub(DBALException::class));
102104

103105
$connection = new Connection([], $driverConnection);
104106
$connection->ack('dummy_id');
@@ -108,7 +110,7 @@ public function testItThrowsATransportExceptionIfItCannotRejectMessage()
108110
{
109111
$this->expectException(TransportException::class);
110112
$driverConnection = $this->getDBALConnectionMock();
111-
$driverConnection->method('delete')->willThrowException(new DBALException());
113+
$driverConnection->method('delete')->willThrowException($this->createStub(DBALException::class));
112114

113115
$connection = new Connection([], $driverConnection);
114116
$connection->reject('dummy_id');
@@ -391,7 +393,7 @@ public function testGeneratedSql(AbstractPlatform $platform, string $expectedSql
391393
public static function providePlatformSql(): iterable
392394
{
393395
yield 'MySQL' => [
394-
new MySQL57Platform(),
396+
class_exists(MySQLPlatform::class) ? new MySQLPlatform() : new MySQL57Platform(),
395397
'SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC LIMIT 1 FOR UPDATE',
396398
];
397399

@@ -403,14 +405,23 @@ public static function providePlatformSql(): iterable
403405
}
404406

405407
yield 'SQL Server' => [
406-
new SQLServer2012Platform(),
408+
class_exists(SQLServerPlatform::class) ? new SQLServerPlatform() : new SQLServer2012Platform(),
407409
'SELECT m.* FROM messenger_messages m WITH (UPDLOCK, ROWLOCK) WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY ',
408410
];
409411

410-
yield 'Oracle' => [
411-
new OraclePlatform(),
412-
'SELECT w.id AS "id", w.body AS "body", w.headers AS "headers", w.queue_name AS "queue_name", w.created_at AS "created_at", w.available_at AS "available_at", w.delivered_at AS "delivered_at" FROM messenger_messages w WHERE w.id IN (SELECT a.id FROM (SELECT m.id FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC) a WHERE ROWNUM <= 1) FOR UPDATE',
413-
];
412+
if (!class_exists(MySQL57Platform::class)) {
413+
// DBAL >= 4
414+
yield 'Oracle' => [
415+
new OraclePlatform(),
416+
'SELECT w.id AS "id", w.body AS "body", w.headers AS "headers", w.queue_name AS "queue_name", w.created_at AS "created_at", w.available_at AS "available_at", w.delivered_at AS "delivered_at" FROM messenger_messages w WHERE w.id IN (SELECT m.id FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC FETCH NEXT 1 ROWS ONLY) FOR UPDATE',
417+
];
418+
} else {
419+
// DBAL < 4
420+
yield 'Oracle' => [
421+
new OraclePlatform(),
422+
'SELECT w.id AS "id", w.body AS "body", w.headers AS "headers", w.queue_name AS "queue_name", w.created_at AS "created_at", w.available_at AS "available_at", w.delivered_at AS "delivered_at" FROM messenger_messages w WHERE w.id IN (SELECT a.id FROM (SELECT m.id FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC) a WHERE ROWNUM <= 1) FOR UPDATE',
423+
];
424+
}
414425
}
415426

416427
public function testConfigureSchema()
@@ -483,7 +494,7 @@ public function testFindAllSqlGenerated(AbstractPlatform $platform, string $expe
483494
public function provideFindAllSqlGeneratedByPlatform(): iterable
484495
{
485496
yield 'MySQL' => [
486-
new MySQL57Platform(),
497+
class_exists(MySQLPlatform::class) ? new MySQLPlatform() : new MySQL57Platform(),
487498
'SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) LIMIT 50',
488499
];
489500

@@ -495,13 +506,22 @@ public function provideFindAllSqlGeneratedByPlatform(): iterable
495506
}
496507

497508
yield 'SQL Server' => [
498-
new SQLServer2012Platform(),
509+
class_exists(SQLServerPlatform::class) ? new SQLServerPlatform() : new SQLServer2012Platform(),
499510
'SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 50 ROWS ONLY',
500511
];
501512

502-
yield 'Oracle' => [
503-
new OraclePlatform(),
504-
'SELECT a.* FROM (SELECT m.id AS "id", m.body AS "body", m.headers AS "headers", m.queue_name AS "queue_name", m.created_at AS "created_at", m.available_at AS "available_at", m.delivered_at AS "delivered_at" FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?)) a WHERE ROWNUM <= 50',
505-
];
513+
if (!class_exists(MySQL57Platform::class)) {
514+
// DBAL >= 4
515+
yield 'Oracle' => [
516+
new OraclePlatform(),
517+
'SELECT m.id AS "id", m.body AS "body", m.headers AS "headers", m.queue_name AS "queue_name", m.created_at AS "created_at", m.available_at AS "available_at", m.delivered_at AS "delivered_at" FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) FETCH NEXT 50 ROWS ONLY',
518+
];
519+
} else {
520+
// DBAL < 4
521+
yield 'Oracle' => [
522+
new OraclePlatform(),
523+
'SELECT a.* FROM (SELECT m.id AS "id", m.body AS "body", m.headers AS "headers", m.queue_name AS "queue_name", m.created_at AS "created_at", m.available_at AS "available_at", m.delivered_at AS "delivered_at" FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?)) a WHERE ROWNUM <= 50',
524+
];
525+
}
506526
}
507527
}

src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineTransportFactoryTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public function testCreateTransport()
4646
$schemaConfig = $this->createMock(SchemaConfig::class);
4747
$platform = $this->createMock(AbstractPlatform::class);
4848
$schemaManager->method('createSchemaConfig')->willReturn($schemaConfig);
49-
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
49+
$driverConnection->method(
50+
method_exists(\Doctrine\DBAL\Connection::class, 'createSchemaManager')
51+
? 'createSchemaManager'
52+
: 'getSchemaManager'
53+
)->willReturn($schemaManager);
5054
$driverConnection->method('getDatabasePlatform')->willReturn($platform);
5155
$registry = $this->createMock(ConnectionRegistry::class);
5256

@@ -70,7 +74,11 @@ public function testCreateTransportNotifyWithPostgreSQLPlatform()
7074
$schemaConfig = $this->createMock(SchemaConfig::class);
7175
$platform = $this->createMock(PostgreSQLPlatform::class);
7276
$schemaManager->method('createSchemaConfig')->willReturn($schemaConfig);
73-
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
77+
$driverConnection->method(
78+
method_exists(\Doctrine\DBAL\Connection::class, 'createSchemaManager')
79+
? 'createSchemaManager'
80+
: 'getSchemaManager'
81+
)->willReturn($schemaManager);
7482
$driverConnection->method('getDatabasePlatform')->willReturn($platform);
7583
$registry = $this->createMock(ConnectionRegistry::class);
7684

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,8 @@ public function get(): ?array
177177

178178
// Append pessimistic write lock to FROM clause if db platform supports it
179179
$sql = $query->getSQL();
180-
if (($fromPart = $query->getQueryPart('from')) &&
181-
($table = $fromPart[0]['table'] ?? null) &&
182-
($alias = $fromPart[0]['alias'] ?? null)
183-
) {
184-
$fromClause = sprintf('%s %s', $table, $alias);
180+
if (preg_match( '/FROM (.+) WHERE/', (string) $sql, $matches)) {
181+
$fromClause = $matches[1];
185182
$sql = str_replace(
186183
sprintf('FROM %s WHERE', $fromClause),
187184
sprintf('FROM %s WHERE', $this->driverConnection->getDatabasePlatform()->appendLockHint($fromClause, LockMode::PESSIMISTIC_WRITE)),

src/Symfony/Component/Messenger/Bridge/Doctrine/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"symfony/service-contracts": "^1.1|^2|^3"
2222
},
2323
"require-dev": {
24-
"doctrine/dbal": "^2.13|^3.0",
24+
"doctrine/dbal": "^2.13|^3|^4",
2525
"doctrine/persistence": "^1.3|^2|^3",
2626
"symfony/property-access": "^4.4|^5.0|^6.0",
2727
"symfony/serializer": "^4.4|^5.0|^6.0"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy