Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ jobs:
run: "composer require doctrine/dbal ^${{ matrix.dbal-version }} --no-update"
if: "${{ matrix.dbal-version != 'default' }}"

- name: "Downgrade VarExporter"
run: 'composer require --no-update "symfony/var-exporter:^6.4 || ^7.4"'
if: "${{ matrix.native_lazy == '0' }}"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v3"
with:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"doctrine/persistence": "^3.3.1 || ^4",
"psr/cache": "^1 || ^2 || ^3",
"symfony/console": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"symfony/var-exporter": "^6.3.9 || ^7.0"
"symfony/var-exporter": "^6.3.9 || ^7.0 || ^8.0"
},
"require-dev": {
"doctrine/coding-standard": "^14.0",
Expand All @@ -54,7 +54,7 @@
"phpstan/phpstan-deprecation-rules": "^2",
"phpunit/phpunit": "^10.5.0 || ^11.5",
"psr/log": "^1 || ^2 || ^3",
"symfony/cache": "^5.4 || ^6.2 || ^7.0"
"symfony/cache": "^5.4 || ^6.2 || ^7.0 || ^8.0"
},
"suggest": {
"ext-dom": "Provides support for XSD validation for XML mapping files",
Expand Down
5 changes: 5 additions & 0 deletions src/ORMInvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ public static function proxyDirectoryRequired(): self
return new self('You must configure a proxy directory. See docs for details');
}

public static function lazyGhostUnavailable(): self
{
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.');
}

public static function proxyNamespaceRequired(): self
{
return new self('You must configure a proxy namespace');
Expand Down
8 changes: 7 additions & 1 deletion src/Proxy/ProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use function is_int;
use function is_writable;
use function ltrim;
use function method_exists;
use function mkdir;
use function preg_match_all;
use function random_bytes;
Expand Down Expand Up @@ -161,6 +162,11 @@ public function __construct(
);
}

// @phpstan-ignore function.impossibleType (This method has been removed in Symfony 8)
if (! method_exists(ProxyHelper::class, 'generateLazyGhost')) {
throw ORMInvalidArgumentException::lazyGhostUnavailable();
}

if (! $proxyDir) {
throw ORMInvalidArgumentException::proxyDirectoryRequired();
}
Expand Down Expand Up @@ -464,7 +470,7 @@ private function generateProxyClass(ClassMetadata $class, string|null $fileName,

private function generateUseLazyGhostTrait(ClassMetadata $class): string
{
// @phpstan-ignore staticMethod.deprecated (Because we support Symfony < 7.3)
// @phpstan-ignore staticMethod.notFound (This method has been removed in Symfony 8)
$code = ProxyHelper::generateLazyGhost($class->getReflectionClass());
$code = substr($code, 7 + (int) strpos($code, "\n{"));
$code = substr($code, 0, (int) strpos($code, "\n}"));
Expand Down
3 changes: 3 additions & 0 deletions tests/Tests/ORM/Persisters/BinaryIdPersisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Doctrine\Tests\Models\BinaryPrimaryKey\Category;
use Doctrine\Tests\OrmTestCase;

use const PHP_VERSION_ID;

final class BinaryIdPersisterTest extends OrmTestCase
{
private EntityManager|null $entityManager = null;
Expand Down Expand Up @@ -64,6 +66,7 @@ private function createEntityManager(): EntityManager
}

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

if (! DbalType::hasType(BinaryIdType::NAME)) {
DbalType::addType(BinaryIdType::NAME, BinaryIdType::class);
Expand Down
23 changes: 23 additions & 0 deletions tests/Tests/ORM/Proxy/ProxyFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\EntityNotFoundException;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\ORMInvalidArgumentException;
use Doctrine\ORM\Persisters\Entity\BasicEntityPersister;
use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\Persistence\Mapping\RuntimeReflectionService;
Expand All @@ -22,10 +23,12 @@
use Doctrine\Tests\OrmTestCase;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\Attributes\RequiresMethod;
use PHPUnit\Framework\Attributes\RequiresPhp;
use ReflectionClass;
use ReflectionProperty;
use stdClass;
use Symfony\Component\VarExporter\ProxyHelper;

use function assert;
use function method_exists;
Expand Down Expand Up @@ -247,6 +250,7 @@ public function testProxyFactoryAcceptsNullProxyArgsWhenNativeLazyObjectsAreEnab
}

#[RequiresPhp('8.4')]
#[RequiresMethod(ProxyHelper::class, 'generateLazyGhost')]
#[IgnoreDeprecations]
public function testProxyFactoryTriggersDeprecationWhenNativeLazyObjectsAreDisabled(): void
{
Expand Down Expand Up @@ -276,6 +280,25 @@ public function testProxyFactoryDoesNotTriggerDeprecationWhenNativeLazyObjectsAr
ProxyFactory::AUTOGENERATE_ALWAYS,
);
}

public function testProxyFactoryThrowsIfLazyGhostsAreUnavailable(): void
{
if (method_exists(ProxyHelper::class, 'generateLazyGhost')) {
self::markTestSkipped('This test is not relevant when lazy ghosts are available');
}

$this->emMock->getConfiguration()->enableNativeLazyObjects(false);

$this->expectException(ORMInvalidArgumentException::class);
$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.');

new ProxyFactory(
$this->emMock,
sys_get_temp_dir(),
'Proxies',
ProxyFactory::AUTOGENERATE_ALWAYS,
);
}
}

abstract class AbstractClass
Expand Down