public function testLoadFromEntityWithSamePropertyValues() { $fooA = new Foo(); $fooA->setBar(1); $fooA->setBaz('baz'); $fooB = new Foo(); $fooB->setBar(2); $fooB->setBaz('baz'); $this->modelManager->expects($this->once())->method('findBy')->will($this->returnValue(array($fooA, $fooB))); $this->modelManager->expects($this->any())->method('getIdentifierValues')->will($this->returnCallback(function (Foo $foo) { return array($foo->getBar()); })); $modelChoiceLoader = new ModelChoiceLoader($this->modelManager, 'Sonata\\AdminBundle\\Tests\\Fixtures\\Entity\\Foo', 'baz'); $expectedChoices = array(1 => 'baz (id: 1)', 2 => 'baz (id: 2)'); $this->assertSame($expectedChoices, $modelChoiceLoader->loadChoiceList()->getOriginalKeys()); }