diff --git a/tests/Doctrine/Tests/Models/SingleTableInheritanceType/Structure.php b/tests/Doctrine/Tests/Models/SingleTableInheritanceType/Structure.php new file mode 100755 index 00000000000..6be981aebcb --- /dev/null +++ b/tests/Doctrine/Tests/Models/SingleTableInheritanceType/Structure.php @@ -0,0 +1,22 @@ +followedUsers = new ArrayCollection(); + $this->followedStructures = new ArrayCollection(); + } + + /* + * Remove followers + * + * @param UserFollowedUser $followers + */ + private function removeFollower(UserFollowedUser $followers) + { + $this->followers->removeElement($followers); + } + + /** + * Add followedUsers + * + * @param UserFollowedUser $followedUsers + * @return User + */ + public function addFollowedUser(UserFollowedUser $followedUsers) + { + $this->followedUsers[] = $followedUsers; + + return $this; + } + + /** + * Remove followedUsers + * + * @param UserFollowedUser $followedUsers + * @return User + */ + public function removeFollowedUser(UserFollowedUser $followedUsers) + { + $this->followedUsers->removeElement($followedUsers); + + return $this; + } + + /** + * Get followedUsers + * + * @return Doctrine\Common\Collections\Collection + */ + public function getFollowedUsers() + { + return $this->followedUsers; + } + + /** + * Add followedStructures + * + * @param UserFollowedStructure $followedStructures + * @return User + */ + public function addFollowedStructure(UserFollowedStructure $followedStructures) + { + $this->followedStructures[] = $followedStructures; + + return $this; + } + + /** + * Remove followedStructures + * + * @param UserFollowedStructure $followedStructures + * @return User + */ + public function removeFollowedStructure(UserFollowedStructure $followedStructures) + { + $this->followedStructures->removeElement($followedStructures); + + return $this; + } + + /** + * Get followedStructures + * + * @return Doctrine\Common\Collections\Collection + */ + public function getFollowedStructures() + { + return $this->followedStructures; + } +} diff --git a/tests/Doctrine/Tests/Models/SingleTableInheritanceType/UserFollowedObject.php b/tests/Doctrine/Tests/Models/SingleTableInheritanceType/UserFollowedObject.php new file mode 100755 index 00000000000..9996660c032 --- /dev/null +++ b/tests/Doctrine/Tests/Models/SingleTableInheritanceType/UserFollowedObject.php @@ -0,0 +1,32 @@ +id; + } +} diff --git a/tests/Doctrine/Tests/Models/SingleTableInheritanceType/UserFollowedStructure.php b/tests/Doctrine/Tests/Models/SingleTableInheritanceType/UserFollowedStructure.php new file mode 100755 index 00000000000..8ee0888cf28 --- /dev/null +++ b/tests/Doctrine/Tests/Models/SingleTableInheritanceType/UserFollowedStructure.php @@ -0,0 +1,54 @@ +user = $user; + $this->followedStructure = $followedStructure; + } + + /** + * + * @return User + */ + public function getUser() + { + return $this->user; + } + + /** + * Gets followed structure + * + * @return Structure + */ + public function getFollowedStructure() + { + return $this->followedStructure; + } +} diff --git a/tests/Doctrine/Tests/Models/SingleTableInheritanceType/UserFollowedUser.php b/tests/Doctrine/Tests/Models/SingleTableInheritanceType/UserFollowedUser.php new file mode 100755 index 00000000000..0f90a2416b9 --- /dev/null +++ b/tests/Doctrine/Tests/Models/SingleTableInheritanceType/UserFollowedUser.php @@ -0,0 +1,55 @@ +user = $user; + $this->followedUser = $followedUser; + } + + /** + * {@inheritdoc} + */ + public function getUser() + { + return $this->user; + } + + /** + * Gets followed user + * + * @return User + */ + public function getFollowedUser() + { + return $this->followedUser; + } + +} diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php index 66093a38d10..c215cf6f0d0 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php @@ -32,6 +32,38 @@ public function testAddUniqueIndexForUniqueFieldAnnocation() $this->assertTrue($schema->getTable('cms_users')->columnsAreIndexed(array('username')), "username column should be indexed."); } + public function testForeignKeyOnSTIWithMultipleMapping() + { + $em = $this->_getTestEntityManager(); + $schemaTool = new SchemaTool($em); + + $classes = array( + $em->getClassMetadata('Doctrine\Tests\Models\SingleTableInheritanceType\User'), + $em->getClassMetadata('Doctrine\Tests\Models\SingleTableInheritanceType\Structure'), + $em->getClassMetadata('Doctrine\Tests\Models\SingleTableInheritanceType\UserFollowedObject'), + $em->getClassMetadata('Doctrine\Tests\Models\SingleTableInheritanceType\UserFollowedStructure'), + $em->getClassMetadata('Doctrine\Tests\Models\SingleTableInheritanceType\UserFollowedUser') + ); + + $schema = $schemaTool->getSchemaFromMetadata($classes); + $this->assertTrue($schema->hasTable('users_followed_objects'), "Table users_followed_objects should exist."); + + /* @var $table \Doctrine\DBAL\Schema\Table */ + $table = ($schema->getTable('users_followed_objects')); + $this->assertTrue($table->columnsAreIndexed(array('object_id'))); + $this->assertTrue($table->columnsAreIndexed(array('user_id'))); + $foreignKeys = $table->getForeignKeys(); + $this->assertCount(1, $foreignKeys, 'user_id column has to have FK, but not object_id'); + + /* @var $fk \Doctrine\DBAL\Schema\ForeignKeyConstraint */ + $fk = reset($foreignKeys); + $this->assertEquals('users', $fk->getForeignTableName()); + + $localColumns = $fk->getLocalColumns(); + $this->assertContains('user_id', $localColumns); + $this->assertCount(1, $localColumns); + } + public function testAnnotationOptionsAttribute() { $em = $this->_getTestEntityManager();