/** * {@inheritdoc} */ protected function createChoiceLoader($group = false) { $objects = $this->objects; $this->objectLoader->expects($this->any())->method('getSize')->will($this->returnValue(count($objects))); $this->objectLoader->expects($this->any())->method('getEntities')->will($this->returnCallback(function () use($objects) { $values = array(); foreach ($objects as $object) { $values[$object->getLabel()] = $object; } return $values; })); $this->objectLoader->expects($this->any())->method('getPaginatedEntities')->will($this->returnCallback(function ($pageSize, $pageNumber) use($objects) { $values = array(); if (is_int($pageSize) && is_int($pageNumber)) { $values[$objects[1]->getLabel()] = $objects[1]; $values[$objects[2]->getLabel()] = $objects[2]; } return $values; })); $this->objectLoader->expects($this->any())->method('getEntitiesByIds')->will($this->returnCallback(function ($idField, $values) use($objects) { $entities = array(); foreach ($values as $id) { if (isset($objects[$id]) && is_string($idField)) { $entities[$id] = $objects[$id]; } } return $entities; })); $this->idReader->expects($this->any())->method('getIdField')->will($this->returnValue('id')); $this->idReader->expects($this->any())->method('isSingleId')->will($this->returnValue(true)); $this->idReader->expects($this->any())->method('getIdValue')->will($this->returnCallback(function ($value) use($objects) { foreach ($objects as $i => $object) { if ($object === $value) { return $i; } } throw new RuntimeException('MOCK_EXCEPTION'); })); return new AjaxDoctrineChoiceLoader($this->objectLoader, $this->idReader, 'label'); }
/** * {@inheritdoc} */ public function reset() { $this->objectLoader->reset(); $this->objectLoader->setSearch((string) $this->label, $this->getSearch()); return $this; }