-
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 branch 'hotfix/#1265-sti-persister-one-to-one-association-notices'
Close #1265
- Loading branch information
Showing
5 changed files
with
102 additions
and
2 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
16 changes: 16 additions & 0 deletions
16
tests/Doctrine/Tests/Models/OneToOneSingleTableInheritance/Cat.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,16 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\OneToOneSingleTableInheritance; | ||
|
||
/** @Entity */ | ||
class Cat extends Pet | ||
{ | ||
const CLASSNAME = __CLASS__; | ||
|
||
/** | ||
* @OneToOne(targetEntity="LitterBox") | ||
* | ||
* @var LitterBox | ||
*/ | ||
public $litterBox; | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/Doctrine/Tests/Models/OneToOneSingleTableInheritance/LitterBox.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,15 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\OneToOneSingleTableInheritance; | ||
|
||
/** | ||
* @Entity | ||
* @Table(name="one_to_one_single_table_inheritance_litter_box") | ||
*/ | ||
class LitterBox | ||
{ | ||
const CLASSNAME = __CLASS__; | ||
|
||
/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */ | ||
public $id; | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/Doctrine/Tests/Models/OneToOneSingleTableInheritance/Pet.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,17 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\OneToOneSingleTableInheritance; | ||
|
||
/** | ||
* @Entity | ||
* @Table(name="one_to_one_single_table_inheritance_pet") | ||
* @InheritanceType("SINGLE_TABLE") | ||
* @DiscriminatorMap({"cat" = "Cat"}) | ||
*/ | ||
abstract class Pet | ||
{ | ||
const CLASSNAME = __CLASS__; | ||
|
||
/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */ | ||
public $id; | ||
} |
52 changes: 52 additions & 0 deletions
52
tests/Doctrine/Tests/ORM/Functional/OneToOneSingleTableInheritanceTest.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,52 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\ORM\Functional; | ||
|
||
use Doctrine\Tests\Models\ECommerce\ECommerceProduct; | ||
use Doctrine\Tests\Models\ECommerce\ECommerceShipping; | ||
use Doctrine\ORM\Mapping\AssociationMapping; | ||
use Doctrine\ORM\Mapping\ClassMetadata; | ||
use Doctrine\ORM\Query; | ||
use Doctrine\Tests\Models\OneToOneSingleTableInheritance\Cat; | ||
use Doctrine\Tests\Models\OneToOneSingleTableInheritance\LitterBox; | ||
use Doctrine\Tests\Models\OneToOneSingleTableInheritance\Pet; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
class OneToOneSingleTableInheritanceTest extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->_schemaTool->createSchema([ | ||
$this->_em->getClassMetadata(Pet::CLASSNAME), | ||
$this->_em->getClassMetadata(Cat::CLASSNAME), | ||
$this->_em->getClassMetadata(LitterBox::CLASSNAME), | ||
]); | ||
} | ||
|
||
/** | ||
* Tests a unidirectional one-to-one association mapping from an inheritance child class | ||
* | ||
* @group DDC-3517 | ||
* @group #1265 | ||
*/ | ||
public function testFindFromOneToOneOwningSideJoinedTableInheritance() | ||
{ | ||
$cat = new Cat(); | ||
$cat->litterBox = new LitterBox(); | ||
|
||
$this->_em->persist($cat); | ||
$this->_em->persist($cat->litterBox); | ||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
/* @var $foundCat Cat */ | ||
$foundCat = $this->_em->find(Pet::CLASSNAME, $cat->id); | ||
|
||
$this->assertInstanceOf(Cat::CLASSNAME, $foundCat); | ||
$this->assertSame($cat->id, $foundCat->id); | ||
$this->assertInstanceOf(LitterBox::CLASSNAME, $foundCat->litterBox); | ||
$this->assertSame($cat->litterBox->id, $foundCat->litterBox->id); | ||
} | ||
} |