Tested composite primary key support
This commit is contained in:
parent
5e29bbd41f
commit
7222991b13
44
tests/Doctrine/Tests/Models/GeoNames/Admin1.php
Normal file
44
tests/Doctrine/Tests/Models/GeoNames/Admin1.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\GeoNames;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="geonames_admin1")
|
||||
* @Cache
|
||||
*/
|
||||
class Admin1
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
* @Column(type="integer", length=25)
|
||||
* @GeneratedValue(strategy="NONE")
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @Id
|
||||
* @ManyToOne(targetEntity="Country")
|
||||
* @JoinColumn(name="country", referencedColumnName="id")
|
||||
* @Cache
|
||||
*/
|
||||
public $country;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="Admin1AlternateName", mappedBy="admin1")
|
||||
* @Cache
|
||||
*/
|
||||
public $names = array();
|
||||
|
||||
/**
|
||||
* @Column(type="string", length=255);
|
||||
*/
|
||||
public $name;
|
||||
|
||||
public function __construct($id, $name, Country $country)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->country = $country;
|
||||
}
|
||||
}
|
41
tests/Doctrine/Tests/Models/GeoNames/Admin1AlternateName.php
Normal file
41
tests/Doctrine/Tests/Models/GeoNames/Admin1AlternateName.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\GeoNames;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="geonames_admin1_alternate_name")
|
||||
* @Cache
|
||||
*/
|
||||
class Admin1AlternateName
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
* @Column(type="string", length=25)
|
||||
* @GeneratedValue(strategy="NONE")
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @ManyToOne(targetEntity="Admin1", inversedBy="names")
|
||||
* @JoinColumns({
|
||||
* @JoinColumn(name="admin1", referencedColumnName="id"),
|
||||
* @JoinColumn(name="country", referencedColumnName="country")
|
||||
* })
|
||||
* @Cache
|
||||
*/
|
||||
public $admin1;
|
||||
|
||||
/**
|
||||
* @Column(type="string", length=255);
|
||||
*/
|
||||
public $name;
|
||||
|
||||
|
||||
public function __construct($id, $name, Admin1 $admin1)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->admin1 = $admin1;
|
||||
}
|
||||
}
|
47
tests/Doctrine/Tests/Models/GeoNames/City.php
Normal file
47
tests/Doctrine/Tests/Models/GeoNames/City.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\GeoNames;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="geonames_city")
|
||||
* @Cache
|
||||
*/
|
||||
class City
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
* @Column(type="string", length=25)
|
||||
* @GeneratedValue(strategy="NONE")
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @ManyToOne(targetEntity="Country")
|
||||
* @JoinColumn(name="country", referencedColumnName="id")
|
||||
* @Cache
|
||||
*/
|
||||
public $country;
|
||||
|
||||
/**
|
||||
* @ManyToOne(targetEntity="Admin1")
|
||||
* @JoinColumns({
|
||||
* @JoinColumn(name="admin1", referencedColumnName="id"),
|
||||
* @JoinColumn(name="country", referencedColumnName="country")
|
||||
* })
|
||||
* @Cache
|
||||
*/
|
||||
public $admin1;
|
||||
|
||||
/**
|
||||
* @Column(type="string", length=255);
|
||||
*/
|
||||
public $name;
|
||||
|
||||
|
||||
public function __construct($id, $name)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
29
tests/Doctrine/Tests/Models/GeoNames/Country.php
Normal file
29
tests/Doctrine/Tests/Models/GeoNames/Country.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\GeoNames;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="geonames_country")
|
||||
* @Cache
|
||||
*/
|
||||
class Country
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
* @Column(type="string", length=2)
|
||||
* @GeneratedValue(strategy="NONE")
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @Column(type="string", length=255);
|
||||
*/
|
||||
public $name;
|
||||
|
||||
public function __construct($id, $name)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\Tests\Models\GeoNames\Country;
|
||||
use Doctrine\Tests\Models\GeoNames\Admin1;
|
||||
use Doctrine\Tests\Models\GeoNames\Admin1AlternateName;
|
||||
|
||||
class CompositePrimaryKeyWithAssociationsTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->useModelSet('geonames');
|
||||
parent::setUp();
|
||||
|
||||
$it = new Country("IT", "Italy");
|
||||
|
||||
$this->_em->persist($it);
|
||||
$this->_em->flush();
|
||||
|
||||
$admin1 = new Admin1(1, "Rome", $it);
|
||||
|
||||
$this->_em->persist($admin1);
|
||||
$this->_em->flush();
|
||||
|
||||
$name1 = new Admin1AlternateName(1, "Roma", $admin1);
|
||||
$name2 = new Admin1AlternateName(2, "Rome", $admin1);
|
||||
|
||||
$admin1->names[] = $name1;
|
||||
$admin1->names[] = $name2;
|
||||
|
||||
$this->_em->persist($admin1);
|
||||
$this->_em->persist($name1);
|
||||
$this->_em->persist($name2);
|
||||
|
||||
$this->_em->flush();
|
||||
|
||||
$this->_em->clear();
|
||||
}
|
||||
|
||||
public function testFindByAbleToGetCompositeEntitiesWithMixedTypeIdentifiers()
|
||||
{
|
||||
$admin1Repo = $this->_em->getRepository('Doctrine\Tests\Models\GeoNames\Admin1');
|
||||
$admin1NamesRepo = $this->_em->getRepository('Doctrine\Tests\Models\GeoNames\Admin1AlternateName');
|
||||
|
||||
$admin1Rome = $admin1Repo->findOneBy(array('country' => 'IT', 'id' => 1));
|
||||
|
||||
$names = $admin1NamesRepo->findBy(array('admin1' => $admin1Rome));
|
||||
$this->assertCount(2, $names);
|
||||
|
||||
$name1 = $admin1NamesRepo->findOneBy(array('admin1' => $admin1Rome, 'id' => 1));
|
||||
$name2 = $admin1NamesRepo->findOneBy(array('admin1' => $admin1Rome, 'id' => 2));
|
||||
|
||||
$this->assertEquals(1, $name1->id);
|
||||
$this->assertEquals("Roma", $name1->name);
|
||||
|
||||
$this->assertEquals(2, $name2->id);
|
||||
$this->assertEquals("Rome", $name2->name);
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Persisters;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\ORM\Persisters\Entity\BasicEntityPersister;
|
||||
use Doctrine\Tests\Models\GeoNames\Admin1;
|
||||
use Doctrine\Tests\Models\GeoNames\Country;
|
||||
|
||||
class BasicEntityPersisterCompositeTypeParametersTest extends \Doctrine\Tests\OrmTestCase
|
||||
{
|
||||
/**
|
||||
* @var BasicEntityPersister
|
||||
*/
|
||||
protected $_persister;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\ORM\EntityManager
|
||||
*/
|
||||
protected $_em;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_em = $this->_getTestEntityManager();
|
||||
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\Models\GeoNames\Country');
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\Models\GeoNames\Admin1');
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\Models\GeoNames\Admin1AlternateName');
|
||||
|
||||
$this->_persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\GeoNames\Admin1AlternateName'));
|
||||
|
||||
}
|
||||
|
||||
public function testExpandParametersWillExpandCompositeEntityKeys()
|
||||
{
|
||||
$country = new Country("IT", "Italy");
|
||||
$admin1 = new Admin1(10, "Rome", $country);
|
||||
|
||||
|
||||
list ($values, $types) = $this->_persister->expandParameters(array(
|
||||
'admin1' => $admin1
|
||||
));
|
||||
|
||||
$this->assertEquals(array('integer', 'string'), $types);
|
||||
$this->assertEquals(array(10, 'IT'), $values);
|
||||
}
|
||||
|
||||
public function testExpandCriteriaParametersWillExpandCompositeEntityKeys()
|
||||
{
|
||||
$country = new Country("IT", "Italy");
|
||||
$admin1 = new Admin1(10, "Rome", $country);
|
||||
|
||||
$criteria = Criteria::create();
|
||||
|
||||
$criteria->andWhere(Criteria::expr()->eq("admin1", $admin1));
|
||||
|
||||
list ($values, $types) = $this->_persister->expandCriteriaParameters($criteria);
|
||||
|
||||
$this->assertEquals(array('integer', 'string'), $types);
|
||||
$this->assertEquals(array(10, 'IT'), $values);
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Persisters;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\DBAL\Types\Type as DBALType;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\Persisters\Entity\BasicEntityPersister;
|
||||
use Doctrine\Tests\Models\CustomType\CustomTypeParent;
|
||||
use Doctrine\Tests\Models\CustomType\CustomTypeChild;
|
||||
use Doctrine\Common\Collections\Expr\Comparison;
|
||||
|
||||
class BasicEntityPersisterCompositeTypeSqlTest extends \Doctrine\Tests\OrmTestCase
|
||||
{
|
||||
/**
|
||||
* @var BasicEntityPersister
|
||||
*/
|
||||
protected $_persister;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\ORM\EntityManager
|
||||
*/
|
||||
protected $_em;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_em = $this->_getTestEntityManager();
|
||||
|
||||
$this->_persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\GeoNames\Admin1AlternateName'));
|
||||
}
|
||||
|
||||
public function testSelectConditionStatementEq()
|
||||
{
|
||||
$statement = $this->_persister->getSelectConditionStatementSQL('admin1', 1, array(), Comparison::EQ);
|
||||
$this->assertEquals('t0.admin1 = ? AND t0.country = ?', $statement);
|
||||
}
|
||||
|
||||
public function testSelectConditionStatementEqNull()
|
||||
{
|
||||
$statement = $this->_persister->getSelectConditionStatementSQL('admin1', null, array(), Comparison::IS);
|
||||
$this->assertEquals('t0.admin1 IS NULL AND t0.country IS NULL', $statement);
|
||||
}
|
||||
|
||||
public function testSelectConditionStatementNeqNull()
|
||||
{
|
||||
$statement = $this->_persister->getSelectConditionStatementSQL('admin1', null, array(), Comparison::NEQ);
|
||||
$this->assertEquals('t0.admin1 IS NOT NULL AND t0.country IS NOT NULL', $statement);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Doctrine\ORM\ORMException
|
||||
*/
|
||||
public function testSelectConditionStatementIn()
|
||||
{
|
||||
$this->_persister->getSelectConditionStatementSQL('admin1', array(), array(), Comparison::IN);
|
||||
}
|
||||
}
|
@ -252,6 +252,12 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
||||
'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity',
|
||||
'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity'
|
||||
),
|
||||
'geonames' => array(
|
||||
'Doctrine\Tests\Models\GeoNames\Country',
|
||||
'Doctrine\Tests\Models\GeoNames\Admin1',
|
||||
'Doctrine\Tests\Models\GeoNames\Admin1AlternateName',
|
||||
'Doctrine\Tests\Models\GeoNames\City'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
@ -483,6 +489,12 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
||||
$conn->executeUpdate('DELETE FROM vct_owning_manytomany_extralazy');
|
||||
$conn->executeUpdate('DELETE FROM vct_inversed_manytomany_extralazy');
|
||||
}
|
||||
if (isset($this->_usedModelSets['geonames'])) {
|
||||
$conn->executeUpdate('DELETE FROM geonames_admin1_alternate_name');
|
||||
$conn->executeUpdate('DELETE FROM geonames_admin1');
|
||||
$conn->executeUpdate('DELETE FROM geonames_city');
|
||||
$conn->executeUpdate('DELETE FROM geonames_country');
|
||||
}
|
||||
|
||||
$this->_em->clear();
|
||||
}
|
||||
@ -623,7 +635,8 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
||||
}
|
||||
|
||||
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(
|
||||
realpath(__DIR__ . '/Models/Cache')
|
||||
realpath(__DIR__ . '/Models/Cache'),
|
||||
realpath(__DIR__ . '/Models/GeoNames')
|
||||
), true));
|
||||
|
||||
$conn = static::$_sharedConn;
|
||||
|
Loading…
Reference in New Issue
Block a user