adedd failing test for PR #440
This commit is contained in:
parent
4e04daaed4
commit
b1c69ebab9
22
tests/Doctrine/Tests/Models/SingleTableInheritanceType/Structure.php
Executable file
22
tests/Doctrine/Tests/Models/SingleTableInheritanceType/Structure.php
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\Models\SingleTableInheritanceType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Table(name="structures")
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class Structure
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(type="integer")
|
||||||
|
* @GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Column(type="string", length=32, nullable=true)
|
||||||
|
*/
|
||||||
|
protected $name;
|
||||||
|
}
|
123
tests/Doctrine/Tests/Models/SingleTableInheritanceType/User.php
Executable file
123
tests/Doctrine/Tests/Models/SingleTableInheritanceType/User.php
Executable file
@ -0,0 +1,123 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\Models\SingleTableInheritanceType;
|
||||||
|
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Table(name="users")
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class User
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(type="integer")
|
||||||
|
* @GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Column(type="string", length=32, nullable=true)
|
||||||
|
*/
|
||||||
|
protected $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var ArrayCollection $followedUsers
|
||||||
|
* @OneToMany(targetEntity="UserFollowedUser", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
|
||||||
|
*/
|
||||||
|
protected $followedUsers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var ArrayCollection $followedStructures
|
||||||
|
* @OneToMany(targetEntity="UserFollowedStructure", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
|
||||||
|
*/
|
||||||
|
protected $followedStructures;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\Models\SingleTableInheritanceType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
* @Table(name="users_followed_objects")
|
||||||
|
* @InheritanceType("SINGLE_TABLE")
|
||||||
|
* @DiscriminatorColumn(name="object_type", type="smallint")
|
||||||
|
* @DiscriminatorMap({4 = "UserFollowedUser", 3 = "UserFollowedStructure"})
|
||||||
|
*/
|
||||||
|
abstract class UserFollowedObject
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var integer $id
|
||||||
|
*
|
||||||
|
* @Column(name="id", type="integer")
|
||||||
|
* @Id
|
||||||
|
* @GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get id
|
||||||
|
*
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\Models\SingleTableInheritanceType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class UserFollowedStructure extends UserFollowedObject
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @ManyToOne(targetEntity="User", inversedBy="followedStructures")
|
||||||
|
* @JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
|
||||||
|
* @var User $user
|
||||||
|
*/
|
||||||
|
protected $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ManyToOne(targetEntity="Structure")
|
||||||
|
* @JoinColumn(name="object_id", referencedColumnName="id", nullable=false)
|
||||||
|
* @var Structure $followedStructure
|
||||||
|
*/
|
||||||
|
private $followedStructure;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a UserFollowedStructure entity
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
* @param Structure $followedStructure
|
||||||
|
*/
|
||||||
|
public function __construct(User $user, Structure $followedStructure)
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
$this->followedStructure = $followedStructure;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return User
|
||||||
|
*/
|
||||||
|
public function getUser()
|
||||||
|
{
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets followed structure
|
||||||
|
*
|
||||||
|
* @return Structure
|
||||||
|
*/
|
||||||
|
public function getFollowedStructure()
|
||||||
|
{
|
||||||
|
return $this->followedStructure;
|
||||||
|
}
|
||||||
|
}
|
55
tests/Doctrine/Tests/Models/SingleTableInheritanceType/UserFollowedUser.php
Executable file
55
tests/Doctrine/Tests/Models/SingleTableInheritanceType/UserFollowedUser.php
Executable file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\Models\SingleTableInheritanceType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class UserFollowedUser extends UserFollowedObject
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @ManyToOne(targetEntity="User", inversedBy="followedUsers")
|
||||||
|
* @JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
|
||||||
|
* @var User $user
|
||||||
|
*/
|
||||||
|
protected $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ManyToOne(targetEntity="User")
|
||||||
|
* @JoinColumn(name="object_id", referencedColumnName="id", nullable=false)
|
||||||
|
* @var User $user
|
||||||
|
*/
|
||||||
|
private $followedUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a UserFollowedUser entity
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
* @param User $followedUser
|
||||||
|
* @param bool $giveAgency
|
||||||
|
*/
|
||||||
|
public function __construct(User $user, User $followedUser)
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
$this->followedUser = $followedUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getUser()
|
||||||
|
{
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets followed user
|
||||||
|
*
|
||||||
|
* @return User
|
||||||
|
*/
|
||||||
|
public function getFollowedUser()
|
||||||
|
{
|
||||||
|
return $this->followedUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -32,6 +32,38 @@ class SchemaToolTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$this->assertTrue($schema->getTable('cms_users')->columnsAreIndexed(array('username')), "username column should be indexed.");
|
$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()
|
public function testAnnotationOptionsAttribute()
|
||||||
{
|
{
|
||||||
$em = $this->_getTestEntityManager();
|
$em = $this->_getTestEntityManager();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user