Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add self-referencing OneToMany associations (#34)
- Loading branch information
Showing
10 changed files
with
143 additions
and
28 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
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
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
51 changes: 51 additions & 0 deletions
51
model-tests/ModelAssociationsOneToManySelfReferencingTest.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,51 @@ | ||
<?php | ||
|
||
namespace Webforge\Doctrine\Compiler; | ||
|
||
use ACME\Blog\Entities\Category; | ||
use ACME\Blog\Entities\Tag; | ||
use ACME\Blog\Entities\Author; | ||
|
||
class ModelAssociationsOneToManySelfReferencingTest extends \Webforge\Doctrine\Compiler\Test\ModelBase { | ||
|
||
public function setUp() { | ||
parent::setUp(); | ||
|
||
$this->nodeClass = $this->elevateFull('ACME\Blog\Entities\NavigationNode'); | ||
} | ||
|
||
public function testHasAllSettersGettersAddersRemoversAndCheckers() { | ||
$this->assertThatGClass($this->nodeClass->getParent()) | ||
->hasProperty('children') | ||
->isProtected() | ||
->hasMethod('getChildren') | ||
->hasMethod('setChildren') | ||
->hasMethod('addChild') | ||
->hasMethod('removeChild') | ||
->hasMethod('hasChild') | ||
|
||
->hasProperty('parent') | ||
->isProtected() | ||
->hasMethod('getParent') | ||
->hasMethod('setParent') | ||
; | ||
} | ||
|
||
public function testOneToManyDoctrineMetadata_selfReferencing() { | ||
$metadata = $this->assertDoctrineMetadata($this->nodeClass->getFQN()); | ||
|
||
// inverse side | ||
$children = $this->assertAssociationMapping('children', $metadata, 'OneToMany'); | ||
|
||
$this->assertHasTargetEntity($this->nodeClass, $children); | ||
$this->assertEmpty($children['inversedBy'], 'inversedBy should be empty for inverse side '.print_r($children, true)); | ||
$this->assertIsMappedBy('parent', $children); | ||
|
||
// owning side | ||
$parent = $this->assertAssociationMapping('parent', $metadata, 'ManyToOne'); | ||
|
||
$this->assertHasTargetEntity($this->nodeClass, $parent); | ||
$this->assertEmpty($parent['mappedBy'], 'mappedBy should be empty for owning side'); | ||
$this->assertIsInversedBy('children', $parent); | ||
} | ||
} |
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
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