forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
174 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
use function count; | ||
|
||
/** | ||
* @group GH7877 | ||
*/ | ||
class GH7877Test extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp() :void | ||
{ | ||
parent::setUp(); | ||
|
||
$classMetadatas = [ | ||
$this->_em->getClassMetadata(GH7877ApplicationGenerated::class), | ||
$this->_em->getClassMetadata(GH7877DatabaseGenerated::class), | ||
]; | ||
// We first drop the schema to avoid collision between tests | ||
$this->_schemaTool->dropSchema($classMetadatas); | ||
$this->_schemaTool->createSchema($classMetadatas); | ||
} | ||
|
||
public function providerDifferentEntity(): iterable | ||
{ | ||
yield [GH7877ApplicationGenerated::class]; | ||
yield [GH7877DatabaseGenerated::class]; | ||
} | ||
|
||
/** | ||
* @dataProvider providerDifferentEntity | ||
*/ | ||
public function testExtraUpdateWithDifferentEntities(string $class): void | ||
{ | ||
$parent = new $class($parentId = 1); | ||
$this->_em->persist($parent); | ||
|
||
$child = new $class($childId = 2); | ||
$child->parent = $parent; | ||
$this->_em->persist($child); | ||
|
||
$count = count($this->_sqlLoggerStack->queries); | ||
$this->_em->flush(); | ||
$this->assertCount($count + 5, $this->_sqlLoggerStack->queries); | ||
|
||
$this->_em->clear(); | ||
|
||
$child = $this->_em->find($class, $childId); | ||
$this->assertSame($parentId, $child->parent->id); | ||
} | ||
|
||
public function testNoExtraUpdateWithApplicationGeneratedId(): void | ||
{ | ||
$entity = new GH7877ApplicationGenerated($entityId = 1); | ||
$entity->parent = $entity; | ||
$this->_em->persist($entity); | ||
|
||
$count = count($this->_sqlLoggerStack->queries); | ||
$this->_em->flush(); | ||
$this->assertCount($count + 3, $this->_sqlLoggerStack->queries); | ||
|
||
$this->_em->clear(); | ||
|
||
$child = $this->_em->find(GH7877ApplicationGenerated::class, $entityId); | ||
$this->assertSame($entityId, $child->parent->id); | ||
} | ||
|
||
public function textExtraUpdateWithDatabaseGeneratedId(): void | ||
{ | ||
$entity = new GH7877DatabaseGenerated(); | ||
$entity->parent = $entity; | ||
$this->_em->persist($entity); | ||
|
||
$count = count($this->_sqlLoggerStack->queries); | ||
$this->_em->flush(); | ||
$this->assertCount($count + 4, $this->_sqlLoggerStack->queries); | ||
$entityId = $entity->id; | ||
|
||
$this->_em->clear(); | ||
|
||
$child = $this->_em->find(GH7877DatabaseGenerated::class, $entityId); | ||
$this->assertSame($entityId, $child->parent->id); | ||
} | ||
} | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class GH7877ApplicationGenerated | ||
{ | ||
public function __construct(int $id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue(strategy="NONE") | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="Doctrine\Tests\ORM\Functional\GH7877ApplicationGenerated") | ||
* @var self | ||
*/ | ||
public $parent; | ||
} | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class GH7877DatabaseGenerated | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue(strategy="AUTO") | ||
* @var integer | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="Doctrine\Tests\ORM\Functional\Issue7877DatabaseGenerated") | ||
* @var self | ||
*/ | ||
public $parent; | ||
} |