Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5c4d182

Browse files
author
scyzoryck
committedAug 10, 2021
Throw exception NotSupported Exception for UuidGenerator with doctrine/dbal:3.x.
Generating `getGuidExpression` has been removed in doctrine/dbal:3.x. Partially fixes #8884
1 parent c4456a2 commit 5c4d182

File tree

10 files changed

+52
-4
lines changed

10 files changed

+52
-4
lines changed
 

‎.github/workflows/continuous-integration.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ jobs:
4040

4141
- name: "Run PHPUnit"
4242
continue-on-error: true
43-
run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --coverage-clover=coverage-no-cache.xml"
43+
run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --coverage-clover=coverage-no-cache.xml --exclude-group performance,locking_functional,dbal2"
4444
env:
4545
ENABLE_SECOND_LEVEL_CACHE: 0
4646

4747
- name: "Run PHPUnit with Second Level Cache"
4848
id: "phpunit-run-slc"
4949
continue-on-error: true
50-
run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --exclude-group performance,non-cacheable,locking_functional --coverage-clover=coverage-cache.xml"
50+
run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --exclude-group performance,non-cacheable,locking_functional,dbal2 --coverage-clover=coverage-cache.xml"
5151
env:
5252
ENABLE_SECOND_LEVEL_CACHE: 1
5353

@@ -93,7 +93,7 @@ jobs:
9393
ENABLE_SECOND_LEVEL_CACHE: 0
9494

9595
- name: "Run PHPUnit with Second Level Cache"
96-
run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --exclude-group performance,non-cacheable,locking_functional --coverage-clover=coverage-cache.xml"
96+
run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --exclude-group performance,non-cacheable,locking_functional,dbal3 --coverage-clover=coverage-cache.xml"
9797
env:
9898
ENABLE_SECOND_LEVEL_CACHE: 1
9999

@@ -261,7 +261,7 @@ jobs:
261261
ENABLE_SECOND_LEVEL_CACHE: 0
262262

263263
- name: "Run PHPUnit with Second Level Cache"
264-
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --exclude-group performance,non-cacheable,locking_functional --coverage-clover=coverage-no-cache.xml"
264+
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --exclude-group performance,non-cacheable,locking_functional,dbal3 --coverage-clover=coverage-no-cache.xml"
265265
env:
266266
ENABLE_SECOND_LEVEL_CACHE: 1
267267

‎ci/github/phpunit/mysqli.xml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<exclude>
3434
<group>performance</group>
3535
<group>locking_functional</group>
36+
<group>dbal3</group>
3637
</exclude>
3738
</groups>
3839
</phpunit>

‎ci/github/phpunit/pdo_mysql.xml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<exclude>
3535
<group>performance</group>
3636
<group>locking_functional</group>
37+
<group>dbal3</group>
3738
</exclude>
3839
</groups>
3940
</phpunit>

‎ci/github/phpunit/pdo_pgsql.xml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<exclude>
3434
<group>performance</group>
3535
<group>locking_functional</group>
36+
<group>dbal3</group>
3637
</exclude>
3738
</groups>
3839
</phpunit>

‎ci/github/phpunit/sqlite.xml

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<exclude>
3232
<group>performance</group>
3333
<group>locking_functional</group>
34+
<group>dbal3</group>
3435
</exclude>
3536
</groups>
3637
</phpunit>

‎lib/Doctrine/ORM/Exception/NotSupported.php

+5
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ public static function create(): self
1010
{
1111
return new self('This behaviour is (currently) not supported by Doctrine 2');
1212
}
13+
14+
public static function createForDbal3(): self
15+
{
16+
return new self('This behaviour is not supported by doctrine/dbal:3.x, please use doctrine/dbal:2.x instead.');
17+
}
1318
}

‎lib/Doctrine/ORM/Id/UuidGenerator.php

+10
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
namespace Doctrine\ORM\Id;
66

7+
use Doctrine\DBAL\Connection;
78
use Doctrine\Deprecations\Deprecation;
89
use Doctrine\ORM\EntityManager;
10+
use Doctrine\ORM\Exception\NotSupported;
11+
12+
use function method_exists;
913

1014
/**
1115
* Represents an ID generator that uses the database UUID expression
@@ -22,10 +26,16 @@ public function __construct()
2226
'%s is deprecated with no replacement, use an application-side generator instead',
2327
self::class
2428
);
29+
30+
if (! method_exists(Connection::class, 'getGuidExpression')) {
31+
throw NotSupported::createForDbal3();
32+
}
2533
}
2634

2735
/**
2836
* {@inheritDoc}
37+
*
38+
* @throws NotSupported
2939
*/
3040
public function generate(EntityManager $em, $entity)
3141
{

‎phpunit.xml.dist

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<exclude>
2929
<group>performance</group>
3030
<group>locking_functional</group>
31+
<group>dbal3</group>
3132
</exclude>
3233
</groups>
3334

‎psalm.xml

+6
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,11 @@
4747
<referencedClass name="Doctrine\Common\Cache\XcacheCache"/>
4848
</errorLevel>
4949
</UndefinedClass>
50+
<UndefinedMethod>
51+
<errorLevel type="suppress">
52+
<!-- See https://github.com/doctrine/orm/issues/8884 -->
53+
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getGuidExpression"/>
54+
</errorLevel>
55+
</UndefinedMethod>
5056
</issueHandlers>
5157
</psalm>

‎tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44

55
namespace Doctrine\Tests\ORM\Functional;
66

7+
use Doctrine\DBAL\Connection;
78
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
9+
use Doctrine\ORM\Exception\NotSupported;
810
use Doctrine\ORM\Mapping\Column;
911
use Doctrine\ORM\Mapping\Entity;
1012
use Doctrine\ORM\Mapping\GeneratedValue;
1113
use Doctrine\ORM\Mapping\Id;
1214
use Doctrine\Tests\OrmFunctionalTestCase;
1315

16+
use function method_exists;
1417
use function strlen;
1518

1619
/**
@@ -20,18 +23,28 @@ class UUIDGeneratorTest extends OrmFunctionalTestCase
2023
{
2124
use VerifyDeprecations;
2225

26+
/**
27+
* @group dbal2
28+
*/
2329
public function testItIsDeprecated(): void
2430
{
2531
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/7312');
2632
$this->_em->getClassMetadata(UUIDEntity::class);
2733
}
2834

35+
/**
36+
* @group dbal2
37+
*/
2938
public function testGenerateUUID(): void
3039
{
3140
if ($this->_em->getConnection()->getDatabasePlatform()->getName() !== 'mysql') {
3241
self::markTestSkipped('Currently restricted to MySQL platform.');
3342
}
3443

44+
if (! method_exists(Connection::class, 'getGuidExpression')) {
45+
self::markTestSkipped('Test valid for doctrine/dbal:2.x only.');
46+
}
47+
3548
$this->_schemaTool->createSchema([
3649
$this->_em->getClassMetadata(UUIDEntity::class),
3750
]);
@@ -41,6 +54,15 @@ public function testGenerateUUID(): void
4154
self::assertNotNull($entity->getId());
4255
self::assertTrue(strlen($entity->getId()) > 0);
4356
}
57+
58+
/**
59+
* @group dbal3
60+
*/
61+
public function testItCannotBeInitialised(): void
62+
{
63+
$this->expectException(NotSupported::class);
64+
$this->_em->getClassMetadata(UUIDEntity::class);
65+
}
4466
}
4567

4668
/**

0 commit comments

Comments
 (0)
Please sign in to comment.