private function createGeolocator(OutputInterface $output, InputInterface $input) { $providerId = $input->getOption(self::PROVIDER_ARGUMENT); $geolocator = new VisitorGeolocator(LocationProvider::getProviderById($providerId) ?: null); $usedProvider = $geolocator->getProvider(); if (!$usedProvider->isAvailable()) { throw new \InvalidArgumentException("The provider '{$providerId}' is not currently available, please make sure it is configured correctly."); } $isWorkingOrErrorMessage = $usedProvider->isWorking(); if ($isWorkingOrErrorMessage !== true) { $errorMessage = "The provider '{$providerId}' does not appear to be working correctly. Details: {$isWorkingOrErrorMessage}"; $forceGeolocation = $input->getOption(self::FORCE_OPTION); if ($forceGeolocation) { $output->writeln("<error>{$errorMessage}</error>"); $output->writeln("<comment>Ignoring location provider issue, geolocating anyway due to --force option.</comment>"); } else { throw new \InvalidArgumentException($errorMessage); } } return $geolocator; }
public function test_get_shouldReturnCurrentProvider_IfCurrentProviderIsSet() { Cache::setCacheGeneral(array('currentLocationProviderId' => MockLocationProvider::ID)); $geolocator = new VisitorGeolocator(); $this->assertEquals(MockLocationProvider::ID, $geolocator->getProvider()->getId()); }