Skip to content

Commit

Permalink
Test adjustments, missing the setValue/getValue changes now.
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Oct 9, 2024
1 parent 00667e7 commit d6a8298
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 29 deletions.
20 changes: 20 additions & 0 deletions src/Proxy/ProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,26 @@ public function getProxy(string $className, array $identifier): object
$classMetadata->reflFields[$idField]->setRawValueWithoutLazyInitialization($proxy, $value);

Check failure on line 177 in src/Proxy/ProxyFactory.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (default)

PossiblyNullReference

src/Proxy/ProxyFactory.php:177:55: PossiblyNullReference: Cannot call method setRawValueWithoutLazyInitialization on possibly null value (see https://psalm.dev/083)

Check failure on line 177 in src/Proxy/ProxyFactory.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (default)

UndefinedMethod

src/Proxy/ProxyFactory.php:177:55: UndefinedMethod: Method ReflectionProperty::setRawValueWithoutLazyInitialization does not exist (see https://psalm.dev/022)

Check failure on line 177 in src/Proxy/ProxyFactory.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (3.8.2)

PossiblyNullReference

src/Proxy/ProxyFactory.php:177:55: PossiblyNullReference: Cannot call method setRawValueWithoutLazyInitialization on possibly null value (see https://psalm.dev/083)

Check failure on line 177 in src/Proxy/ProxyFactory.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (3.8.2)

UndefinedMethod

src/Proxy/ProxyFactory.php:177:55: UndefinedMethod: Method ReflectionProperty::setRawValueWithoutLazyInitialization does not exist (see https://psalm.dev/022)
}

// todo: this skipLazyInitialization for properites calculation must be moved into ClassMetadata partially
$identifiers = array_flip($classMetadata->getIdentifierFieldNames());
$filter = ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PRIVATE;
$reflector = $classMetadata->getReflectionClass();

while ($reflector) {
foreach ($reflector->getProperties($filter) as $property) {
$name = $property->name;

if ($property->isStatic() || (($classMetadata->hasField($name) || $classMetadata->hasAssociation($name)) && ! isset($identifiers[$name]))) {
continue;
}

$property->skipLazyInitialization($proxy);

Check failure on line 193 in src/Proxy/ProxyFactory.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (default)

UndefinedMethod

src/Proxy/ProxyFactory.php:193:32: UndefinedMethod: Method ReflectionProperty::skipLazyInitialization does not exist (see https://psalm.dev/022)

Check failure on line 193 in src/Proxy/ProxyFactory.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (3.8.2)

UndefinedMethod

src/Proxy/ProxyFactory.php:193:32: UndefinedMethod: Method ReflectionProperty::skipLazyInitialization does not exist (see https://psalm.dev/022)

Check failure on line 193 in src/Proxy/ProxyFactory.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (default, phpstan.neon)

Call to an undefined method ReflectionProperty::skipLazyInitialization().

Check failure on line 193 in src/Proxy/ProxyFactory.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (3.8.2, phpstan-dbal3.neon)

Call to an undefined method ReflectionProperty::skipLazyInitialization().
}

$filter = ReflectionProperty::IS_PRIVATE;
$reflector = $reflector->getParentClass();
}

return $proxy;
}

Expand Down
7 changes: 3 additions & 4 deletions tests/Tests/ORM/Functional/BasicFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public function testSetToOneAssociationWithGetReference(): void
$this->_em->persist($article);
$this->_em->flush();

self::assertFalse($userRef->__isInitialized());
self::assertTrue($this->isUninitializedObject($userRef));

$this->_em->clear();

Expand Down Expand Up @@ -592,7 +592,7 @@ public function testAddToToManyAssociationWithGetReference(): void
$this->_em->persist($user);
$this->_em->flush();

self::assertFalse($groupRef->__isInitialized());
self::assertTrue($this->isUninitializedObject($groupRef));

$this->_em->clear();

Expand Down Expand Up @@ -940,8 +940,7 @@ public function testManyToOneFetchModeQuery(): void
->setParameter(1, $article->id)
->setFetchMode(CmsArticle::class, 'user', ClassMetadata::FETCH_EAGER)
->getSingleResult();
self::assertInstanceOf(InternalProxy::class, $article->user, 'It IS a proxy, ...');
self::assertFalse($this->isUninitializedObject($article->user), '...but its initialized!');
self::assertFalse($this->isUninitializedObject($article->user));
$this->assertQueryCount(2);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ protected function setUp(): void
{
parent::setUp();

if ($this->_em->getConfiguration()->isLazyProxyEnabled()) {
self::markTestSkipped('This test is not applicable when lazy proxy is enabled.');
}

$this->createSchemaForModels(
CmsUser::class,
CmsTag::class,
Expand Down
3 changes: 1 addition & 2 deletions tests/Tests/ORM/Functional/ReferenceProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ public function testCommonPersistenceProxy(): void
assert($entity instanceof ECommerceProduct);
$className = DefaultProxyClassNameResolver::getClass($entity);

self::assertInstanceOf(InternalProxy::class, $entity);
self::assertTrue($this->isUninitializedObject($entity));
self::assertEquals(ECommerceProduct::class, $className);

Expand All @@ -257,7 +256,7 @@ public function testCommonPersistenceProxy(): void
$proxyFileName = $this->_em->getConfiguration()->getProxyDir() . DIRECTORY_SEPARATOR . str_replace('\\', '', $restName) . '.php';
self::assertTrue(file_exists($proxyFileName), 'Proxy file name cannot be found generically.');

$entity->__load();
$this->initializeObject($entity);
self::assertFalse($this->isUninitializedObject($entity));
}
}
5 changes: 0 additions & 5 deletions tests/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Doctrine\ORM\Cache\Exception\CacheException;
use Doctrine\ORM\Cache\QueryCacheEntry;
use Doctrine\ORM\Cache\QueryCacheKey;
use Doctrine\ORM\Proxy\InternalProxy;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\Tests\Models\Cache\Attraction;
Expand Down Expand Up @@ -939,7 +938,6 @@ public function testResolveAssociationCacheEntry(): void
self::assertNotNull($state1->getCountry());
$this->assertQueryCount(1);
self::assertInstanceOf(State::class, $state1);
self::assertInstanceOf(InternalProxy::class, $state1->getCountry());
self::assertEquals($countryName, $state1->getCountry()->getName());
self::assertEquals($stateId, $state1->getId());

Expand All @@ -957,7 +955,6 @@ public function testResolveAssociationCacheEntry(): void
self::assertNotNull($state2->getCountry());
$this->assertQueryCount(0);
self::assertInstanceOf(State::class, $state2);
self::assertInstanceOf(InternalProxy::class, $state2->getCountry());
self::assertEquals($countryName, $state2->getCountry()->getName());
self::assertEquals($stateId, $state2->getId());
}
Expand Down Expand Up @@ -1031,7 +1028,6 @@ public function testResolveToManyAssociationCacheEntry(): void

$this->assertQueryCount(1);
self::assertInstanceOf(State::class, $state1);
self::assertInstanceOf(InternalProxy::class, $state1->getCountry());
self::assertInstanceOf(City::class, $state1->getCities()->get(0));
self::assertInstanceOf(State::class, $state1->getCities()->get(0)->getState());
self::assertSame($state1, $state1->getCities()->get(0)->getState());
Expand All @@ -1048,7 +1044,6 @@ public function testResolveToManyAssociationCacheEntry(): void

$this->assertQueryCount(0);
self::assertInstanceOf(State::class, $state2);
self::assertInstanceOf(InternalProxy::class, $state2->getCountry());
self::assertInstanceOf(City::class, $state2->getCities()->get(0));
self::assertInstanceOf(State::class, $state2->getCities()->get(0)->getState());
self::assertSame($state2, $state2->getCities()->get(0)->getState());
Expand Down
8 changes: 0 additions & 8 deletions tests/Tests/ORM/Functional/SecondLevelCacheRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ public function testRepositoryCacheFindAllToOneAssociation(): void
self::assertInstanceOf(State::class, $entities[1]);
self::assertInstanceOf(Country::class, $entities[0]->getCountry());
self::assertInstanceOf(Country::class, $entities[0]->getCountry());
self::assertInstanceOf(InternalProxy::class, $entities[0]->getCountry());
self::assertInstanceOf(InternalProxy::class, $entities[1]->getCountry());

// load from cache
$this->getQueryLog()->reset()->enable();
Expand All @@ -212,8 +210,6 @@ public function testRepositoryCacheFindAllToOneAssociation(): void
self::assertInstanceOf(State::class, $entities[1]);
self::assertInstanceOf(Country::class, $entities[0]->getCountry());
self::assertInstanceOf(Country::class, $entities[1]->getCountry());
self::assertInstanceOf(InternalProxy::class, $entities[0]->getCountry());
self::assertInstanceOf(InternalProxy::class, $entities[1]->getCountry());

// invalidate cache
$this->_em->persist(new State('foo', $this->_em->find(Country::class, $this->countries[0]->getId())));
Expand All @@ -231,8 +227,6 @@ public function testRepositoryCacheFindAllToOneAssociation(): void
self::assertInstanceOf(State::class, $entities[1]);
self::assertInstanceOf(Country::class, $entities[0]->getCountry());
self::assertInstanceOf(Country::class, $entities[1]->getCountry());
self::assertInstanceOf(InternalProxy::class, $entities[0]->getCountry());
self::assertInstanceOf(InternalProxy::class, $entities[1]->getCountry());

// load from cache
$this->getQueryLog()->reset()->enable();
Expand All @@ -245,7 +239,5 @@ public function testRepositoryCacheFindAllToOneAssociation(): void
self::assertInstanceOf(State::class, $entities[1]);
self::assertInstanceOf(Country::class, $entities[0]->getCountry());
self::assertInstanceOf(Country::class, $entities[1]->getCountry());
self::assertInstanceOf(InternalProxy::class, $entities[0]->getCountry());
self::assertInstanceOf(InternalProxy::class, $entities[1]->getCountry());
}
}
13 changes: 3 additions & 10 deletions tests/Tests/ORM/Functional/Ticket/GH10808Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,11 @@ public function testDQLDeferredEagerLoad(): void
// Clear the EM to prevent the recovery of the loaded instance, which would otherwise result in a proxy.
$this->_em->clear();

self::assertTrue($this->_em->getUnitOfWork()->isUninitializedObject($deferredLoadResult->child));

$eagerLoadResult = $query->setHint(UnitOfWork::HINT_DEFEREAGERLOAD, false)->getSingleResult();

self::assertNotEquals(
GH10808AppointmentChild::class,
get_class($deferredLoadResult->child),
'$deferredLoadResult->child should be a proxy',
);
self::assertEquals(
GH10808AppointmentChild::class,
get_class($eagerLoadResult->child),
'$eagerLoadResult->child should not be a proxy',
);
self::assertFalse($this->_em->getUnitOfWork()->isUninitializedObject($eagerLoadResult->child));
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/Tests/OrmFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\ORM\Proxy\InternalProxy;

Check failure on line 25 in tests/Tests/OrmFunctionalTestCase.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.3)

Type Doctrine\ORM\Proxy\InternalProxy is not used in this file.
use Doctrine\ORM\Tools\DebugUnitOfWorkListener;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\Tools\ToolsException;
Expand Down

0 comments on commit d6a8298

Please sign in to comment.