[DoctrineBridge] fixed DoctrineChoiceLoaderTest by removing deprecated factory

This commit is contained in:
Jules Pietri 2016-06-29 12:52:49 +02:00
parent 0439837729
commit 3f86eaece1
1 changed files with 37 additions and 76 deletions

View File

@ -18,18 +18,12 @@ use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ChoiceListFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $factory;
/**
* @var ObjectManager|\PHPUnit_Framework_MockObject_MockObject
*/
@ -98,36 +92,60 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadChoiceList()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
);
$choices = array($this->obj1, $this->obj2, $this->obj3);
$choiceList = new ArrayChoiceList(array());
$value = function () {};
$choiceList = new ArrayChoiceList($choices, $value);
$this->repository->expects($this->once())
->method('findAll')
->willReturn($choices);
$this->factory->expects($this->once())
->method('createListFromChoices')
->with($choices, $value)
->willReturn($choiceList);
$this->assertSame($choiceList, $loader->loadChoiceList($value));
$this->assertEquals($choiceList, $loader->loadChoiceList($value));
// no further loads on subsequent calls
$this->assertSame($choiceList, $loader->loadChoiceList($value));
$this->assertEquals($choiceList, $loader->loadChoiceList($value));
}
/**
* @group legacy
*/
public function testLegacyLoadChoiceList()
{
$factory = $this->getMock('Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface');
$loader = new DoctrineChoiceLoader(
$factory,
$this->om,
$this->class,
$this->idReader
);
$choices = array($this->obj1, $this->obj2, $this->obj3);
$value = function () {};
$choiceList = new ArrayChoiceList($choices, $value);
$this->repository->expects($this->once())
->method('findAll')
->willReturn($choices);
$factory->expects($this->never())
->method('createListFromChoices');
$this->assertEquals($choiceList, $loaded = $loader->loadChoiceList($value));
// no further loads on subsequent calls
$this->assertSame($loaded, $loader->loadChoiceList($value));
}
public function testLoadChoiceListUsesObjectLoaderIfAvailable()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader,
@ -135,7 +153,7 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
);
$choices = array($this->obj1, $this->obj2, $this->obj3);
$choiceList = new ArrayChoiceList(array());
$choiceList = new ArrayChoiceList($choices);
$this->repository->expects($this->never())
->method('findAll');
@ -144,39 +162,27 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
->method('getEntities')
->willReturn($choices);
$this->factory->expects($this->once())
->method('createListFromChoices')
->with($choices)
->willReturn($choiceList);
$this->assertSame($choiceList, $loader->loadChoiceList());
$this->assertEquals($choiceList, $loaded = $loader->loadChoiceList());
// no further loads on subsequent calls
$this->assertSame($choiceList, $loader->loadChoiceList());
$this->assertSame($loaded, $loader->loadChoiceList());
}
public function testLoadValuesForChoices()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
);
$choices = array($this->obj1, $this->obj2, $this->obj3);
$choiceList = new ArrayChoiceList($choices);
$this->repository->expects($this->once())
->method('findAll')
->willReturn($choices);
$this->factory->expects($this->once())
->method('createListFromChoices')
->with($choices)
->willReturn($choiceList);
$this->assertSame(array('1', '2'), $loader->loadValuesForChoices(array($this->obj2, $this->obj3)));
// no further loads on subsequent calls
@ -187,7 +193,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadValuesForChoicesDoesNotLoadIfEmptyChoices()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
@ -196,16 +201,12 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$this->repository->expects($this->never())
->method('findAll');
$this->factory->expects($this->never())
->method('createListFromChoices');
$this->assertSame(array(), $loader->loadValuesForChoices(array()));
}
public function testLoadValuesForChoicesDoesNotLoadIfSingleIntId()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
@ -218,9 +219,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$this->repository->expects($this->never())
->method('findAll');
$this->factory->expects($this->never())
->method('createListFromChoices');
$this->idReader->expects($this->any())
->method('getIdValue')
->with($this->obj2)
@ -232,7 +230,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadValuesForChoicesLoadsIfSingleIntIdAndValueGiven()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
@ -240,7 +237,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$choices = array($this->obj1, $this->obj2, $this->obj3);
$value = function (\stdClass $object) { return $object->name; };
$choiceList = new ArrayChoiceList($choices, $value);
$this->idReader->expects($this->any())
->method('isSingleId')
@ -250,11 +246,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
->method('findAll')
->willReturn($choices);
$this->factory->expects($this->once())
->method('createListFromChoices')
->with($choices, $value)
->willReturn($choiceList);
$this->assertSame(array('B'), $loader->loadValuesForChoices(
array($this->obj2),
$value
@ -264,7 +255,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadValuesForChoicesDoesNotLoadIfValueIsIdReader()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
@ -279,9 +269,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$this->repository->expects($this->never())
->method('findAll');
$this->factory->expects($this->never())
->method('createListFromChoices');
$this->idReader->expects($this->any())
->method('getIdValue')
->with($this->obj2)
@ -296,24 +283,17 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadChoicesForValues()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
);
$choices = array($this->obj1, $this->obj2, $this->obj3);
$choiceList = new ArrayChoiceList($choices);
$this->repository->expects($this->once())
->method('findAll')
->willReturn($choices);
$this->factory->expects($this->once())
->method('createListFromChoices')
->with($choices)
->willReturn($choiceList);
$this->assertSame(array($this->obj2, $this->obj3), $loader->loadChoicesForValues(array('1', '2')));
// no further loads on subsequent calls
@ -324,7 +304,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadChoicesForValuesDoesNotLoadIfEmptyValues()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
@ -333,16 +312,12 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$this->repository->expects($this->never())
->method('findAll');
$this->factory->expects($this->never())
->method('createListFromChoices');
$this->assertSame(array(), $loader->loadChoicesForValues(array()));
}
public function testLoadChoicesForValuesLoadsOnlyChoicesIfSingleIntId()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader,
@ -362,9 +337,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$this->repository->expects($this->never())
->method('findAll');
$this->factory->expects($this->never())
->method('createListFromChoices');
$this->objectLoader->expects($this->once())
->method('getEntitiesByIds')
->with('idField', array(4 => '3', 7 => '2'))
@ -386,7 +358,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadChoicesForValuesLoadsAllIfSingleIntIdAndValueGiven()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
@ -394,7 +365,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$choices = array($this->obj1, $this->obj2, $this->obj3);
$value = function (\stdClass $object) { return $object->name; };
$choiceList = new ArrayChoiceList($choices, $value);
$this->idReader->expects($this->any())
->method('isSingleId')
@ -404,11 +374,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
->method('findAll')
->willReturn($choices);
$this->factory->expects($this->once())
->method('createListFromChoices')
->with($choices, $value)
->willReturn($choiceList);
$this->assertSame(array($this->obj2), $loader->loadChoicesForValues(
array('B'),
$value
@ -418,7 +383,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoadChoicesForValuesLoadsOnlyChoicesIfValueIsIdReader()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader,
@ -439,9 +403,6 @@ class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
$this->repository->expects($this->never())
->method('findAll');
$this->factory->expects($this->never())
->method('createListFromChoices');
$this->objectLoader->expects($this->once())
->method('getEntitiesByIds')
->with('idField', array('2'))