Skip to content

Try to add a reproducer for #11861 #11901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: 3.3.x
Choose a base branch
from
Draft
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
106 changes: 106 additions & 0 deletions tests/Tests/ORM/Functional/Ticket/GH11861Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Tests\OrmFunctionalTestCase;

class GH11861Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$this->setUpEntitySchema([
GH11861BaseEntity::class,
GH11861ChildEntityA::class,
]);
}

/**

Check failure on line 23 in tests/Tests/ORM/Functional/Ticket/GH11861Test.php

View workflow job for this annotation

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

Found multi-line doc comment with single line content, use one-line doc comment instead.
* @throws ORMException
*/
public function testEntityMapCollision(): void
{
$externalId = 'external-123'; // Predefined/external ID

// Create and persist entity
$entity = new GH11861ChildEntityA();
$entity->setId($externalId);
$entity->setFieldA('test');
$this->_em->persist($entity);
$this->_em->flush();
$this->_em->clear();

// Fetch via parent class
$baseEntity = $this->_em->find(GH11861BaseEntity::class, $externalId); // Returns ChildEntityA

// Fetch via child class
$childEntity = $this->_em->find(GH11861ChildEntityA::class, $externalId); // New instance created

// Check if they’re the same
self::assertSame($baseEntity, $childEntity);

// Trigger collision
$this->_em->flush(); // Throws identity collision error
}
}

/**
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"a" = "GH11861ChildEntityA"})
*/
#[ORM\Entity]
#[ORM\InheritanceType('JOINED')]
#[ORM\DiscriminatorColumn(name: 'type', type: 'string')]
#[ORM\DiscriminatorMap(['a' => GH11861ChildEntityA::class])]
class GH11861BaseEntity
{
/**
* @ORM\Id
* @ORM\Column(type="string") // Predefined/external ID
*/
#[ORM\Id]
#[ORM\Column(type: 'string')] // Predefined/external ID
protected $id;

Check failure on line 70 in tests/Tests/ORM/Functional/Ticket/GH11861Test.php

View workflow job for this annotation

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

Property \Doctrine\Tests\ORM\Functional\Ticket\GH11861BaseEntity::$id does not have @var annotation for its value.

public function setId($id)

Check failure on line 72 in tests/Tests/ORM/Functional/Ticket/GH11861Test.php

View workflow job for this annotation

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

Method \Doctrine\Tests\ORM\Functional\Ticket\GH11861BaseEntity::setId() does not have void return type hint.
{
$this->id = $id;
}

public function getId()

Check failure on line 77 in tests/Tests/ORM/Functional/Ticket/GH11861Test.php

View workflow job for this annotation

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

Method \Doctrine\Tests\ORM\Functional\Ticket\GH11861BaseEntity::getId() does not have return type hint nor @return annotation for its return value.
{
return $this->id;
}
}

// Child entity

/**

Check failure on line 85 in tests/Tests/ORM/Functional/Ticket/GH11861Test.php

View workflow job for this annotation

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

Found multi-line doc comment with single line content, use one-line doc comment instead.
* @ORM\Entity
*/
#[ORM\Entity]
class GH11861ChildEntityA extends GH11861BaseEntity
{
/**

Check failure on line 91 in tests/Tests/ORM/Functional/Ticket/GH11861Test.php

View workflow job for this annotation

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

Found multi-line doc comment with single line content, use one-line doc comment instead.
* @ORM\Column(type="string")
*/
#[ORM\Column(type: 'string')]
private $fieldA;

Check failure on line 95 in tests/Tests/ORM/Functional/Ticket/GH11861Test.php

View workflow job for this annotation

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

Property \Doctrine\Tests\ORM\Functional\Ticket\GH11861ChildEntityA::$fieldA does not have @var annotation for its value.

public function setFieldA($value)

Check failure on line 97 in tests/Tests/ORM/Functional/Ticket/GH11861Test.php

View workflow job for this annotation

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

Method \Doctrine\Tests\ORM\Functional\Ticket\GH11861ChildEntityA::setFieldA() does not have void return type hint.
{
$this->fieldA = $value;
}

public function getFieldA()

Check failure on line 102 in tests/Tests/ORM/Functional/Ticket/GH11861Test.php

View workflow job for this annotation

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

Method \Doctrine\Tests\ORM\Functional\Ticket\GH11861ChildEntityA::getFieldA() does not have return type hint nor @return annotation for its return value.
{
return $this->fieldA;
}
}
Loading