Skip to content

Commit

Permalink
minor #19222 [DoctrineBridge] fixed DoctrineChoiceLoaderTest by remov…
Browse files Browse the repository at this point in the history
…ing deprecated factory (HeahDude)

This PR was merged into the 3.1 branch.

Discussion
----------

[DoctrineBridge] fixed DoctrineChoiceLoaderTest by removing deprecated factory

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | ~
| License       | MIT
| Doc PR        | ~

Commits
-------

3f86eae [DoctrineBridge] fixed DoctrineChoiceLoaderTest by removing deprecated factory
  • Loading branch information
nicolas-grekas committed Jun 29, 2016
2 parents 0439837 + 3f86eae commit 4976c7f
Showing 1 changed file with 36 additions and 75 deletions.
Expand Up @@ -18,18 +18,12 @@
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
*/
Expand Down Expand Up @@ -98,44 +92,68 @@ protected function setUp()
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->assertEquals($choiceList, $loader->loadChoiceList($value));

$this->assertSame($choiceList, $loader->loadChoiceList($value));
// no further loads on subsequent calls

$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($choiceList, $loader->loadChoiceList($value));
$this->assertSame($loaded, $loader->loadChoiceList($value));
}

public function testLoadChoiceListUsesObjectLoaderIfAvailable()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader,
$this->objectLoader
);

$choices = array($this->obj1, $this->obj2, $this->obj3);
$choiceList = new ArrayChoiceList(array());
$choiceList = new ArrayChoiceList($choices);

$this->repository->expects($this->never())
->method('findAll');
Expand All @@ -144,39 +162,27 @@ public function testLoadChoiceListUsesObjectLoaderIfAvailable()
->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
Expand All @@ -187,7 +193,6 @@ public function testLoadValuesForChoices()
public function testLoadValuesForChoicesDoesNotLoadIfEmptyChoices()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
Expand All @@ -196,16 +201,12 @@ public function testLoadValuesForChoicesDoesNotLoadIfEmptyChoices()
$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
Expand All @@ -218,9 +219,6 @@ public function testLoadValuesForChoicesDoesNotLoadIfSingleIntId()
$this->repository->expects($this->never())
->method('findAll');

$this->factory->expects($this->never())
->method('createListFromChoices');

$this->idReader->expects($this->any())
->method('getIdValue')
->with($this->obj2)
Expand All @@ -232,15 +230,13 @@ public function testLoadValuesForChoicesDoesNotLoadIfSingleIntId()
public function testLoadValuesForChoicesLoadsIfSingleIntIdAndValueGiven()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
);

$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')
Expand All @@ -250,11 +246,6 @@ public function testLoadValuesForChoicesLoadsIfSingleIntIdAndValueGiven()
->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
Expand All @@ -264,7 +255,6 @@ public function testLoadValuesForChoicesLoadsIfSingleIntIdAndValueGiven()
public function testLoadValuesForChoicesDoesNotLoadIfValueIsIdReader()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
Expand All @@ -279,9 +269,6 @@ public function testLoadValuesForChoicesDoesNotLoadIfValueIsIdReader()
$this->repository->expects($this->never())
->method('findAll');

$this->factory->expects($this->never())
->method('createListFromChoices');

$this->idReader->expects($this->any())
->method('getIdValue')
->with($this->obj2)
Expand All @@ -296,24 +283,17 @@ public function testLoadValuesForChoicesDoesNotLoadIfValueIsIdReader()
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
Expand All @@ -324,7 +304,6 @@ public function testLoadChoicesForValues()
public function testLoadChoicesForValuesDoesNotLoadIfEmptyValues()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
Expand All @@ -333,16 +312,12 @@ public function testLoadChoicesForValuesDoesNotLoadIfEmptyValues()
$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,
Expand All @@ -362,9 +337,6 @@ public function testLoadChoicesForValuesLoadsOnlyChoicesIfSingleIntId()
$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'))
Expand All @@ -386,15 +358,13 @@ public function testLoadChoicesForValuesLoadsOnlyChoicesIfSingleIntId()
public function testLoadChoicesForValuesLoadsAllIfSingleIntIdAndValueGiven()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader
);

$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')
Expand All @@ -404,11 +374,6 @@ public function testLoadChoicesForValuesLoadsAllIfSingleIntIdAndValueGiven()
->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
Expand All @@ -418,7 +383,6 @@ public function testLoadChoicesForValuesLoadsAllIfSingleIntIdAndValueGiven()
public function testLoadChoicesForValuesLoadsOnlyChoicesIfValueIsIdReader()
{
$loader = new DoctrineChoiceLoader(
$this->factory,
$this->om,
$this->class,
$this->idReader,
Expand All @@ -439,9 +403,6 @@ public function testLoadChoicesForValuesLoadsOnlyChoicesIfValueIsIdReader()
$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'))
Expand Down

0 comments on commit 4976c7f

Please sign in to comment.