[DoctrineBridge] Improved test coverage of EntityChoiceList
This commit is contained in:
parent
58e7c100dc
commit
7879f079f6
@ -208,11 +208,26 @@ class EntityChoiceList extends ObjectChoiceList
|
|||||||
// Optimize performance in case we have an entity loader and
|
// Optimize performance in case we have an entity loader and
|
||||||
// a single-field identifier
|
// a single-field identifier
|
||||||
if ($this->idAsValue && $this->entityLoader) {
|
if ($this->idAsValue && $this->entityLoader) {
|
||||||
if (empty($values)) {
|
$unorderedEntities = $this->entityLoader->getEntitiesByIds($this->idField, $values);
|
||||||
return array();
|
$entitiesByValue = array();
|
||||||
|
$entities = array();
|
||||||
|
|
||||||
|
// Maintain order and indices from the given $values
|
||||||
|
// An alternative approach to the following loop is to add the
|
||||||
|
// "INDEX BY" clause to the Doctrine query in the loader,
|
||||||
|
// but I'm not sure whether that's doable in a generic fashion.
|
||||||
|
foreach ($unorderedEntities as $entity) {
|
||||||
|
$value = $this->fixValue(current($this->getIdentifierValues($entity)));
|
||||||
|
$entitiesByValue[$value] = $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->entityLoader->getEntitiesByIds($this->idField, $values);
|
foreach ($values as $i => $value) {
|
||||||
|
if (isset($entitiesByValue[$value])) {
|
||||||
|
$entities[$i] = $entitiesByValue[$value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->load();
|
$this->load();
|
||||||
@ -240,10 +255,10 @@ class EntityChoiceList extends ObjectChoiceList
|
|||||||
if ($this->idAsValue) {
|
if ($this->idAsValue) {
|
||||||
$values = array();
|
$values = array();
|
||||||
|
|
||||||
foreach ($entities as $entity) {
|
foreach ($entities as $i => $entity) {
|
||||||
if ($entity instanceof $this->class) {
|
if ($entity instanceof $this->class) {
|
||||||
// Make sure to convert to the right format
|
// Make sure to convert to the right format
|
||||||
$values[] = $this->fixValue(current($this->getIdentifierValues($entity)));
|
$values[$i] = $this->fixValue(current($this->getIdentifierValues($entity)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,10 +290,10 @@ class EntityChoiceList extends ObjectChoiceList
|
|||||||
if ($this->idAsIndex) {
|
if ($this->idAsIndex) {
|
||||||
$indices = array();
|
$indices = array();
|
||||||
|
|
||||||
foreach ($entities as $entity) {
|
foreach ($entities as $i => $entity) {
|
||||||
if ($entity instanceof $this->class) {
|
if ($entity instanceof $this->class) {
|
||||||
// Make sure to convert to the right format
|
// Make sure to convert to the right format
|
||||||
$indices[] = $this->fixIndex(current($this->getIdentifierValues($entity)));
|
$indices[$i] = $this->fixIndex(current($this->getIdentifierValues($entity)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
59
src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php
Normal file
59
src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Doctrine\Test;
|
||||||
|
|
||||||
|
use Doctrine\Common\Annotations\AnnotationReader;
|
||||||
|
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
|
||||||
|
use Doctrine\ORM\EntityManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides utility functions needed in tests.
|
||||||
|
*
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
class DoctrineTestHelper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns an entity manager for testing.
|
||||||
|
*
|
||||||
|
* @return EntityManager
|
||||||
|
*/
|
||||||
|
public static function createTestEntityManager()
|
||||||
|
{
|
||||||
|
if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) {
|
||||||
|
\PHPUnit_Framework_TestCase::markTestSkipped('This test requires SQLite support in your environment');
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = new \Doctrine\ORM\Configuration();
|
||||||
|
$config->setEntityNamespaces(array('SymfonyTestsDoctrine' => 'Symfony\Bridge\Doctrine\Tests\Fixtures'));
|
||||||
|
$config->setAutoGenerateProxyClasses(true);
|
||||||
|
$config->setProxyDir(\sys_get_temp_dir());
|
||||||
|
$config->setProxyNamespace('SymfonyTests\Doctrine');
|
||||||
|
$config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader()));
|
||||||
|
$config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
|
||||||
|
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
|
||||||
|
|
||||||
|
$params = array(
|
||||||
|
'driver' => 'pdo_sqlite',
|
||||||
|
'memory' => true,
|
||||||
|
);
|
||||||
|
|
||||||
|
return EntityManager::create($params, $config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class cannot be instantiated.
|
||||||
|
*/
|
||||||
|
private function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -11,10 +11,14 @@
|
|||||||
|
|
||||||
namespace Symfony\Bridge\Doctrine\Tests;
|
namespace Symfony\Bridge\Doctrine\Tests;
|
||||||
|
|
||||||
use Doctrine\Common\Annotations\AnnotationReader;
|
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
|
||||||
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
|
|
||||||
use Doctrine\ORM\EntityManager;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DoctrineOrmTestCase
|
||||||
|
*
|
||||||
|
* @deprecated Deprecated as of Symfony 2.4, to be removed in Symfony 3.0.
|
||||||
|
* Use {@link DoctrineTestHelper} instead.
|
||||||
|
*/
|
||||||
abstract class DoctrineOrmTestCase extends \PHPUnit_Framework_TestCase
|
abstract class DoctrineOrmTestCase extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
@ -33,27 +37,10 @@ abstract class DoctrineOrmTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return EntityManager
|
* @return \Doctrine\ORM\EntityManager
|
||||||
*/
|
*/
|
||||||
public static function createTestEntityManager($paths = array())
|
public static function createTestEntityManager()
|
||||||
{
|
{
|
||||||
if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) {
|
return DoctrineTestHelper::createTestEntityManager();
|
||||||
self::markTestSkipped('This test requires SQLite support in your environment');
|
|
||||||
}
|
|
||||||
$config = new \Doctrine\ORM\Configuration();
|
|
||||||
$config->setEntityNamespaces(array('SymfonyTestsDoctrine' => 'Symfony\Bridge\Doctrine\Tests\Fixtures'));
|
|
||||||
$config->setAutoGenerateProxyClasses(true);
|
|
||||||
$config->setProxyDir(\sys_get_temp_dir());
|
|
||||||
$config->setProxyNamespace('SymfonyTests\Doctrine');
|
|
||||||
$config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader()));
|
|
||||||
$config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
|
|
||||||
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
|
|
||||||
|
|
||||||
$params = array(
|
|
||||||
'driver' => 'pdo_sqlite',
|
|
||||||
'memory' => true,
|
|
||||||
);
|
|
||||||
|
|
||||||
return EntityManager::create($params, $config);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,18 +26,18 @@ class AssociationEntity
|
|||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="SingleIdentEntity")
|
* @ORM\ManyToOne(targetEntity="SingleIntIdEntity")
|
||||||
* @var \Symfony\Bridge\Doctrine\Tests\Form\Fixtures\SingleIdentEntity
|
* @var \Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity
|
||||||
*/
|
*/
|
||||||
public $single;
|
public $single;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="CompositeIdentEntity")
|
* @ORM\ManyToOne(targetEntity="CompositeIntIdEntity")
|
||||||
* @ORM\JoinColumns({
|
* @ORM\JoinColumns({
|
||||||
* @ORM\JoinColumn(name="composite_id1", referencedColumnName="id1"),
|
* @ORM\JoinColumn(name="composite_id1", referencedColumnName="id1"),
|
||||||
* @ORM\JoinColumn(name="composite_id2", referencedColumnName="id2")
|
* @ORM\JoinColumn(name="composite_id2", referencedColumnName="id2")
|
||||||
* })
|
* })
|
||||||
* @var \Symfony\Bridge\Doctrine\Tests\Form\Fixtures\CompositeIdentEntity
|
* @var \Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity
|
||||||
*/
|
*/
|
||||||
public $composite;
|
public $composite;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping\Id;
|
||||||
|
use Doctrine\ORM\Mapping\Column;
|
||||||
|
use Doctrine\ORM\Mapping\Entity;
|
||||||
|
|
||||||
|
/** @Entity */
|
||||||
|
class CompositeIntIdEntity
|
||||||
|
{
|
||||||
|
/** @Id @Column(type="integer") */
|
||||||
|
protected $id1;
|
||||||
|
|
||||||
|
/** @Id @Column(type="integer") */
|
||||||
|
protected $id2;
|
||||||
|
|
||||||
|
/** @Column(type="string") */
|
||||||
|
public $name;
|
||||||
|
|
||||||
|
public function __construct($id1, $id2, $name)
|
||||||
|
{
|
||||||
|
$this->id1 = $id1;
|
||||||
|
$this->id2 = $id2;
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,7 @@ use Doctrine\ORM\Mapping\Column;
|
|||||||
use Doctrine\ORM\Mapping\Entity;
|
use Doctrine\ORM\Mapping\Entity;
|
||||||
|
|
||||||
/** @Entity */
|
/** @Entity */
|
||||||
class CompositeStringIdentEntity
|
class CompositeStringIdEntity
|
||||||
{
|
{
|
||||||
/** @Id @Column(type="string") */
|
/** @Id @Column(type="string") */
|
||||||
protected $id1;
|
protected $id1;
|
||||||
@ -33,4 +33,9 @@ class CompositeStringIdentEntity
|
|||||||
$this->id2 = $id2;
|
$this->id2 = $id2;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
}
|
}
|
@ -16,7 +16,7 @@ use Doctrine\ORM\Mapping\Column;
|
|||||||
use Doctrine\ORM\Mapping\Entity;
|
use Doctrine\ORM\Mapping\Entity;
|
||||||
|
|
||||||
/** @Entity */
|
/** @Entity */
|
||||||
class DoubleIdentEntity
|
class DoubleNameEntity
|
||||||
{
|
{
|
||||||
/** @Id @Column(type="integer") */
|
/** @Id @Column(type="integer") */
|
||||||
protected $id;
|
protected $id;
|
@ -16,7 +16,7 @@ use Doctrine\ORM\Mapping\Column;
|
|||||||
use Doctrine\ORM\Mapping\Entity;
|
use Doctrine\ORM\Mapping\Entity;
|
||||||
|
|
||||||
/** @Entity */
|
/** @Entity */
|
||||||
class ItemGroupEntity
|
class GroupableEntity
|
||||||
{
|
{
|
||||||
/** @Id @Column(type="integer") */
|
/** @Id @Column(type="integer") */
|
||||||
protected $id;
|
protected $id;
|
@ -16,7 +16,7 @@ use Doctrine\ORM\Mapping\Column;
|
|||||||
use Doctrine\ORM\Mapping\Entity;
|
use Doctrine\ORM\Mapping\Entity;
|
||||||
|
|
||||||
/** @Entity */
|
/** @Entity */
|
||||||
class SingleIdentEntity
|
class SingleIntIdEntity
|
||||||
{
|
{
|
||||||
/** @Id @Column(type="integer") */
|
/** @Id @Column(type="integer") */
|
||||||
protected $id;
|
protected $id;
|
@ -16,7 +16,7 @@ use Doctrine\ORM\Mapping\Column;
|
|||||||
use Doctrine\ORM\Mapping\Entity;
|
use Doctrine\ORM\Mapping\Entity;
|
||||||
|
|
||||||
/** @Entity */
|
/** @Entity */
|
||||||
class NoToStringSingleIdentEntity
|
class SingleIntIdNoToStringEntity
|
||||||
{
|
{
|
||||||
/** @Id @Column(type="integer") */
|
/** @Id @Column(type="integer") */
|
||||||
protected $id;
|
protected $id;
|
@ -16,7 +16,7 @@ use Doctrine\ORM\Mapping\Column;
|
|||||||
use Doctrine\ORM\Mapping\Entity;
|
use Doctrine\ORM\Mapping\Entity;
|
||||||
|
|
||||||
/** @Entity */
|
/** @Entity */
|
||||||
class SingleStringIdentEntity
|
class SingleStringIdEntity
|
||||||
{
|
{
|
||||||
/** @Id @Column(type="string") */
|
/** @Id @Column(type="string") */
|
||||||
protected $id;
|
protected $id;
|
||||||
@ -29,4 +29,9 @@ class SingleStringIdentEntity
|
|||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
}
|
}
|
@ -17,7 +17,7 @@ use Doctrine\ORM\Mapping\Entity;
|
|||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
|
|
||||||
/** @Entity */
|
/** @Entity */
|
||||||
class CompositeIdentEntity implements UserInterface
|
class User implements UserInterface
|
||||||
{
|
{
|
||||||
/** @Id @Column(type="integer") */
|
/** @Id @Column(type="integer") */
|
||||||
protected $id1;
|
protected $id1;
|
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||||
|
|
||||||
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
abstract class AbstractEntityChoiceListCompositeIdTest extends AbstractEntityChoiceListTest
|
||||||
|
{
|
||||||
|
protected function getEntityClass()
|
||||||
|
{
|
||||||
|
return 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
||||||
|
*/
|
||||||
|
protected function createObjects()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
new CompositeIntIdEntity(10, 11, 'A'),
|
||||||
|
new CompositeIntIdEntity(20, 21, 'B'),
|
||||||
|
new CompositeIntIdEntity(30, 31, 'C'),
|
||||||
|
new CompositeIntIdEntity(40, 41, 'D'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getChoices()
|
||||||
|
{
|
||||||
|
return array(0 => $this->obj1, 1 => $this->obj2, 2 => $this->obj3, 3 => $this->obj4);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getLabels()
|
||||||
|
{
|
||||||
|
return array(0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getValues()
|
||||||
|
{
|
||||||
|
return array(0 => '0', 1 => '1', 2 => '2', 3 => '3');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getIndices()
|
||||||
|
{
|
||||||
|
return array(0, 1, 2, 3);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||||
|
|
||||||
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
abstract class AbstractEntityChoiceListSingleIntIdTest extends AbstractEntityChoiceListTest
|
||||||
|
{
|
||||||
|
protected function getEntityClass()
|
||||||
|
{
|
||||||
|
return 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
||||||
|
*/
|
||||||
|
protected function createObjects()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
new SingleIntIdEntity(-10, 'A'),
|
||||||
|
new SingleIntIdEntity(10, 'B'),
|
||||||
|
new SingleIntIdEntity(20, 'C'),
|
||||||
|
new SingleIntIdEntity(30, 'D'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getChoices()
|
||||||
|
{
|
||||||
|
return array('_10' => $this->obj1, 10 => $this->obj2, 20 => $this->obj3, 30 => $this->obj4);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getLabels()
|
||||||
|
{
|
||||||
|
return array('_10' => 'A', 10 => 'B', 20 => 'C', 30 => 'D');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getValues()
|
||||||
|
{
|
||||||
|
return array('_10' => '-10', 10 => '10', 20 => '20', 30 => '30');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getIndices()
|
||||||
|
{
|
||||||
|
return array('_10', 10, 20, 30);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||||
|
|
||||||
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
abstract class AbstractEntityChoiceListSingleStringIdTest extends AbstractEntityChoiceListTest
|
||||||
|
{
|
||||||
|
protected function getEntityClass()
|
||||||
|
{
|
||||||
|
return 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
||||||
|
*/
|
||||||
|
protected function createObjects()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
new SingleStringIdEntity('a', 'A'),
|
||||||
|
new SingleStringIdEntity('b', 'B'),
|
||||||
|
new SingleStringIdEntity('c', 'C'),
|
||||||
|
new SingleStringIdEntity('d', 'D'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getChoices()
|
||||||
|
{
|
||||||
|
return array(0 => $this->obj1, 1 => $this->obj2, 2 => $this->obj3, 3 => $this->obj4);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getLabels()
|
||||||
|
{
|
||||||
|
return array(0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getValues()
|
||||||
|
{
|
||||||
|
return array(0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getIndices()
|
||||||
|
{
|
||||||
|
return array(0, 1, 2, 3);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||||
|
|
||||||
|
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
|
||||||
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
|
||||||
|
use Doctrine\ORM\Tools\SchemaTool;
|
||||||
|
use Symfony\Component\Form\Tests\Extension\Core\ChoiceList\AbstractChoiceListTest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
abstract class AbstractEntityChoiceListTest extends AbstractChoiceListTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \Doctrine\ORM\EntityManager
|
||||||
|
*/
|
||||||
|
protected $em;
|
||||||
|
|
||||||
|
protected $obj1;
|
||||||
|
|
||||||
|
protected $obj2;
|
||||||
|
|
||||||
|
protected $obj3;
|
||||||
|
|
||||||
|
protected $obj4;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
if (!class_exists('Symfony\Component\Form\Form')) {
|
||||||
|
$this->markTestSkipped('The "Form" component is not available');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!class_exists('Doctrine\DBAL\Platforms\MySqlPlatform')) {
|
||||||
|
$this->markTestSkipped('Doctrine DBAL is not available.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!class_exists('Doctrine\Common\Version')) {
|
||||||
|
$this->markTestSkipped('Doctrine Common is not available.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!class_exists('Doctrine\ORM\EntityManager')) {
|
||||||
|
$this->markTestSkipped('Doctrine ORM is not available.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->em = DoctrineTestHelper::createTestEntityManager();
|
||||||
|
|
||||||
|
$schemaTool = new SchemaTool($this->em);
|
||||||
|
$classes = array($this->em->getClassMetadata($this->getEntityClass()));
|
||||||
|
|
||||||
|
try {
|
||||||
|
$schemaTool->dropSchema($classes);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$schemaTool->createSchema($classes);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
list($this->obj1, $this->obj2, $this->obj3, $this->obj4) = $this->createObjects();
|
||||||
|
|
||||||
|
$this->em->persist($this->obj1);
|
||||||
|
$this->em->persist($this->obj2);
|
||||||
|
$this->em->persist($this->obj3);
|
||||||
|
$this->em->persist($this->obj4);
|
||||||
|
$this->em->flush();
|
||||||
|
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown()
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
$this->em = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected function getEntityClass();
|
||||||
|
|
||||||
|
abstract protected function createObjects();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
||||||
|
*/
|
||||||
|
protected function createChoiceList()
|
||||||
|
{
|
||||||
|
return new EntityChoiceList($this->em, $this->getEntityClass());
|
||||||
|
}
|
||||||
|
}
|
@ -11,26 +11,27 @@
|
|||||||
|
|
||||||
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||||
|
|
||||||
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
|
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
|
||||||
use Symfony\Bridge\Doctrine\Tests\DoctrineOrmTestCase;
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\GroupableEntity;
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\ItemGroupEntity;
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIdentEntity;
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity;
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdentEntity;
|
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\NoToStringSingleIdentEntity;
|
|
||||||
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
|
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
|
||||||
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
use Doctrine\ORM\Tools\SchemaTool;
|
use Doctrine\ORM\Tools\SchemaTool;
|
||||||
|
|
||||||
class EntityChoiceListTest extends DoctrineOrmTestCase
|
class GenericEntityChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
const ITEM_GROUP_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\ItemGroupEntity';
|
const SINGLE_INT_ID_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity';
|
||||||
|
|
||||||
const SINGLE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIdentEntity';
|
const SINGLE_STRING_ID_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity';
|
||||||
|
|
||||||
const SINGLE_STRING_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdentEntity';
|
const COMPOSITE_ID_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity';
|
||||||
|
|
||||||
const COMPOSITE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIdentEntity';
|
const GROUPABLE_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\GroupableEntity';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Doctrine\ORM\EntityManager
|
||||||
|
*/
|
||||||
private $em;
|
private $em;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
@ -39,16 +40,26 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
$this->markTestSkipped('The "Form" component is not available');
|
$this->markTestSkipped('The "Form" component is not available');
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::setUp();
|
if (!class_exists('Doctrine\DBAL\Platforms\MySqlPlatform')) {
|
||||||
|
$this->markTestSkipped('Doctrine DBAL is not available.');
|
||||||
|
}
|
||||||
|
|
||||||
$this->em = $this->createTestEntityManager();
|
if (!class_exists('Doctrine\Common\Version')) {
|
||||||
|
$this->markTestSkipped('Doctrine Common is not available.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!class_exists('Doctrine\ORM\EntityManager')) {
|
||||||
|
$this->markTestSkipped('Doctrine ORM is not available.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->em = DoctrineTestHelper::createTestEntityManager();
|
||||||
|
|
||||||
$schemaTool = new SchemaTool($this->em);
|
$schemaTool = new SchemaTool($this->em);
|
||||||
$classes = array(
|
$classes = array(
|
||||||
$this->em->getClassMetadata(self::ITEM_GROUP_CLASS),
|
$this->em->getClassMetadata(self::SINGLE_INT_ID_CLASS),
|
||||||
$this->em->getClassMetadata(self::SINGLE_IDENT_CLASS),
|
$this->em->getClassMetadata(self::SINGLE_STRING_ID_CLASS),
|
||||||
$this->em->getClassMetadata(self::SINGLE_STRING_IDENT_CLASS),
|
$this->em->getClassMetadata(self::COMPOSITE_ID_CLASS),
|
||||||
$this->em->getClassMetadata(self::COMPOSITE_IDENT_CLASS),
|
$this->em->getClassMetadata(self::GROUPABLE_CLASS),
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -60,6 +71,8 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
$schemaTool->createSchema($classes);
|
$schemaTool->createSchema($classes);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
@ -71,12 +84,12 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\StringCastException
|
* @expectedException \Symfony\Component\Form\Exception\StringCastException
|
||||||
* @expectedMessage Entity "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIdentEntity" passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option).
|
* @expectedMessage Entity "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity" passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option).
|
||||||
*/
|
*/
|
||||||
public function testEntitiesMustHaveAToStringMethod()
|
public function testEntitiesMustHaveAToStringMethod()
|
||||||
{
|
{
|
||||||
$entity1 = new NoToStringSingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdNoToStringEntity(1, 'Foo');
|
||||||
$entity2 = new NoToStringSingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdNoToStringEntity(2, 'Bar');
|
||||||
|
|
||||||
// Persist for managed state
|
// Persist for managed state
|
||||||
$this->em->persist($entity1);
|
$this->em->persist($entity1);
|
||||||
@ -84,7 +97,7 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
|
|
||||||
$choiceList = new EntityChoiceList(
|
$choiceList = new EntityChoiceList(
|
||||||
$this->em,
|
$this->em,
|
||||||
self::SINGLE_IDENT_CLASS,
|
self::SINGLE_INT_ID_CLASS,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
array(
|
array(
|
||||||
@ -101,14 +114,14 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
*/
|
*/
|
||||||
public function testChoicesMustBeManaged()
|
public function testChoicesMustBeManaged()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
|
|
||||||
// no persist here!
|
// no persist here!
|
||||||
|
|
||||||
$choiceList = new EntityChoiceList(
|
$choiceList = new EntityChoiceList(
|
||||||
$this->em,
|
$this->em,
|
||||||
self::SINGLE_IDENT_CLASS,
|
self::SINGLE_INT_ID_CLASS,
|
||||||
'name',
|
'name',
|
||||||
null,
|
null,
|
||||||
array(
|
array(
|
||||||
@ -121,10 +134,10 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
$choiceList->getChoices();
|
$choiceList->getChoices();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFlattenedChoicesAreManaged()
|
public function testInitExplicitChoices()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
|
|
||||||
// Persist for managed state
|
// Persist for managed state
|
||||||
$this->em->persist($entity1);
|
$this->em->persist($entity1);
|
||||||
@ -132,7 +145,7 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
|
|
||||||
$choiceList = new EntityChoiceList(
|
$choiceList = new EntityChoiceList(
|
||||||
$this->em,
|
$this->em,
|
||||||
self::SINGLE_IDENT_CLASS,
|
self::SINGLE_INT_ID_CLASS,
|
||||||
'name',
|
'name',
|
||||||
null,
|
null,
|
||||||
array(
|
array(
|
||||||
@ -144,10 +157,10 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
$this->assertSame(array(1 => $entity1, 2 => $entity2), $choiceList->getChoices());
|
$this->assertSame(array(1 => $entity1, 2 => $entity2), $choiceList->getChoices());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEmptyChoicesAreManaged()
|
public function testInitEmptyChoices()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
|
|
||||||
// Persist for managed state
|
// Persist for managed state
|
||||||
$this->em->persist($entity1);
|
$this->em->persist($entity1);
|
||||||
@ -155,7 +168,7 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
|
|
||||||
$choiceList = new EntityChoiceList(
|
$choiceList = new EntityChoiceList(
|
||||||
$this->em,
|
$this->em,
|
||||||
self::SINGLE_IDENT_CLASS,
|
self::SINGLE_INT_ID_CLASS,
|
||||||
'name',
|
'name',
|
||||||
null,
|
null,
|
||||||
array()
|
array()
|
||||||
@ -164,10 +177,10 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
$this->assertSame(array(), $choiceList->getChoices());
|
$this->assertSame(array(), $choiceList->getChoices());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNestedChoicesAreManaged()
|
public function testInitNestedChoices()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
|
|
||||||
// Oh yeah, we're persisting with fire now!
|
// Oh yeah, we're persisting with fire now!
|
||||||
$this->em->persist($entity1);
|
$this->em->persist($entity1);
|
||||||
@ -175,7 +188,7 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
|
|
||||||
$choiceList = new EntityChoiceList(
|
$choiceList = new EntityChoiceList(
|
||||||
$this->em,
|
$this->em,
|
||||||
self::SINGLE_IDENT_CLASS,
|
self::SINGLE_INT_ID_CLASS,
|
||||||
'name',
|
'name',
|
||||||
null,
|
null,
|
||||||
array(
|
array(
|
||||||
@ -192,12 +205,12 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
), $choiceList->getRemainingViews());
|
), $choiceList->getRemainingViews());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGroupBySupportsString()
|
public function testGroupByPropertyPath()
|
||||||
{
|
{
|
||||||
$item1 = new ItemGroupEntity(1, 'Foo', 'Group1');
|
$item1 = new GroupableEntity(1, 'Foo', 'Group1');
|
||||||
$item2 = new ItemGroupEntity(2, 'Bar', 'Group1');
|
$item2 = new GroupableEntity(2, 'Bar', 'Group1');
|
||||||
$item3 = new ItemGroupEntity(3, 'Baz', 'Group2');
|
$item3 = new GroupableEntity(3, 'Baz', 'Group2');
|
||||||
$item4 = new ItemGroupEntity(4, 'Boo!', null);
|
$item4 = new GroupableEntity(4, 'Boo!', null);
|
||||||
|
|
||||||
$this->em->persist($item1);
|
$this->em->persist($item1);
|
||||||
$this->em->persist($item2);
|
$this->em->persist($item2);
|
||||||
@ -206,7 +219,7 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
|
|
||||||
$choiceList = new EntityChoiceList(
|
$choiceList = new EntityChoiceList(
|
||||||
$this->em,
|
$this->em,
|
||||||
self::ITEM_GROUP_CLASS,
|
self::GROUPABLE_CLASS,
|
||||||
'name',
|
'name',
|
||||||
null,
|
null,
|
||||||
array(
|
array(
|
||||||
@ -229,15 +242,15 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
|
|
||||||
public function testGroupByInvalidPropertyPathReturnsFlatChoices()
|
public function testGroupByInvalidPropertyPathReturnsFlatChoices()
|
||||||
{
|
{
|
||||||
$item1 = new ItemGroupEntity(1, 'Foo', 'Group1');
|
$item1 = new GroupableEntity(1, 'Foo', 'Group1');
|
||||||
$item2 = new ItemGroupEntity(2, 'Bar', 'Group1');
|
$item2 = new GroupableEntity(2, 'Bar', 'Group1');
|
||||||
|
|
||||||
$this->em->persist($item1);
|
$this->em->persist($item1);
|
||||||
$this->em->persist($item2);
|
$this->em->persist($item2);
|
||||||
|
|
||||||
$choiceList = new EntityChoiceList(
|
$choiceList = new EntityChoiceList(
|
||||||
$this->em,
|
$this->em,
|
||||||
self::ITEM_GROUP_CLASS,
|
self::GROUPABLE_CLASS,
|
||||||
'name',
|
'name',
|
||||||
null,
|
null,
|
||||||
array(
|
array(
|
||||||
@ -254,105 +267,20 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
), $choiceList->getChoices());
|
), $choiceList->getChoices());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPossibleToProvideShorthandEntityName()
|
public function testInitShorthandEntityName()
|
||||||
{
|
{
|
||||||
$shorthandName = 'SymfonyTestsDoctrine:SingleIdentEntity';
|
$item1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
|
$item2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
$item1 = new SingleIdentEntity(1, 'Foo');
|
|
||||||
$item2 = new SingleIdentEntity(2, 'Bar');
|
|
||||||
|
|
||||||
$this->em->persist($item1);
|
$this->em->persist($item1);
|
||||||
$this->em->persist($item2);
|
$this->em->persist($item2);
|
||||||
|
|
||||||
$choiceList = new EntityChoiceList(
|
$choiceList = new EntityChoiceList(
|
||||||
$this->em,
|
$this->em,
|
||||||
$shorthandName,
|
'SymfonyTestsDoctrine:SingleIntIdEntity'
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
array(),
|
|
||||||
null
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(array(1, 2), $choiceList->getValuesForChoices(array($item1, $item2)));
|
$this->assertEquals(array(1, 2), $choiceList->getValuesForChoices(array($item1, $item2)));
|
||||||
$this->assertEquals(array(1, 2), $choiceList->getIndicesForChoices(array($item1, $item2)));
|
$this->assertEquals(array(1, 2), $choiceList->getIndicesForChoices(array($item1, $item2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ticket #3446
|
|
||||||
public function testGetEmptyArrayChoicesForEmptyValues()
|
|
||||||
{
|
|
||||||
$qb = $this->em->createQueryBuilder()->select('s')->from(self::SINGLE_IDENT_CLASS, 's');
|
|
||||||
$entityLoader = new ORMQueryBuilderLoader($qb);
|
|
||||||
$choiceList = new EntityChoiceList(
|
|
||||||
$this->em,
|
|
||||||
self::SINGLE_IDENT_CLASS,
|
|
||||||
null,
|
|
||||||
$entityLoader
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals(array(), $choiceList->getChoicesForValues(array()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/symfony/symfony/issues/3635
|
|
||||||
public function testSingleNonIntIdFallsBackToGeneration()
|
|
||||||
{
|
|
||||||
$entity1 = new SingleStringIdentEntity('Id 1', 'Foo');
|
|
||||||
$entity2 = new SingleStringIdentEntity('Id 2', 'Bar');
|
|
||||||
|
|
||||||
// Persist for managed state
|
|
||||||
$this->em->persist($entity1);
|
|
||||||
$this->em->persist($entity2);
|
|
||||||
$this->em->flush();
|
|
||||||
|
|
||||||
$choiceList = new EntityChoiceList(
|
|
||||||
$this->em,
|
|
||||||
self::SINGLE_STRING_IDENT_CLASS,
|
|
||||||
'name'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertSame(array(0 => $entity1, 1 => $entity2), $choiceList->getChoices());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testMinusReplacedByUnderscoreInNegativeIntIds()
|
|
||||||
{
|
|
||||||
$entity1 = new SingleIdentEntity(-1, 'Foo');
|
|
||||||
$entity2 = new SingleIdentEntity(1, 'Bar');
|
|
||||||
|
|
||||||
// Persist for managed state
|
|
||||||
$this->em->persist($entity1);
|
|
||||||
$this->em->persist($entity2);
|
|
||||||
$this->em->flush();
|
|
||||||
|
|
||||||
$choiceList = new EntityChoiceList(
|
|
||||||
$this->em,
|
|
||||||
self::SINGLE_IDENT_CLASS,
|
|
||||||
'name'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertSame(array('_1' => $entity1, 1 => $entity2), $choiceList->getChoices());
|
|
||||||
$this->assertSame(array('_1', 1), $choiceList->getIndicesForChoices(array($entity1, $entity2)));
|
|
||||||
$this->assertSame(array('_1', 1), $choiceList->getIndicesForValues(array('-1', '1')));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testMinusReplacedByUnderscoreIfNotLoaded()
|
|
||||||
{
|
|
||||||
$entity1 = new SingleIdentEntity(-1, 'Foo');
|
|
||||||
$entity2 = new SingleIdentEntity(1, 'Bar');
|
|
||||||
|
|
||||||
// Persist for managed state
|
|
||||||
$this->em->persist($entity1);
|
|
||||||
$this->em->persist($entity2);
|
|
||||||
$this->em->flush();
|
|
||||||
|
|
||||||
$choiceList = new EntityChoiceList(
|
|
||||||
$this->em,
|
|
||||||
self::SINGLE_IDENT_CLASS,
|
|
||||||
'name'
|
|
||||||
);
|
|
||||||
|
|
||||||
// no getChoices()!
|
|
||||||
|
|
||||||
$this->assertSame(array('_1', 1), $choiceList->getIndicesForChoices(array($entity1, $entity2)));
|
|
||||||
$this->assertSame(array('_1', 1), $choiceList->getIndicesForValues(array('-1', '1')));
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
class LoadedEntityChoiceListCompositeIdTest extends AbstractEntityChoiceListCompositeIdTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
||||||
|
*/
|
||||||
|
protected function createChoiceList()
|
||||||
|
{
|
||||||
|
$list = parent::createChoiceList();
|
||||||
|
|
||||||
|
// load list
|
||||||
|
$list->getChoices();
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
class LoadedEntityChoiceListSingleIntIdTest extends AbstractEntityChoiceListSingleIntIdTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
||||||
|
*/
|
||||||
|
protected function createChoiceList()
|
||||||
|
{
|
||||||
|
$list = parent::createChoiceList();
|
||||||
|
|
||||||
|
// load list
|
||||||
|
$list->getChoices();
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
class LoadedEntityChoiceListSingleStringIdTest extends AbstractEntityChoiceListSingleStringIdTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
||||||
|
*/
|
||||||
|
protected function createChoiceList()
|
||||||
|
{
|
||||||
|
$list = parent::createChoiceList();
|
||||||
|
|
||||||
|
// load list
|
||||||
|
$list->getChoices();
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
class UnloadedEntityChoiceListCompositeIdTest extends AbstractEntityChoiceListCompositeIdTest
|
||||||
|
{
|
||||||
|
public function testGetIndicesForValuesIgnoresNonExistingValues()
|
||||||
|
{
|
||||||
|
$this->markTestSkipped('Non-existing values are not detected for unloaded choice lists.');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||||
|
|
||||||
|
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
class UnloadedEntityChoiceListCompositeIdWithQueryBuilderTest extends UnloadedEntityChoiceListCompositeIdTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
||||||
|
*/
|
||||||
|
protected function createChoiceList()
|
||||||
|
{
|
||||||
|
$qb = $this->em->createQueryBuilder()->select('s')->from($this->getEntityClass(), 's');
|
||||||
|
$loader = new ORMQueryBuilderLoader($qb);
|
||||||
|
|
||||||
|
return new EntityChoiceList($this->em, $this->getEntityClass(), null, $loader);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
class UnloadedEntityChoiceListSingleIntIdTest extends AbstractEntityChoiceListSingleIntIdTest
|
||||||
|
{
|
||||||
|
public function testGetIndicesForValuesIgnoresNonExistingValues()
|
||||||
|
{
|
||||||
|
$this->markTestSkipped('Non-existing values are not detected for unloaded choice lists.');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||||
|
|
||||||
|
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
class UnloadedEntityChoiceListSingleIntIdWithQueryBuilderTest extends UnloadedEntityChoiceListSingleIntIdTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
||||||
|
*/
|
||||||
|
protected function createChoiceList()
|
||||||
|
{
|
||||||
|
$qb = $this->em->createQueryBuilder()->select('s')->from($this->getEntityClass(), 's');
|
||||||
|
$loader = new ORMQueryBuilderLoader($qb);
|
||||||
|
|
||||||
|
return new EntityChoiceList($this->em, $this->getEntityClass(), null, $loader);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
class UnloadedEntityChoiceListSingleStringIdTest extends AbstractEntityChoiceListSingleStringIdTest
|
||||||
|
{
|
||||||
|
public function testGetIndicesForValuesIgnoresNonExistingValues()
|
||||||
|
{
|
||||||
|
$this->markTestSkipped('Non-existing values are not detected for unloaded choice lists.');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||||
|
|
||||||
|
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
class UnloadedEntityChoiceListSingleStringIdWithQueryBuilderTest extends UnloadedEntityChoiceListSingleStringIdTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
||||||
|
*/
|
||||||
|
protected function createChoiceList()
|
||||||
|
{
|
||||||
|
$qb = $this->em->createQueryBuilder()->select('s')->from($this->getEntityClass(), 's');
|
||||||
|
$loader = new ORMQueryBuilderLoader($qb);
|
||||||
|
|
||||||
|
return new EntityChoiceList($this->em, $this->getEntityClass(), null, $loader);
|
||||||
|
}
|
||||||
|
}
|
@ -89,7 +89,7 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase
|
|||||||
|
|
||||||
foreach ($ids as $id) {
|
foreach ($ids as $id) {
|
||||||
$name = 65 + chr($id % 57);
|
$name = 65 + chr($id % 57);
|
||||||
$this->em->persist(new SingleIdentEntity($id, $name));
|
$this->em->persist(new SingleIntIdEntity($id, $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
|
@ -11,14 +11,14 @@
|
|||||||
|
|
||||||
namespace Symfony\Bridge\Doctrine\Tests\Form\Type;
|
namespace Symfony\Bridge\Doctrine\Tests\Form\Type;
|
||||||
|
|
||||||
|
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||||
use Symfony\Component\Form\Tests\Extension\Core\Type\TypeTestCase;
|
use Symfony\Component\Form\Test\TypeTestCase;
|
||||||
use Symfony\Bridge\Doctrine\Tests\DoctrineOrmTestCase;
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\GroupableEntity;
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\ItemGroupEntity;
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIdentEntity;
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity;
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdentEntity;
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity;
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIdentEntity;
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeStringIdEntity;
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeStringIdentEntity;
|
|
||||||
use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension;
|
use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension;
|
||||||
use Doctrine\ORM\Tools\SchemaTool;
|
use Doctrine\ORM\Tools\SchemaTool;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
@ -26,11 +26,11 @@ use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
|||||||
|
|
||||||
class EntityTypeTest extends TypeTestCase
|
class EntityTypeTest extends TypeTestCase
|
||||||
{
|
{
|
||||||
const ITEM_GROUP_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\ItemGroupEntity';
|
const ITEM_GROUP_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\GroupableEntity';
|
||||||
const SINGLE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIdentEntity';
|
const SINGLE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity';
|
||||||
const SINGLE_STRING_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdentEntity';
|
const SINGLE_STRING_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity';
|
||||||
const COMPOSITE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIdentEntity';
|
const COMPOSITE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity';
|
||||||
const COMPOSITE_STRING_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeStringIdentEntity';
|
const COMPOSITE_STRING_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeStringIdEntity';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Doctrine\ORM\EntityManager
|
* @var \Doctrine\ORM\EntityManager
|
||||||
@ -60,7 +60,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
$this->markTestSkipped('Doctrine ORM is not available.');
|
$this->markTestSkipped('Doctrine ORM is not available.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->em = DoctrineOrmTestCase::createTestEntityManager();
|
$this->em = DoctrineTestHelper::createTestEntityManager();
|
||||||
$this->emRegistry = $this->createRegistryMock('default', $this->em);
|
$this->emRegistry = $this->createRegistryMock('default', $this->em);
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@ -121,8 +121,8 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSetDataToUninitializedEntityWithNonRequired()
|
public function testSetDataToUninitializedEntityWithNonRequired()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
@ -138,8 +138,8 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSetDataToUninitializedEntityWithNonRequiredToString()
|
public function testSetDataToUninitializedEntityWithNonRequiredToString()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
@ -154,8 +154,8 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
|
public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
$qb = $this->em->createQueryBuilder()->select('e')->from(self::SINGLE_IDENT_CLASS, 'e');
|
$qb = $this->em->createQueryBuilder()->select('e')->from(self::SINGLE_IDENT_CLASS, 'e');
|
||||||
@ -283,8 +283,8 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleNonExpandedSingleIdentifier()
|
public function testSubmitSingleNonExpandedSingleIdentifier()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
@ -305,8 +305,8 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleNonExpandedCompositeIdentifier()
|
public function testSubmitSingleNonExpandedCompositeIdentifier()
|
||||||
{
|
{
|
||||||
$entity1 = new CompositeIdentEntity(10, 20, 'Foo');
|
$entity1 = new CompositeIntIdEntity(10, 20, 'Foo');
|
||||||
$entity2 = new CompositeIdentEntity(30, 40, 'Bar');
|
$entity2 = new CompositeIntIdEntity(30, 40, 'Bar');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
@ -328,9 +328,9 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleNonExpandedSingleIdentifier()
|
public function testSubmitMultipleNonExpandedSingleIdentifier()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
$entity3 = new SingleIdentEntity(3, 'Baz');
|
$entity3 = new SingleIntIdEntity(3, 'Baz');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
@ -353,9 +353,9 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleNonExpandedSingleIdentifierForExistingData()
|
public function testSubmitMultipleNonExpandedSingleIdentifierForExistingData()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
$entity3 = new SingleIdentEntity(3, 'Baz');
|
$entity3 = new SingleIntIdEntity(3, 'Baz');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
@ -384,9 +384,9 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleNonExpandedCompositeIdentifier()
|
public function testSubmitMultipleNonExpandedCompositeIdentifier()
|
||||||
{
|
{
|
||||||
$entity1 = new CompositeIdentEntity(10, 20, 'Foo');
|
$entity1 = new CompositeIntIdEntity(10, 20, 'Foo');
|
||||||
$entity2 = new CompositeIdentEntity(30, 40, 'Bar');
|
$entity2 = new CompositeIntIdEntity(30, 40, 'Bar');
|
||||||
$entity3 = new CompositeIdentEntity(50, 60, 'Baz');
|
$entity3 = new CompositeIntIdEntity(50, 60, 'Baz');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
@ -410,9 +410,9 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleNonExpandedCompositeIdentifierExistingData()
|
public function testSubmitMultipleNonExpandedCompositeIdentifierExistingData()
|
||||||
{
|
{
|
||||||
$entity1 = new CompositeIdentEntity(10, 20, 'Foo');
|
$entity1 = new CompositeIntIdEntity(10, 20, 'Foo');
|
||||||
$entity2 = new CompositeIdentEntity(30, 40, 'Bar');
|
$entity2 = new CompositeIntIdEntity(30, 40, 'Bar');
|
||||||
$entity3 = new CompositeIdentEntity(50, 60, 'Baz');
|
$entity3 = new CompositeIntIdEntity(50, 60, 'Baz');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
@ -441,8 +441,8 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleExpanded()
|
public function testSubmitSingleExpanded()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
@ -466,9 +466,9 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleExpanded()
|
public function testSubmitMultipleExpanded()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
$entity3 = new SingleIdentEntity(3, 'Bar');
|
$entity3 = new SingleIntIdEntity(3, 'Bar');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
@ -496,9 +496,9 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testOverrideChoices()
|
public function testOverrideChoices()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
$entity3 = new SingleIdentEntity(3, 'Baz');
|
$entity3 = new SingleIntIdEntity(3, 'Baz');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
@ -520,10 +520,10 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testGroupByChoices()
|
public function testGroupByChoices()
|
||||||
{
|
{
|
||||||
$item1 = new ItemGroupEntity(1, 'Foo', 'Group1');
|
$item1 = new GroupableEntity(1, 'Foo', 'Group1');
|
||||||
$item2 = new ItemGroupEntity(2, 'Bar', 'Group1');
|
$item2 = new GroupableEntity(2, 'Bar', 'Group1');
|
||||||
$item3 = new ItemGroupEntity(3, 'Baz', 'Group2');
|
$item3 = new GroupableEntity(3, 'Baz', 'Group2');
|
||||||
$item4 = new ItemGroupEntity(4, 'Boo!', null);
|
$item4 = new GroupableEntity(4, 'Boo!', null);
|
||||||
|
|
||||||
$this->persist(array($item1, $item2, $item3, $item4));
|
$this->persist(array($item1, $item2, $item3, $item4));
|
||||||
|
|
||||||
@ -547,9 +547,9 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPreferredChoices()
|
public function testPreferredChoices()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
$entity3 = new SingleIdentEntity(3, 'Baz');
|
$entity3 = new SingleIntIdEntity(3, 'Baz');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
@ -566,9 +566,9 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testOverrideChoicesWithPreferredChoices()
|
public function testOverrideChoicesWithPreferredChoices()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
$entity3 = new SingleIdentEntity(3, 'Baz');
|
$entity3 = new SingleIntIdEntity(3, 'Baz');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
@ -586,9 +586,9 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testDisallowChoicesThatAreNotIncludedChoicesSingleIdentifier()
|
public function testDisallowChoicesThatAreNotIncludedChoicesSingleIdentifier()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
$entity3 = new SingleIdentEntity(3, 'Baz');
|
$entity3 = new SingleIntIdEntity(3, 'Baz');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
@ -607,9 +607,9 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testDisallowChoicesThatAreNotIncludedChoicesCompositeIdentifier()
|
public function testDisallowChoicesThatAreNotIncludedChoicesCompositeIdentifier()
|
||||||
{
|
{
|
||||||
$entity1 = new CompositeIdentEntity(10, 20, 'Foo');
|
$entity1 = new CompositeIntIdEntity(10, 20, 'Foo');
|
||||||
$entity2 = new CompositeIdentEntity(30, 40, 'Bar');
|
$entity2 = new CompositeIntIdEntity(30, 40, 'Bar');
|
||||||
$entity3 = new CompositeIdentEntity(50, 60, 'Baz');
|
$entity3 = new CompositeIntIdEntity(50, 60, 'Baz');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
@ -628,9 +628,9 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifier()
|
public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifier()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
$entity3 = new SingleIdentEntity(3, 'Baz');
|
$entity3 = new SingleIntIdEntity(3, 'Baz');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
@ -652,9 +652,9 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testDisallowChoicesThatAreNotIncludedQueryBuilderAsClosureSingleIdentifier()
|
public function testDisallowChoicesThatAreNotIncludedQueryBuilderAsClosureSingleIdentifier()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'Bar');
|
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||||
$entity3 = new SingleIdentEntity(3, 'Baz');
|
$entity3 = new SingleIntIdEntity(3, 'Baz');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
@ -676,9 +676,9 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testDisallowChoicesThatAreNotIncludedQueryBuilderAsClosureCompositeIdentifier()
|
public function testDisallowChoicesThatAreNotIncludedQueryBuilderAsClosureCompositeIdentifier()
|
||||||
{
|
{
|
||||||
$entity1 = new CompositeIdentEntity(10, 20, 'Foo');
|
$entity1 = new CompositeIntIdEntity(10, 20, 'Foo');
|
||||||
$entity2 = new CompositeIdentEntity(30, 40, 'Bar');
|
$entity2 = new CompositeIntIdEntity(30, 40, 'Bar');
|
||||||
$entity3 = new CompositeIdentEntity(50, 60, 'Baz');
|
$entity3 = new CompositeIntIdEntity(50, 60, 'Baz');
|
||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
@ -700,7 +700,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleStringIdentifier()
|
public function testSubmitSingleStringIdentifier()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleStringIdentEntity('foo', 'Foo');
|
$entity1 = new SingleStringIdEntity('foo', 'Foo');
|
||||||
|
|
||||||
$this->persist(array($entity1));
|
$this->persist(array($entity1));
|
||||||
|
|
||||||
@ -721,7 +721,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitCompositeStringIdentifier()
|
public function testSubmitCompositeStringIdentifier()
|
||||||
{
|
{
|
||||||
$entity1 = new CompositeStringIdentEntity('foo1', 'foo2', 'Foo');
|
$entity1 = new CompositeStringIdEntity('foo1', 'foo2', 'Foo');
|
||||||
|
|
||||||
$this->persist(array($entity1));
|
$this->persist(array($entity1));
|
||||||
|
|
||||||
|
@ -11,12 +11,12 @@
|
|||||||
|
|
||||||
namespace Symfony\Bridge\Doctrine\Tests\Security\User;
|
namespace Symfony\Bridge\Doctrine\Tests\Security\User;
|
||||||
|
|
||||||
use Symfony\Bridge\Doctrine\Tests\DoctrineOrmTestCase;
|
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIdentEntity;
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\User;
|
||||||
use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider;
|
use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider;
|
||||||
use Doctrine\ORM\Tools\SchemaTool;
|
use Doctrine\ORM\Tools\SchemaTool;
|
||||||
|
|
||||||
class EntityUserProviderTest extends DoctrineOrmTestCase
|
class EntityUserProviderTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
@ -29,17 +29,17 @@ class EntityUserProviderTest extends DoctrineOrmTestCase
|
|||||||
|
|
||||||
public function testRefreshUserGetsUserByPrimaryKey()
|
public function testRefreshUserGetsUserByPrimaryKey()
|
||||||
{
|
{
|
||||||
$em = $this->createTestEntityManager();
|
$em = DoctrineTestHelper::createTestEntityManager();
|
||||||
$this->createSchema($em);
|
$this->createSchema($em);
|
||||||
|
|
||||||
$user1 = new CompositeIdentEntity(1, 1, 'user1');
|
$user1 = new User(1, 1, 'user1');
|
||||||
$user2 = new CompositeIdentEntity(1, 2, 'user2');
|
$user2 = new User(1, 2, 'user2');
|
||||||
|
|
||||||
$em->persist($user1);
|
$em->persist($user1);
|
||||||
$em->persist($user2);
|
$em->persist($user2);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIdentEntity', 'name');
|
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
|
||||||
|
|
||||||
// try to change the user identity
|
// try to change the user identity
|
||||||
$user1->name = 'user2';
|
$user1->name = 'user2';
|
||||||
@ -49,10 +49,10 @@ class EntityUserProviderTest extends DoctrineOrmTestCase
|
|||||||
|
|
||||||
public function testRefreshUserRequiresId()
|
public function testRefreshUserRequiresId()
|
||||||
{
|
{
|
||||||
$em = $this->createTestEntityManager();
|
$em = DoctrineTestHelper::createTestEntityManager();
|
||||||
|
|
||||||
$user1 = new CompositeIdentEntity(null, null, 'user1');
|
$user1 = new User(null, null, 'user1');
|
||||||
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIdentEntity', 'name');
|
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
|
||||||
|
|
||||||
$this->setExpectedException(
|
$this->setExpectedException(
|
||||||
'InvalidArgumentException',
|
'InvalidArgumentException',
|
||||||
@ -63,17 +63,17 @@ class EntityUserProviderTest extends DoctrineOrmTestCase
|
|||||||
|
|
||||||
public function testRefreshInvalidUser()
|
public function testRefreshInvalidUser()
|
||||||
{
|
{
|
||||||
$em = $this->createTestEntityManager();
|
$em = DoctrineTestHelper::createTestEntityManager();
|
||||||
$this->createSchema($em);
|
$this->createSchema($em);
|
||||||
|
|
||||||
$user1 = new CompositeIdentEntity(1, 1, 'user1');
|
$user1 = new User(1, 1, 'user1');
|
||||||
|
|
||||||
$em->persist($user1);
|
$em->persist($user1);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIdentEntity', 'name');
|
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
|
||||||
|
|
||||||
$user2 = new CompositeIdentEntity(1, 2, 'user2');
|
$user2 = new User(1, 2, 'user2');
|
||||||
$this->setExpectedException(
|
$this->setExpectedException(
|
||||||
'Symfony\Component\Security\Core\Exception\UsernameNotFoundException',
|
'Symfony\Component\Security\Core\Exception\UsernameNotFoundException',
|
||||||
'User with id {"id1":1,"id2":2} not found'
|
'User with id {"id1":1,"id2":2} not found'
|
||||||
@ -83,18 +83,18 @@ class EntityUserProviderTest extends DoctrineOrmTestCase
|
|||||||
|
|
||||||
public function testSupportProxy()
|
public function testSupportProxy()
|
||||||
{
|
{
|
||||||
$em = $this->createTestEntityManager();
|
$em = DoctrineTestHelper::createTestEntityManager();
|
||||||
$this->createSchema($em);
|
$this->createSchema($em);
|
||||||
|
|
||||||
$user1 = new CompositeIdentEntity(1, 1, 'user1');
|
$user1 = new User(1, 1, 'user1');
|
||||||
|
|
||||||
$em->persist($user1);
|
$em->persist($user1);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
$em->clear();
|
$em->clear();
|
||||||
|
|
||||||
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIdentEntity', 'name');
|
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
|
||||||
|
|
||||||
$user2 = $em->getReference('Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIdentEntity', array('id1' => 1, 'id2' => 1));
|
$user2 = $em->getReference('Symfony\Bridge\Doctrine\Tests\Fixtures\User', array('id1' => 1, 'id2' => 1));
|
||||||
$this->assertTrue($provider->supportsClass(get_class($user2)));
|
$this->assertTrue($provider->supportsClass(get_class($user2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ class EntityUserProviderTest extends DoctrineOrmTestCase
|
|||||||
{
|
{
|
||||||
$schemaTool = new SchemaTool($em);
|
$schemaTool = new SchemaTool($em);
|
||||||
$schemaTool->createSchema(array(
|
$schemaTool->createSchema(array(
|
||||||
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIdentEntity'),
|
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\User'),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,12 @@
|
|||||||
|
|
||||||
namespace Symfony\Bridge\Doctrine\Tests\Validator\Constraints;
|
namespace Symfony\Bridge\Doctrine\Tests\Validator\Constraints;
|
||||||
|
|
||||||
use Symfony\Bridge\Doctrine\Tests\DoctrineOrmTestCase;
|
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
|
||||||
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity;
|
||||||
use Symfony\Component\Validator\DefaultTranslator;
|
use Symfony\Component\Validator\DefaultTranslator;
|
||||||
use Symfony\Component\Validator\Tests\Fixtures\FakeMetadataFactory;
|
use Symfony\Component\Validator\Tests\Fixtures\FakeMetadataFactory;
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIdentEntity;
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleIdentEntity;
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNameEntity;
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIdentEntity;
|
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity;
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity;
|
||||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator;
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator;
|
||||||
@ -24,7 +24,7 @@ use Symfony\Component\Validator\Mapping\ClassMetadata;
|
|||||||
use Symfony\Component\Validator\Validator;
|
use Symfony\Component\Validator\Validator;
|
||||||
use Doctrine\ORM\Tools\SchemaTool;
|
use Doctrine\ORM\Tools\SchemaTool;
|
||||||
|
|
||||||
class UniqueValidatorTest extends DoctrineOrmTestCase
|
class UniqueValidatorTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
@ -109,7 +109,7 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
|||||||
public function createValidator($entityManagerName, $em, $validateClass = null, $uniqueFields = null, $errorPath = null, $repositoryMethod = 'findBy', $ignoreNull = true)
|
public function createValidator($entityManagerName, $em, $validateClass = null, $uniqueFields = null, $errorPath = null, $repositoryMethod = 'findBy', $ignoreNull = true)
|
||||||
{
|
{
|
||||||
if (!$validateClass) {
|
if (!$validateClass) {
|
||||||
$validateClass = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIdentEntity';
|
$validateClass = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity';
|
||||||
}
|
}
|
||||||
if (!$uniqueFields) {
|
if (!$uniqueFields) {
|
||||||
$uniqueFields = array('name');
|
$uniqueFields = array('name');
|
||||||
@ -140,9 +140,9 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
|||||||
{
|
{
|
||||||
$schemaTool = new SchemaTool($em);
|
$schemaTool = new SchemaTool($em);
|
||||||
$schemaTool->createSchema(array(
|
$schemaTool->createSchema(array(
|
||||||
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIdentEntity'),
|
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity'),
|
||||||
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleIdentEntity'),
|
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNameEntity'),
|
||||||
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIdentEntity'),
|
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity'),
|
||||||
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity'),
|
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity'),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -153,11 +153,11 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
|||||||
public function testValidateUniqueness()
|
public function testValidateUniqueness()
|
||||||
{
|
{
|
||||||
$entityManagerName = "foo";
|
$entityManagerName = "foo";
|
||||||
$em = $this->createTestEntityManager();
|
$em = DoctrineTestHelper::createTestEntityManager();
|
||||||
$this->createSchema($em);
|
$this->createSchema($em);
|
||||||
$validator = $this->createValidator($entityManagerName, $em);
|
$validator = $this->createValidator($entityManagerName, $em);
|
||||||
|
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
$violationsList = $validator->validate($entity1);
|
$violationsList = $validator->validate($entity1);
|
||||||
$this->assertEquals(0, $violationsList->count(), "No violations found on entity before it is saved to the database.");
|
$this->assertEquals(0, $violationsList->count(), "No violations found on entity before it is saved to the database.");
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
|||||||
$violationsList = $validator->validate($entity1);
|
$violationsList = $validator->validate($entity1);
|
||||||
$this->assertEquals(0, $violationsList->count(), "No violations found on entity after it was saved to the database.");
|
$this->assertEquals(0, $violationsList->count(), "No violations found on entity after it was saved to the database.");
|
||||||
|
|
||||||
$entity2 = new SingleIdentEntity(2, 'Foo');
|
$entity2 = new SingleIntIdEntity(2, 'Foo');
|
||||||
|
|
||||||
$violationsList = $validator->validate($entity2);
|
$violationsList = $validator->validate($entity2);
|
||||||
$this->assertEquals(1, $violationsList->count(), "Violation found on entity with conflicting entity existing in the database.");
|
$this->assertEquals(1, $violationsList->count(), "Violation found on entity with conflicting entity existing in the database.");
|
||||||
@ -181,16 +181,16 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
|||||||
public function testValidateCustomErrorPath()
|
public function testValidateCustomErrorPath()
|
||||||
{
|
{
|
||||||
$entityManagerName = "foo";
|
$entityManagerName = "foo";
|
||||||
$em = $this->createTestEntityManager();
|
$em = DoctrineTestHelper::createTestEntityManager();
|
||||||
$this->createSchema($em);
|
$this->createSchema($em);
|
||||||
$validator = $this->createValidator($entityManagerName, $em, null, null, 'bar');
|
$validator = $this->createValidator($entityManagerName, $em, null, null, 'bar');
|
||||||
|
|
||||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
|
|
||||||
$em->persist($entity1);
|
$em->persist($entity1);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
$entity2 = new SingleIdentEntity(2, 'Foo');
|
$entity2 = new SingleIntIdEntity(2, 'Foo');
|
||||||
|
|
||||||
$violationsList = $validator->validate($entity2);
|
$violationsList = $validator->validate($entity2);
|
||||||
$this->assertEquals(1, $violationsList->count(), "Violation found on entity with conflicting entity existing in the database.");
|
$this->assertEquals(1, $violationsList->count(), "Violation found on entity with conflicting entity existing in the database.");
|
||||||
@ -204,12 +204,12 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
|||||||
public function testValidateUniquenessWithNull()
|
public function testValidateUniquenessWithNull()
|
||||||
{
|
{
|
||||||
$entityManagerName = "foo";
|
$entityManagerName = "foo";
|
||||||
$em = $this->createTestEntityManager();
|
$em = DoctrineTestHelper::createTestEntityManager();
|
||||||
$this->createSchema($em);
|
$this->createSchema($em);
|
||||||
$validator = $this->createValidator($entityManagerName, $em);
|
$validator = $this->createValidator($entityManagerName, $em);
|
||||||
|
|
||||||
$entity1 = new SingleIdentEntity(1, null);
|
$entity1 = new SingleIntIdEntity(1, null);
|
||||||
$entity2 = new SingleIdentEntity(2, null);
|
$entity2 = new SingleIntIdEntity(2, null);
|
||||||
|
|
||||||
$em->persist($entity1);
|
$em->persist($entity1);
|
||||||
$em->persist($entity2);
|
$em->persist($entity2);
|
||||||
@ -222,12 +222,12 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
|||||||
public function testValidateUniquenessWithIgnoreNull()
|
public function testValidateUniquenessWithIgnoreNull()
|
||||||
{
|
{
|
||||||
$entityManagerName = "foo";
|
$entityManagerName = "foo";
|
||||||
$validateClass = 'Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleIdentEntity';
|
$validateClass = 'Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNameEntity';
|
||||||
$em = $this->createTestEntityManager();
|
$em = DoctrineTestHelper::createTestEntityManager();
|
||||||
$this->createSchema($em);
|
$this->createSchema($em);
|
||||||
$validator = $this->createValidator($entityManagerName, $em, $validateClass, array('name', 'name2'), 'bar', 'findby', false);
|
$validator = $this->createValidator($entityManagerName, $em, $validateClass, array('name', 'name2'), 'bar', 'findby', false);
|
||||||
|
|
||||||
$entity1 = new DoubleIdentEntity(1, 'Foo', null);
|
$entity1 = new DoubleNameEntity(1, 'Foo', null);
|
||||||
$violationsList = $validator->validate($entity1);
|
$violationsList = $validator->validate($entity1);
|
||||||
$this->assertEquals(0, $violationsList->count(), "No violations found on entity before it is saved to the database.");
|
$this->assertEquals(0, $violationsList->count(), "No violations found on entity before it is saved to the database.");
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
|||||||
$violationsList = $validator->validate($entity1);
|
$violationsList = $validator->validate($entity1);
|
||||||
$this->assertEquals(0, $violationsList->count(), "No violations found on entity after it was saved to the database.");
|
$this->assertEquals(0, $violationsList->count(), "No violations found on entity after it was saved to the database.");
|
||||||
|
|
||||||
$entity2 = new DoubleIdentEntity(2, 'Foo', null);
|
$entity2 = new DoubleNameEntity(2, 'Foo', null);
|
||||||
|
|
||||||
$violationsList = $validator->validate($entity2);
|
$violationsList = $validator->validate($entity2);
|
||||||
$this->assertEquals(1, $violationsList->count(), "Violation found on entity with conflicting entity existing in the database.");
|
$this->assertEquals(1, $violationsList->count(), "Violation found on entity with conflicting entity existing in the database.");
|
||||||
@ -251,12 +251,12 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
|||||||
public function testValidateUniquenessAfterConsideringMultipleQueryResults()
|
public function testValidateUniquenessAfterConsideringMultipleQueryResults()
|
||||||
{
|
{
|
||||||
$entityManagerName = "foo";
|
$entityManagerName = "foo";
|
||||||
$em = $this->createTestEntityManager();
|
$em = DoctrineTestHelper::createTestEntityManager();
|
||||||
$this->createSchema($em);
|
$this->createSchema($em);
|
||||||
$validator = $this->createValidator($entityManagerName, $em);
|
$validator = $this->createValidator($entityManagerName, $em);
|
||||||
|
|
||||||
$entity1 = new SingleIdentEntity(1, 'foo');
|
$entity1 = new SingleIntIdEntity(1, 'foo');
|
||||||
$entity2 = new SingleIdentEntity(2, 'foo');
|
$entity2 = new SingleIntIdEntity(2, 'foo');
|
||||||
|
|
||||||
$em->persist($entity1);
|
$em->persist($entity1);
|
||||||
$em->persist($entity2);
|
$em->persist($entity2);
|
||||||
@ -280,7 +280,7 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
|||||||
$em = $this->createEntityManagerMock($repository);
|
$em = $this->createEntityManagerMock($repository);
|
||||||
$validator = $this->createValidator($entityManagerName, $em, null, array(), null, 'findByCustom');
|
$validator = $this->createValidator($entityManagerName, $em, null, array(), null, 'findByCustom');
|
||||||
|
|
||||||
$entity1 = new SingleIdentEntity(1, 'foo');
|
$entity1 = new SingleIntIdEntity(1, 'foo');
|
||||||
|
|
||||||
$violationsList = $validator->validate($entity1);
|
$violationsList = $validator->validate($entity1);
|
||||||
$this->assertEquals(0, $violationsList->count(), 'Violation is using custom repository method.');
|
$this->assertEquals(0, $violationsList->count(), 'Violation is using custom repository method.');
|
||||||
@ -288,7 +288,7 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
|||||||
|
|
||||||
public function testValidateUniquenessWithUnrewoundArray()
|
public function testValidateUniquenessWithUnrewoundArray()
|
||||||
{
|
{
|
||||||
$entity = new SingleIdentEntity(1, 'foo');
|
$entity = new SingleIntIdEntity(1, 'foo');
|
||||||
|
|
||||||
$entityManagerName = 'foo';
|
$entityManagerName = 'foo';
|
||||||
$repository = $this->createRepositoryMock();
|
$repository = $this->createRepositoryMock();
|
||||||
@ -318,11 +318,11 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
|||||||
public function testAssociatedEntity()
|
public function testAssociatedEntity()
|
||||||
{
|
{
|
||||||
$entityManagerName = "foo";
|
$entityManagerName = "foo";
|
||||||
$em = $this->createTestEntityManager();
|
$em = DoctrineTestHelper::createTestEntityManager();
|
||||||
$this->createSchema($em);
|
$this->createSchema($em);
|
||||||
$validator = $this->createValidator($entityManagerName, $em, 'Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity', array('single'));
|
$validator = $this->createValidator($entityManagerName, $em, 'Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity', array('single'));
|
||||||
|
|
||||||
$entity1 = new SingleIdentEntity(1, 'foo');
|
$entity1 = new SingleIntIdEntity(1, 'foo');
|
||||||
$associated = new AssociationEntity();
|
$associated = new AssociationEntity();
|
||||||
$associated->single = $entity1;
|
$associated->single = $entity1;
|
||||||
|
|
||||||
@ -349,11 +349,11 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
|||||||
public function testAssociatedCompositeEntity()
|
public function testAssociatedCompositeEntity()
|
||||||
{
|
{
|
||||||
$entityManagerName = "foo";
|
$entityManagerName = "foo";
|
||||||
$em = $this->createTestEntityManager();
|
$em = DoctrineTestHelper::createTestEntityManager();
|
||||||
$this->createSchema($em);
|
$this->createSchema($em);
|
||||||
$validator = $this->createValidator($entityManagerName, $em, 'Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity', array('composite'));
|
$validator = $this->createValidator($entityManagerName, $em, 'Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity', array('composite'));
|
||||||
|
|
||||||
$composite = new CompositeIdentEntity(1, 1, "test");
|
$composite = new CompositeIntIdEntity(1, 1, "test");
|
||||||
$associated = new AssociationEntity();
|
$associated = new AssociationEntity();
|
||||||
$associated->composite = $composite;
|
$associated->composite = $composite;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user