Skip to content

Commit 3d3b5b5

Browse files
authored
Run tests with Symfony 8 (doctrine#12102)
1 parent 7606162 commit 3d3b5b5

File tree

7 files changed

+66
-0
lines changed

7 files changed

+66
-0
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,38 @@ jobs:
4343
- "pdo_sqlite"
4444
deps:
4545
- "highest"
46+
stability:
47+
- "stable"
4648
native_lazy:
4749
- "0"
4850
include:
4951
- php-version: "8.2"
5052
dbal-version: "4@dev"
5153
extension: "pdo_sqlite"
54+
stability: "stable"
5255
native_lazy: "0"
5356
- php-version: "8.2"
5457
dbal-version: "4@dev"
5558
extension: "sqlite3"
59+
stability: "stable"
5660
native_lazy: "0"
5761
- php-version: "8.1"
5862
dbal-version: "default"
5963
deps: "lowest"
6064
extension: "pdo_sqlite"
65+
stability: "stable"
6166
native_lazy: "0"
6267
- php-version: "8.4"
6368
dbal-version: "default"
6469
deps: "highest"
6570
extension: "pdo_sqlite"
71+
stability: "stable"
72+
native_lazy: "1"
73+
- php-version: "8.4"
74+
dbal-version: "default"
75+
deps: "highest"
76+
extension: "sqlite3"
77+
stability: "dev"
6678
native_lazy: "1"
6779

6880
steps:
@@ -79,6 +91,14 @@ jobs:
7991
coverage: "pcov"
8092
ini-values: "zend.assertions=1, apc.enable_cli=1"
8193

94+
- name: "Allow dev dependencies"
95+
run: |
96+
composer config minimum-stability dev
97+
composer remove --no-update --dev phpbench/phpbench phpdocumentor/guides-cli
98+
composer require --no-update symfony/console:^8 symfony/var-exporter:^8 doctrine/dbal:^4.4
99+
composer require --dev --no-update symfony/cache:^8
100+
if: "${{ matrix.stability == 'dev' }}"
101+
82102
- name: "Require specific DBAL version"
83103
run: "composer require doctrine/dbal ^${{ matrix.dbal-version }} --no-update"
84104
if: "${{ matrix.dbal-version != 'default' }}"

phpstan-dbal3.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,8 @@ parameters:
137137
-
138138
message: '~inferType.*never returns~'
139139
path: src/Query/ParameterTypeInferer.php
140+
141+
# Compatibility with Symfony 8
142+
-
143+
message: '#^Call to function method_exists\(\) with ''Symfony\\\\Component\\\\VarExporter\\\\ProxyHelper'' and ''generateLazyGhost'' will always evaluate to true\.$#'
144+
path: src/Proxy/ProxyFactory.php

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ parameters:
5050
-
5151
message: '#Expression on left side of \?\? is not nullable.#'
5252
path: src/Mapping/Driver/AttributeDriver.php
53+
54+
# Compatibility with Symfony 8
55+
-
56+
message: '#^Call to function method_exists\(\) with ''Symfony\\\\Component\\\\VarExporter\\\\ProxyHelper'' and ''generateLazyGhost'' will always evaluate to true\.$#'
57+
path: src/Proxy/ProxyFactory.php

src/ORMInvalidArgumentException.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ public static function proxyDirectoryRequired(): self
160160
return new self('You must configure a proxy directory. See docs for details');
161161
}
162162

163+
public static function lazyGhostUnavailable(): self
164+
{
165+
return new self('Symfony LazyGhost is not available. Please install the "symfony/var-exporter" package version 6.4 or 7 to use this feature or enable PHP 8.4 native lazy objects.');
166+
}
167+
163168
public static function proxyNamespaceRequired(): self
164169
{
165170
return new self('You must configure a proxy namespace');

src/Proxy/ProxyFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use function is_int;
3838
use function is_writable;
3939
use function ltrim;
40+
use function method_exists;
4041
use function mkdir;
4142
use function preg_match_all;
4243
use function random_bytes;
@@ -161,6 +162,10 @@ public function __construct(
161162
);
162163
}
163164

