diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index d3130033e1b..8e3a68229fa 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -40,14 +40,14 @@ jobs: - name: "Run PHPUnit" continue-on-error: true - run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --coverage-clover=coverage-no-cache.xml" + run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --coverage-clover=coverage-no-cache.xml --exclude-group performance,locking_functional,dbal2" env: ENABLE_SECOND_LEVEL_CACHE: 0 - name: "Run PHPUnit with Second Level Cache" id: "phpunit-run-slc" continue-on-error: true - run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --exclude-group performance,non-cacheable,locking_functional --coverage-clover=coverage-cache.xml" + run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --exclude-group performance,non-cacheable,locking_functional,dbal2 --coverage-clover=coverage-cache.xml" env: ENABLE_SECOND_LEVEL_CACHE: 1 @@ -93,7 +93,7 @@ jobs: ENABLE_SECOND_LEVEL_CACHE: 0 - name: "Run PHPUnit with Second Level Cache" - run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --exclude-group performance,non-cacheable,locking_functional --coverage-clover=coverage-cache.xml" + run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --exclude-group performance,non-cacheable,locking_functional,dbal3 --coverage-clover=coverage-cache.xml" env: ENABLE_SECOND_LEVEL_CACHE: 1 @@ -261,7 +261,7 @@ jobs: ENABLE_SECOND_LEVEL_CACHE: 0 - name: "Run PHPUnit with Second Level Cache" - run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --exclude-group performance,non-cacheable,locking_functional --coverage-clover=coverage-no-cache.xml" + 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" env: ENABLE_SECOND_LEVEL_CACHE: 1 diff --git a/ci/github/phpunit/mysqli.xml b/ci/github/phpunit/mysqli.xml index 916e43397ff..9a72c0e89fb 100644 --- a/ci/github/phpunit/mysqli.xml +++ b/ci/github/phpunit/mysqli.xml @@ -33,6 +33,7 @@ performance locking_functional + dbal3 diff --git a/ci/github/phpunit/pdo_mysql.xml b/ci/github/phpunit/pdo_mysql.xml index 9469d9af0f8..aca2cce75aa 100644 --- a/ci/github/phpunit/pdo_mysql.xml +++ b/ci/github/phpunit/pdo_mysql.xml @@ -34,6 +34,7 @@ performance locking_functional + dbal3 diff --git a/ci/github/phpunit/pdo_pgsql.xml b/ci/github/phpunit/pdo_pgsql.xml index 570042dbf40..01f2a6f885b 100644 --- a/ci/github/phpunit/pdo_pgsql.xml +++ b/ci/github/phpunit/pdo_pgsql.xml @@ -33,6 +33,7 @@ performance locking_functional + dbal3 diff --git a/ci/github/phpunit/sqlite.xml b/ci/github/phpunit/sqlite.xml index 4639aa3a1b2..ce26cbc4e0e 100644 --- a/ci/github/phpunit/sqlite.xml +++ b/ci/github/phpunit/sqlite.xml @@ -31,6 +31,7 @@ performance locking_functional + dbal3 diff --git a/lib/Doctrine/ORM/Exception/NotSupported.php b/lib/Doctrine/ORM/Exception/NotSupported.php index 852826b6f6e..63fadec7df1 100644 --- a/lib/Doctrine/ORM/Exception/NotSupported.php +++ b/lib/Doctrine/ORM/Exception/NotSupported.php @@ -10,4 +10,9 @@ public static function create(): self { return new self('This behaviour is (currently) not supported by Doctrine 2'); } + + public static function createForDbal3(): self + { + return new self('This behaviour is not supported by doctrine/dbal:3.x, please use doctrine/dbal:2.x instead.'); + } } diff --git a/lib/Doctrine/ORM/Id/UuidGenerator.php b/lib/Doctrine/ORM/Id/UuidGenerator.php index be12ba617a6..3d63a72992b 100644 --- a/lib/Doctrine/ORM/Id/UuidGenerator.php +++ b/lib/Doctrine/ORM/Id/UuidGenerator.php @@ -4,8 +4,12 @@ namespace Doctrine\ORM\Id; +use Doctrine\DBAL\Connection; use Doctrine\Deprecations\Deprecation; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\Exception\NotSupported; + +use function method_exists; /** * Represents an ID generator that uses the database UUID expression @@ -22,10 +26,16 @@ public function __construct() '%s is deprecated with no replacement, use an application-side generator instead', self::class ); + + if (! method_exists(Connection::class, 'getGuidExpression')) { + throw NotSupported::createForDbal3(); + } } /** * {@inheritDoc} + * + * @throws NotSupported */ public function generate(EntityManager $em, $entity) { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ed380a73685..6b01886eaf7 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -28,6 +28,7 @@ performance locking_functional + dbal3 diff --git a/psalm.xml b/psalm.xml index a236e670f74..13a3d928783 100644 --- a/psalm.xml +++ b/psalm.xml @@ -47,5 +47,11 @@ + + + + + + diff --git a/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php b/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php index e7bfbcffdf8..e0b9d33f3bf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php @@ -4,13 +4,16 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\DBAL\Connection; use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; +use Doctrine\ORM\Exception\NotSupported; use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\GeneratedValue; use Doctrine\ORM\Mapping\Id; use Doctrine\Tests\OrmFunctionalTestCase; +use function method_exists; use function strlen; /** @@ -20,18 +23,28 @@ class UUIDGeneratorTest extends OrmFunctionalTestCase { use VerifyDeprecations; + /** + * @group dbal2 + */ public function testItIsDeprecated(): void { $this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/7312'); $this->_em->getClassMetadata(UUIDEntity::class); } + /** + * @group dbal2 + */ public function testGenerateUUID(): void { if ($this->_em->getConnection()->getDatabasePlatform()->getName() !== 'mysql') { self::markTestSkipped('Currently restricted to MySQL platform.'); } + if (! method_exists(Connection::class, 'getGuidExpression')) { + self::markTestSkipped('Test valid for doctrine/dbal:2.x only.'); + } + $this->_schemaTool->createSchema([ $this->_em->getClassMetadata(UUIDEntity::class), ]); @@ -41,6 +54,15 @@ public function testGenerateUUID(): void self::assertNotNull($entity->getId()); self::assertTrue(strlen($entity->getId()) > 0); } + + /** + * @group dbal3 + */ + public function testItCannotBeInitialised(): void + { + $this->expectException(NotSupported::class); + $this->_em->getClassMetadata(UUIDEntity::class); + } } /**