Skip to content

Commit 831232e

Browse files
committed
Merge branch '3.5.x' into 3.6.x
* 3.5.x: Don't partially mock the AbstractPlatform class (doctrine#12114)
2 parents a774ced + 66e0e92 commit 831232e

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

tests/Tests/ORM/Query/SelectSqlGenerationTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ public function testSupportsMultipleJoins(): void
452452

453453
public function testSupportsTrimFunction(): void
454454
{
455+
$this->entityManager = $this->createTestEntityManagerWithPlatform(new MySQLPlatform());
456+
455457
$this->assertSqlGeneration(
456458
"SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE TRIM(TRAILING ' ' FROM u.name) = 'someone'",
457459
"SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE TRIM(TRAILING ' ' FROM c0_.name) = 'someone'",
@@ -461,6 +463,8 @@ public function testSupportsTrimFunction(): void
461463
#[Group('DDC-2668')]
462464
public function testSupportsTrimLeadingZeroString(): void
463465
{
466+
$this->entityManager = $this->createTestEntityManagerWithPlatform(new MySQLPlatform());
467+
464468
$this->assertSqlGeneration(
465469
"SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE TRIM(TRAILING '0' FROM u.name) != ''",
466470
"SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE TRIM(TRAILING '0' FROM c0_.name) <> ''",
@@ -584,6 +588,8 @@ public function testSupportsNotInExpressionInWherePart(): void
584588
#[Group('DDC-1802')]
585589
public function testSupportsNotInExpressionForModFunction(): void
586590
{
591+
$this->entityManager = $this->createTestEntityManagerWithPlatform(new MySQLPlatform());
592+
587593
$this->assertSqlGeneration(
588594
'SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE MOD(u.id, 5) NOT IN(1,3,4)',
589595
'SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE MOD(c0_.id, 5) NOT IN (1, 3, 4)',
@@ -1925,6 +1931,8 @@ public function testCaseThenParameterArithmeticExpression(): void
19251931
#[Group('DDC-2268')]
19261932
public function testCaseThenFunction(): void
19271933
{
1934+
$this->entityManager = $this->createTestEntityManagerWithPlatform(new PostgreSQLPlatform());
1935+
19281936
$this->assertSqlGeneration(
19291937
'SELECT CASE WHEN LENGTH(u.name) <> 0 THEN CONCAT(u.id, u.name) ELSE u.id END AS name FROM Doctrine\Tests\Models\CMS\CmsUser u',
19301938
'SELECT CASE WHEN LENGTH(c0_.name) <> 0 THEN c0_.id || c0_.name ELSE c0_.id END AS sclr_0 FROM cms_users c0_',

tests/Tests/OrmTestCase.php

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
use Doctrine\DBAL\Driver;
99
use Doctrine\DBAL\Driver\Result;
1010
use Doctrine\DBAL\Platforms\AbstractPlatform;
11-
use Doctrine\DBAL\Schema\AbstractSchemaManager;
12-
use Doctrine\DBAL\Schema\Name\UnquotedIdentifierFolding;
13-
use Doctrine\DBAL\Schema\SchemaConfig;
11+
use Doctrine\DBAL\Platforms\SQLitePlatform;
1412
use Doctrine\ORM\Cache\CacheConfiguration;
1513
use Doctrine\ORM\Cache\CacheFactory;
1614
use Doctrine\ORM\Cache\DefaultCacheFactory;
@@ -22,11 +20,14 @@
2220
use Psr\Cache\CacheItemPoolInterface;
2321
use Symfony\Component\Cache\Adapter\ArrayAdapter;
2422

25-
use function enum_exists;
23+
use function class_exists;
2624
use function method_exists;
2725
use function realpath;
2826
use function sprintf;
2927

28+
// DBAL 3 compatibility
29+
class_exists('Doctrine\\DBAL\\Platforms\\SqlitePlatform');
30+
3031
/**
3132
* Base testcase class for all ORM testcases.
3233
*/
@@ -71,9 +72,7 @@ protected function createAttributeDriver(array $paths = []): AttributeDriver
7172
*/
7273
protected function getTestEntityManager(): EntityManagerMock
7374
{
74-
return $this->buildTestEntityManagerWithPlatform(
75-
$this->createConnectionMock($this->createPlatformMock()),
76-
);
75+
return $this->createTestEntityManagerWithPlatform(new SQLitePlatform());
7776
}
7877

7978
protected function createTestEntityManagerWithConnection(Connection $connection): EntityManagerMock
@@ -153,24 +152,6 @@ private function createConnectionMock(AbstractPlatform $platform): Connection
153152
return $connection;
154153
}
155154

156-
private function createPlatformMock(): AbstractPlatform
157-
{
158-
$schemaManager = $this->createMock(AbstractSchemaManager::class);
159-
$schemaManager->method('createSchemaConfig')
160-
->willReturn(new SchemaConfig());
161-
162-
$platform = $this->getMockBuilder(AbstractPlatform::class)
163-
->setConstructorArgs(enum_exists(UnquotedIdentifierFolding::class) ? [UnquotedIdentifierFolding::UPPER] : [])
164-
->onlyMethods(['supportsIdentityColumns', 'createSchemaManager'])
165-
->getMockForAbstractClass();
166-
$platform->method('supportsIdentityColumns')
167-
->willReturn(true);
168-
$platform->method('createSchemaManager')
169-
->willReturn($schemaManager);
170-
171-
return $platform;
172-
}
173-
174155
private function createDriverMock(AbstractPlatform $platform): Driver
175156
{
176157
$result = $this->createMock(Result::class);

0 commit comments

Comments
 (0)