165+
if (! method_exists(ProxyHelper::class, 'generateLazyGhost')) {
166+
throw ORMInvalidArgumentException::lazyGhostUnavailable();
167+
}
168+
164169
if (! $proxyDir) {
165170
throw ORMInvalidArgumentException::proxyDirectoryRequired();
166171
}

tests/Tests/ORM/Persisters/BinaryIdPersisterTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Doctrine\Tests\Models\BinaryPrimaryKey\Category;
1717
use Doctrine\Tests\OrmTestCase;
1818

19+
use const PHP_VERSION_ID;
20+
1921
final class BinaryIdPersisterTest extends OrmTestCase
2022
{
2123
private EntityManager|null $entityManager = null;
@@ -64,6 +66,7 @@ private function createEntityManager(): EntityManager
6466
}
6567

6668
$config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/../../Models/BinaryPrimaryKey'], isDevMode: true);
69+
$config->enableNativeLazyObjects(PHP_VERSION_ID >= 80400);
6770

6871
if (! DbalType::hasType(BinaryIdType::NAME)) {
6972
DbalType::addType(BinaryIdType::NAME, BinaryIdType::class);

tests/Tests/ORM/Proxy/ProxyFactoryTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
1111
use Doctrine\ORM\EntityNotFoundException;
1212
use Doctrine\ORM\Mapping\ClassMetadata;
13+
use Doctrine\ORM\ORMInvalidArgumentException;
1314
use Doctrine\ORM\Persisters\Entity\BasicEntityPersister;
1415
use Doctrine\ORM\Proxy\ProxyFactory;
1516
use Doctrine\Persistence\Mapping\RuntimeReflectionService;
@@ -21,11 +22,13 @@
2122
use Doctrine\Tests\Models\ECommerce\ECommerceFeature;
2223
use Doctrine\Tests\OrmTestCase;
2324
use PHPUnit\Framework\Attributes\Group;
25+
use PHPUnit\Framework\Attributes\RequiresMethod;
2426
use PHPUnit\Framework\Attributes\RequiresPhp;
2527
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
2628
use ReflectionClass;
2729
use ReflectionProperty;
2830
use stdClass;
31+
use Symfony\Component\VarExporter\ProxyHelper;
2932

3033
use function assert;
3134
use function method_exists;
@@ -247,6 +250,7 @@ public function testProxyFactoryAcceptsNullProxyArgsWhenNativeLazyObjectsAreEnab
247250
}
248251

249252
#[RequiresPhp('8.4')]
253+
#[RequiresMethod(ProxyHelper::class, 'generateLazyGhost')]
250254
#[WithoutErrorHandler]
251255
public function testProxyFactoryTriggersDeprecationWhenNativeLazyObjectsAreDisabled(): void
252256
{
@@ -276,6 +280,25 @@ public function testProxyFactoryDoesNotTriggerDeprecationWhenNativeLazyObjectsAr
276280
ProxyFactory::AUTOGENERATE_ALWAYS,
277281
);
278282
}
283+
284+
public function testProxyFactoryThrowsIfLazyGhostsAreUnavailable(): void
285+
{
286+
if (method_exists(ProxyHelper::class, 'generateLazyGhost')) {
287+
self::markTestSkipped('This test is not relevant when lazy ghosts are available');
288+
}
289+
290+
$this->emMock->getConfiguration()->enableNativeLazyObjects(false);
291+
292+
$this->expectException(ORMInvalidArgumentException::class);
293+
$this->expectExceptionMessage('Symfony LazyGhost is not available. Please install the "symfony/var-exporter" package version 6.4 or 7 to use this feature or enable PHP 8.4 native lazy objects.');
294+
295+
new ProxyFactory(
296+
$this->emMock,
297+
sys_get_temp_dir(),
298+
'Proxies',
299+
ProxyFactory::AUTOGENERATE_ALWAYS,
300+
);
301+
}
279302
}
280303

281304
abstract class AbstractClass

0 commit comments

Comments
 (0)