/** * Load objects * * @throws RuntimeException * @throws Exception\InvalidRepositoryResultException * @return void */ protected function loadObjects() { if (!empty($this->objects)) { return; } $findMethod = (array) $this->getFindMethod(); if (!$findMethod) { $findMethodName = 'findAll'; $repository = $this->objectManager->getRepository($this->targetClass); $objects = $repository->findAll(); } else { if (!isset($findMethod['name'])) { throw new RuntimeException('No method name was set'); } $findMethodName = $findMethod['name']; $findMethodParams = isset($findMethod['params']) ? array_change_key_case($findMethod['params']) : array(); $repository = $this->objectManager->getRepository($this->targetClass); if (!method_exists($repository, $findMethodName)) { throw new RuntimeException(sprintf('Method "%s" could not be found in repository "%s"', $findMethodName, get_class($repository))); } $r = new ReflectionMethod($repository, $findMethodName); $args = array(); foreach ($r->getParameters() as $param) { if (array_key_exists(strtolower($param->getName()), $findMethodParams)) { $args[] = $findMethodParams[strtolower($param->getName())]; } elseif ($param->isDefaultValueAvailable()) { $args[] = $param->getDefaultValue(); } elseif (!$param->isOptional()) { throw new RuntimeException(sprintf('Required parameter "%s" with no default value for method "%s" in repository "%s"' . ' was not provided', $param->getName(), $findMethodName, get_class($repository))); } } $objects = $r->invokeArgs($repository, $args); } GuardUtils::guardForArrayOrTraversable($objects, sprintf('%s::%s() return value', get_class($repository), $findMethodName), 'DoctrineModule\\Form\\Element\\Exception\\InvalidRepositoryResultException'); $this->objects = $objects; }
public function testGuardAgainstNullAllowsNonNull() { $this->assertNull(GuardUtils::guardAgainstNull('foo')); }