Skip to content
Open
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
24 changes: 24 additions & 0 deletions tests/Tests/ORM/Functional/StandardEntityPersisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\Tests\Models\ECommerce\ECommerceCustomer;
use Doctrine\Tests\Models\ECommerce\ECommerceFeature;
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
use Doctrine\Tests\Models\PersistentObject\PersistentEntity;
use Doctrine\Tests\OrmFunctionalTestCase;

/**
Expand Down Expand Up @@ -107,4 +108,27 @@
// Persisted Product now must have 3 Feature items
self::assertCount(3, $res[0]->getFeatures());
}

public function testPersistLazyGhost(): void

Check failure on line 112 in tests/Tests/ORM/Functional/StandardEntityPersisterTest.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (PHP: 8.4)

Whitespace found at end of line
{
if (PHP_VERSION_ID < 80400) {

Check failure on line 114 in tests/Tests/ORM/Functional/StandardEntityPersisterTest.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (PHP: 8.4)

Constant PHP_VERSION_ID should not be referenced via a fallback global name, but via a use statement.
$this->markTestSkipped('Lazy objects are only available in PHP 8.4+.');
}

$initialized = false;
$reflector = new \ReflectionClass(PersistentEntity::class);

Check failure on line 119 in tests/Tests/ORM/Functional/StandardEntityPersisterTest.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (PHP: 8.4)

Class \ReflectionClass should not be referenced via a fully qualified name, but via a use statement.

Check failure on line 119 in tests/Tests/ORM/Functional/StandardEntityPersisterTest.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (PHP: 8.4)

Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
$lazyGhost = $reflector->newLazyGhost(function (PersistentEntity $object) use (&$initialized) {

Check failure on line 120 in tests/Tests/ORM/Functional/StandardEntityPersisterTest.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (PHP: 8.4)

Closure does not have void return type hint.

Check failure on line 120 in tests/Tests/ORM/Functional/StandardEntityPersisterTest.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (PHP: 8.4)

Closure not using "$this" should be declared static.

Check failure on line 120 in tests/Tests/ORM/Functional/StandardEntityPersisterTest.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (PHP: 8.4)

Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
$initialized = true;
$object->setName('LazyGhostInitialized');
});

self::assertFalse($initialized, 'Lazy ghost should not be initialized before persist.');
$this->_em->persist($lazyGhost);
$this->_em->flush();
self::assertTrue($initialized, 'Lazy ghost should be initialized during flush.');
$this->_em->clear();
$retrievedEntity = $this->_em->find(PersistentEntity::class, $lazyGhost->getId());
self::assertNotNull($retrievedEntity);
self::assertEquals('LazyGhostInitialized', $retrievedEntity->name);
}
}
Loading