Skip to content

Commit

Permalink
add reproducer
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond authored and nicolas-grekas committed Jan 9, 2023
1 parent c9efc1c commit 3b8692f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/Doctrine/ORM/Proxy/ProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,10 @@ private function generateSkippedProperties(ClassMetadata $class): string
{
$skippedProperties = ['__isCloning' => true];
$identifiers = array_flip($class->getIdentifierFieldNames());
$filter = ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PRIVATE;
$reflector = $class->getReflectionClass();

$filter = ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PRIVATE;
$reflector = $class->getReflectionClass();

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

Expand All @@ -330,8 +329,10 @@ private function generateSkippedProperties(ClassMetadata $class): string

$skippedProperties[$prefix . $name] = true;
}
$filter = ReflectionProperty::IS_PRIVATE;
} while ($reflector = $reflector->getParentClass());

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

uksort($skippedProperties, 'strnatcmp');

Expand Down
27 changes: 27 additions & 0 deletions tests/Doctrine/Tests/Models/GH10336/GH10336Entity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Models\GH10336;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
* @ORM\Table(name="gh10336_entities")
*/
class GH10336Entity
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
public ?int $id = null;

/**
* @ORM\ManyToOne(targetEntity="GH10336Relation")
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id", nullable=true)
*/
public ?GH10336Relation $relation = null;
}
26 changes: 26 additions & 0 deletions tests/Doctrine/Tests/Models/GH10336/GH10336Relation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Models\GH10336;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
* @ORM\Table(name="gh10336_relations")
*/
class GH10336Relation
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
public ?int $id = null;

/**
* @ORM\Column(type="string")
*/
public string $value;
}
44 changes: 44 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH10336Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Tests\Models\GH10336\GH10336Entity;
use Doctrine\Tests\Models\GH10336\GH10336Relation;
use Doctrine\Tests\OrmFunctionalTestCase;

/**
* @requires PHP 7.4
*/
final class GH10336Test extends OrmFunctionalTestCase
{
public function setUp(): void
{
parent::setUp();

$this->createSchemaForModels(
GH10336Entity::class,
GH10336Relation::class
);
}

public function testCanAccessRelationPropertyAfterClear(): void
{
$relation = new GH10336Relation();
$relation->value = 'foo';
$entity = new GH10336Entity();
$entity->relation = $relation;

$this->_em->persist($entity);
$this->_em->persist($relation);
$this->_em->flush();
$this->_em->clear();

$entity = $this->_em->find(GH10336Entity::class, 1);

$this->_em->clear();

$this->assertSame('foo', $entity->relation->value);
}
}

0 comments on commit 3b8692f

Please sign in to comment.