Skip to content

Commit 7d59499

Browse files
committed
[DoctrineBridge] fixed DoctrineChoiceLoaderTest by removing deprecated factory
1 parent 5128cd3 commit 7d59499

File tree

1 file changed

+33
-75
lines changed

1 file changed

+33
-75
lines changed

src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php

Lines changed: 33 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,12 @@
1818
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
1919
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
2020
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
21-
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
2221

2322
/**
2423
* @author Bernhard Schussek <bschussek@gmail.com>
2524
*/
2625
class DoctrineChoiceLoaderTest extends \PHPUnit_Framework_TestCase
2726
{
28-
/**
29-
* @var ChoiceListFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
30-
*/
31-
private $factory;
32-
3327
/**
3428
* @var ObjectManager|\PHPUnit_Framework_MockObject_MockObject
3529
*/
@@ -98,44 +92,65 @@ protected function setUp()
9892
public function testLoadChoiceList()
9993
{
10094
$loader = new DoctrineChoiceLoader(
101-
$this->factory,
10295
$this->om,
10396
$this->class,
10497
$this->idReader
10598
);
10699

107100
$choices = array($this->obj1, $this->obj2, $this->obj3);
108-
$choiceList = new ArrayChoiceList(array());
109101
$value = function () {};
102+
$choiceList = new ArrayChoiceList($choices, $value);
110103

111104
$this->repository->expects($this->once())
112105
->method('findAll')
113106
->willReturn($choices);
114107

115-
$this->factory->expects($this->once())
116-
->method('createListFromChoices')
117-
->with($choices, $value)
118-
->willReturn($choiceList);
108+
$this->assertEquals($choiceList, $loader->loadChoiceList($value));
109+
110+
// no further loads on subsequent calls
111+
112+
$this->assertEquals($choiceList, $loader->loadChoiceList($value));
113+
}
114+
115+
public function testLegacyLoadChoiceList()
116+
{
117+
$factory = $this->getMock('Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface');
118+
$loader = new DoctrineChoiceLoader(
119+
$factory,
120+
$this->om,
121+
$this->class,
122+
$this->idReader
123+
);
124+
125+
$choices = array($this->obj1, $this->obj2, $this->obj3);
126+
$value = function () {};
127+
$choiceList = new ArrayChoiceList($choices, $value);
128+
129+
$this->repository->expects($this->once())
130+
->method('findAll')
131+
->willReturn($choices);
119132

120-
$this->assertSame($choiceList, $loader->loadChoiceList($value));
133+
$factory->expects($this->never())
134+
->method('createListFromChoices');
135+
136+
$this->assertEquals($choiceList, $loaded = $loader->loadChoiceList($value));
121137

122138
// no further loads on subsequent calls
123139

124-
$this->assertSame($choiceList, $loader->loadChoiceList($value));
140+
$this->assertSame($loaded, $loader->loadChoiceList($value));
125141
}
126142

127143
public function testLoadChoiceListUsesObjectLoaderIfAvailable()
128144
{
129145
$loader = new DoctrineChoiceLoader(
130-
$this->factory,
131146
$this->om,
132147
$this->class,
133148
$this->idReader,
134149
$this->objectLoader
135150
);
136151

137152
$choices = array($this->obj1, $this->obj2, $this->obj3);
138-
$choiceList = new ArrayChoiceList(array());
153+
$choiceList = new ArrayChoiceList($choices);
139154

140155
$this->repository->expects($this->never())
141156
->method('findAll');
@@ -144,39 +159,27 @@ public function testLoadChoiceListUsesObjectLoaderIfAvailable()
144159
->method('getEntities')
145160
->willReturn($choices);
146161

147-
$this->factory->expects($this->once())
148-
->method('createListFromChoices')
149-
->with($choices)
150-
->willReturn($choiceList);
151-
152-
$this->assertSame($choiceList, $loader->loadChoiceList());
162+
$this->assertEquals($choiceList, $loaded = $loader->loadChoiceList());
153163

154164
// no further loads on subsequent calls
155165

156-
$this->assertSame($choiceList, $loader->loadChoiceList());
166+
$this->assertSame($loaded, $loader->loadChoiceList());
157167
}
158168

159169
public function testLoadValuesForChoices()
160170
{
161171
$loader = new DoctrineChoiceLoader(
162-
$this->factory,
163172
$this->om,
164173
$this->class,
165174
$this->idReader
166175
);
167176

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

171179
$this->repository->expects($this->once())
172180
->method('findAll')
173181
->willReturn($choices);
174182

175-
$this->factory->expects($this->once())
176-
->method('createListFromChoices')
177-
->with($choices)
178-
->willReturn($choiceList);
179-
180183
$this->assertSame(array('1', '2'), $loader->loadValuesForChoices(array($this->obj2, $this->obj3)));
181184

182185
// no further loads on subsequent calls
@@ -187,7 +190,6 @@ public function testLoadValuesForChoices()
187190
public function testLoadValuesForChoicesDoesNotLoadIfEmptyChoices()
188191
{
189192
$loader = new DoctrineChoiceLoader(
190-
$this->factory,
191193
$this->om,
192194
$this->class,
193195
$this->idReader
@@ -196,16 +198,12 @@ public function testLoadValuesForChoicesDoesNotLoadIfEmptyChoices()
196198
$this->repository->expects($this->never())
197199
->method('findAll');
198200

199-
$this->factory->expects($this->never())
200-
->method('createListFromChoices');
201-
202201
$this->assertSame(array(), $loader->loadValuesForChoices(array()));
203202
}
204203

205204
public function testLoadValuesForChoicesDoesNotLoadIfSingleIntId()
206205
{
207206
$loader = new DoctrineChoiceLoader(
208-
$this->factory,
209207
$this->om,
210208
$this->class,
211209
$this->idReader
@@ -218,9 +216,6 @@ public function testLoadValuesForChoicesDoesNotLoadIfSingleIntId()
218216
$this->repository->expects($this->never())
219217
->method('findAll');
220218

221-
$this->factory->expects($this->never())
222-
->method('createListFromChoices');
223-
224219
$this->idReader->expects($this->any())
225220
->method('getIdValue')
226221
->with($this->obj2)
@@ -232,15 +227,13 @@ public function testLoadValuesForChoicesDoesNotLoadIfSingleIntId()
232227
public function testLoadValuesForChoicesLoadsIfSingleIntIdAndValueGiven()
233228
{
234229
$loader = new DoctrineChoiceLoader(
235-
$this->factory,
236230
$this->om,
237231
$this->class,
238232
$this->idReader
239233
);
240234

241235
$choices = array($this->obj1, $this->obj2, $this->obj3);
242236
$value = function (\stdClass $object) { return $object->name; };
243-
$choiceList = new ArrayChoiceList($choices, $value);
244237

245238
$this->idReader->expects($this->any())
246239
->method('isSingleId')
@@ -250,11 +243,6 @@ public function testLoadValuesForChoicesLoadsIfSingleIntIdAndValueGiven()
250243
->method('findAll')
251244
->willReturn($choices);
252245

253-
$this->factory->expects($this->once())
254-
->method('createListFromChoices')
255-
->with($choices, $value)
256-
->willReturn($choiceList);
257-
258246
$this->assertSame(array('B'), $loader->loadValuesForChoices(
259247
array($this->obj2),
260248
$value
@@ -264,7 +252,6 @@ public function testLoadValuesForChoicesLoadsIfSingleIntIdAndValueGiven()
264252
public function testLoadValuesForChoicesDoesNotLoadIfValueIsIdReader()
265253
{
266254
$loader = new DoctrineChoiceLoader(
267-
$this->factory,
268255
$this->om,
269256
$this->class,
270257
$this->idReader
@@ -279,9 +266,6 @@ public function testLoadValuesForChoicesDoesNotLoadIfValueIsIdReader()
279266
$this->repository->expects($this->never())
280267
->method('findAll');
281268

282-
$this->factory->expects($this->never())
283-
->method('createListFromChoices');
284-
285269
$this->idReader->expects($this->any())
286270
->method('getIdValue')
287271
->with($this->obj2)
@@ -296,24 +280,17 @@ public function testLoadValuesForChoicesDoesNotLoadIfValueIsIdReader()
296280
public function testLoadChoicesForValues()
297281
{
298282
$loader = new DoctrineChoiceLoader(
299-
$this->factory,
300283
$this->om,
301284
$this->class,
302285
$this->idReader
303286
);
304287

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

308290
$this->repository->expects($this->once())
309291
->method('findAll')
310292
->willReturn($choices);
311293

312-
$this->factory->expects($this->once())
313-
->method('createListFromChoices')
314-
->with($choices)
315-
->willReturn($choiceList);
316-
317294
$this->assertSame(array($this->obj2, $this->obj3), $loader->loadChoicesForValues(array('1', '2')));
318295

319296
// no further loads on subsequent calls
@@ -324,7 +301,6 @@ public function testLoadChoicesForValues()
324301
public function testLoadChoicesForValuesDoesNotLoadIfEmptyValues()
325302
{
326303
$loader = new DoctrineChoiceLoader(
327-
$this->factory,
328304
$this->om,
329305
$this->class,
330306
$this->idReader
@@ -333,16 +309,12 @@ public function testLoadChoicesForValuesDoesNotLoadIfEmptyValues()
333309
$this->repository->expects($this->never())
334310
->method('findAll');
335311

336-
$this->factory->expects($this->never())
337-
->method('createListFromChoices');
338-
339312
$this->assertSame(array(), $loader->loadChoicesForValues(array()));
340313
}
341314

342315
public function testLoadChoicesForValuesLoadsOnlyChoicesIfSingleIntId()
343316
{
344317
$loader = new DoctrineChoiceLoader(
345-
$this->factory,
346318
$this->om,
347319
$this->class,
348320
$this->idReader,
@@ -362,9 +334,6 @@ public function testLoadChoicesForValuesLoadsOnlyChoicesIfSingleIntId()
362334
$this->repository->expects($this->never())
363335
->method('findAll');
364336

365-
$this->factory->expects($this->never())
366-
->method('createListFromChoices');
367-
368337
$this->objectLoader->expects($this->once())
369338
->method('getEntitiesByIds')
370339
->with('idField', array(4 => '3', 7 => '2'))
@@ -386,15 +355,13 @@ public function testLoadChoicesForValuesLoadsOnlyChoicesIfSingleIntId()
386355
public function testLoadChoicesForValuesLoadsAllIfSingleIntIdAndValueGiven()
387356
{
388357
$loader = new DoctrineChoiceLoader(
389-
$this->factory,
390358
$this->om,
391359
$this->class,
392360
$this->idReader
393361
);
394362

395363
$choices = array($this->obj1, $this->obj2, $this->obj3);
396364
$value = function (\stdClass $object) { return $object->name; };
397-
$choiceList = new ArrayChoiceList($choices, $value);
398365

399366
$this->idReader->expects($this->any())
400367
->method('isSingleId')
@@ -404,11 +371,6 @@ public function testLoadChoicesForValuesLoadsAllIfSingleIntIdAndValueGiven()
404371
->method('findAll')
405372
->willReturn($choices);
406373

407-
$this->factory->expects($this->once())
408-
->method('createListFromChoices')
409-
->with($choices, $value)
410-
->willReturn($choiceList);
411-
412374
$this->assertSame(array($this->obj2), $loader->loadChoicesForValues(
413375
array('B'),
414376
$value
@@ -418,7 +380,6 @@ public function testLoadChoicesForValuesLoadsAllIfSingleIntIdAndValueGiven()
418380
public function testLoadChoicesForValuesLoadsOnlyChoicesIfValueIsIdReader()
419381
{
420382
$loader = new DoctrineChoiceLoader(
421-
$this->factory,
422383
$this->om,
423384
$this->class,
424385
$this->idReader,
@@ -439,9 +400,6 @@ public function testLoadChoicesForValuesLoadsOnlyChoicesIfValueIsIdReader()
439400
$this->repository->expects($this->never())
440401
->method('findAll');
441402

442-
$this->factory->expects($this->never())
443-
->method('createListFromChoices');
444-
445403
$this->objectLoader->expects($this->once())
446404
->method('getEntitiesByIds')
447405
->with('idField', array('2'))

0 commit comments

Comments
 (0)