-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10749 from mpdude/6499-fixed
Add tests to show #6499 has been fixed
- Loading branch information
Showing
3 changed files
with
336 additions
and
0 deletions.
There are no files selected for viewing
155 changes: 155 additions & 0 deletions
155
tests/Doctrine/Tests/ORM/Functional/Ticket/GH6499OneToManyRelationshipTest.php
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,155 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
/** | ||
* @group GH6499 | ||
*/ | ||
class GH6499OneToManyRelationshipTest extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->createSchemaForModels(Application::class, Person::class, ApplicationPerson::class); | ||
} | ||
|
||
/** | ||
* Test for the bug described in issue #6499. | ||
*/ | ||
public function testIssue(): void | ||
{ | ||
$person = new Person(); | ||
$this->_em->persist($person); | ||
|
||
$application = new Application(); | ||
$this->_em->persist($application); | ||
|
||
$applicationPerson = new ApplicationPerson($person, $application); | ||
|
||
$this->_em->persist($applicationPerson); | ||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
$personFromDatabase = $this->_em->find(Person::class, $person->id); | ||
$applicationFromDatabase = $this->_em->find(Application::class, $application->id); | ||
|
||
self::assertEquals($personFromDatabase->id, $person->id, 'Issue #6499 will result in an integrity constraint violation before reaching this point.'); | ||
self::assertFalse($personFromDatabase->getApplicationPeople()->isEmpty()); | ||
|
||
self::assertEquals($applicationFromDatabase->id, $application->id, 'Issue #6499 will result in an integrity constraint violation before reaching this point.'); | ||
self::assertFalse($applicationFromDatabase->getApplicationPeople()->isEmpty()); | ||
} | ||
} | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table("GH6499OTM_application") | ||
*/ | ||
class Application | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\OneToMany(targetEntity=ApplicationPerson::class, mappedBy="application", orphanRemoval=true, cascade={"persist"}) | ||
* @ORM\JoinColumn(nullable=false) | ||
* | ||
* @var Collection | ||
*/ | ||
private $applicationPeople; | ||
|
||
public function __construct() | ||
{ | ||
$this->applicationPeople = new ArrayCollection(); | ||
} | ||
|
||
public function getApplicationPeople(): Collection | ||
{ | ||
return $this->applicationPeople; | ||
} | ||
} | ||
/** | ||
* @ORM\Entity() | ||
* @ORM\Table("GH6499OTM_person") | ||
*/ | ||
class Person | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\OneToMany(targetEntity=ApplicationPerson::class, mappedBy="person", orphanRemoval=true, cascade={"persist"}) | ||
* @ORM\JoinColumn(nullable=false) | ||
* | ||
* @var Collection | ||
*/ | ||
private $applicationPeople; | ||
|
||
public function __construct() | ||
{ | ||
$this->applicationPeople = new ArrayCollection(); | ||
} | ||
|
||
public function getApplicationPeople(): Collection | ||
{ | ||
return $this->applicationPeople; | ||
} | ||
} | ||
|
||
/** | ||
* @ORM\Entity() | ||
* @ORM\Table("GH6499OTM_application_person") | ||
*/ | ||
class ApplicationPerson | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity=Application::class, inversedBy="applicationPeople", cascade={"persist"}) | ||
* @ORM\JoinColumn(nullable=false) | ||
* | ||
* @var Application | ||
*/ | ||
public $application; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity=Person::class, inversedBy="applicationPeople", cascade={"persist"}) | ||
* @ORM\JoinColumn(nullable=false) | ||
* | ||
* @var Person | ||
*/ | ||
public $person; | ||
|
||
public function __construct(Person $person, Application $application) | ||
{ | ||
$this->person = $person; | ||
$this->application = $application; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
tests/Doctrine/Tests/ORM/Functional/Ticket/GH6499OneToOneRelationshipTest.php
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,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
/** | ||
* @group GH6499 | ||
*/ | ||
class GH6499OneToOneRelationshipTest extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->createSchemaForModels(GH6499OTOA::class, GH6499OTOB::class); | ||
} | ||
|
||
/** | ||
* Test for the bug described in issue #6499. | ||
*/ | ||
public function testIssue(): void | ||
{ | ||
$a = new GH6499OTOA(); | ||
|
||
$this->_em->persist($a); | ||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
self::assertEquals( | ||
$this->_em->find(GH6499OTOA::class, $a->id)->b->id, | ||
$a->b->id, | ||
'Issue #6499 will result in an integrity constraint violation before reaching this point.' | ||
); | ||
} | ||
} | ||
|
||
/** @ORM\Entity */ | ||
class GH6499OTOA | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\OneToOne(targetEntity="GH6499OTOB", cascade={"persist"}) | ||
* @ORM\JoinColumn(nullable=false) | ||
* | ||
* @var GH6499OTOB | ||
*/ | ||
public $b; | ||
|
||
public function __construct() | ||
{ | ||
$this->b = new GH6499OTOB(); | ||
} | ||
} | ||
|
||
/** @ORM\Entity */ | ||
class GH6499OTOB | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
} |
103 changes: 103 additions & 0 deletions
103
tests/Doctrine/Tests/ORM/Functional/Ticket/GH6499Test.php
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,103 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
/** | ||
* @group GH6499 | ||
* | ||
* Specifically, GH6499B has a dependency on GH6499A, and GH6499A | ||
* has a dependency on GH6499B. Since GH6499A#b is not nullable, | ||
* the database row for GH6499B should be inserted first. | ||
*/ | ||
class GH6499Test extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->createSchemaForModels(GH6499A::class, GH6499B::class); | ||
} | ||
|
||
public function testIssue(): void | ||
{ | ||
$b = new GH6499B(); | ||
$a = new GH6499A(); | ||
|
||
$this->_em->persist($a); | ||
|
||
$a->b = $b; | ||
|
||
$this->_em->persist($b); | ||
|
||
$this->_em->flush(); | ||
|
||
self::assertIsInt($a->id); | ||
self::assertIsInt($b->id); | ||
} | ||
|
||
public function testIssueReversed(): void | ||
{ | ||
$b = new GH6499B(); | ||
$a = new GH6499A(); | ||
|
||
$a->b = $b; | ||
|
||
$this->_em->persist($b); | ||
$this->_em->persist($a); | ||
|
||
$this->_em->flush(); | ||
|
||
self::assertIsInt($a->id); | ||
self::assertIsInt($b->id); | ||
} | ||
} | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class GH6499A | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\JoinColumn(nullable=false) | ||
* @ORM\OneToOne(targetEntity=GH6499B::class) | ||
* | ||
* @var GH6499B | ||
*/ | ||
public $b; | ||
} | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class GH6499B | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity=GH6499A::class) | ||
* | ||
* @var GH6499A | ||
*/ | ||
private $a; | ||
} |