Skip to content

Commit 0fd1539

Browse files
authored
Merge pull request #140 from geocoder-php/command
Updated the command to support geocoder 4.0
2 parents e761a57 + aa10544 commit 0fd1539

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Command/GeocodeCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Bazinga\GeocoderBundle\Command;
1212

13+
use Geocoder\Query\GeocodeQuery;
1314
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
1415
use Symfony\Component\Console\Input\InputArgument;
1516
use Symfony\Component\Console\Input\InputInterface;
@@ -47,14 +48,14 @@ protected function configure()
4748
*/
4849
protected function execute(InputInterface $input, OutputInterface $output)
4950
{
50-
/** @var $geocoder \Geocoder\Geocoder */
51-
$geocoder = $this->getContainer()->get('bazinga_geocoder.geocoder');
51+
/** @var $geocoder \Geocoder\ProviderAggregator */
52+
$geocoder = $this->getContainer()->get('Geocoder\ProviderAggregator');
5253

5354
if ($input->getOption('provider')) {
5455
$geocoder->using($input->getOption('provider'));
5556
}
5657

57-
$results = $geocoder->geocode($input->getArgument('address'));
58+
$results = $geocoder->geocodeQuery(GeocodeQuery::create($input->getArgument('address')));
5859
$data = $results->first()->toArray();
5960

6061
$max = 0;

Tests/Command/GeocodeCommandTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Geocoder\Model\AddressCollection;
1616
use Geocoder\Model\Coordinates;
1717
use Geocoder\Model\Country;
18+
use Geocoder\ProviderAggregator;
19+
use Geocoder\Query\GeocodeQuery;
1820
use PHPUnit\Framework\TestCase;
1921
use Symfony\Bundle\FrameworkBundle\Console\Application;
2022
use Symfony\Component\Console\Tester\CommandTester;
@@ -40,16 +42,17 @@ public function testExecute()
4042
'countryCode' => $country->getCode(),
4143
]);
4244

43-
$geocoder = $this->getMockBuilder('Geocoder\\ProviderAggregator')->getMock();
45+
$geocoder = $this->getMockBuilder(ProviderAggregator::class)->getMock();
46+
$query = GeocodeQuery::create(self::$address);
4447
$geocoder->expects($this->once())
45-
->method('geocode')
46-
->with(self::$address)
48+
->method('geocodeQuery')
49+
->with($query)
4750
->will($this->returnValue(new AddressCollection([$address])));
4851

4952
$container = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Container')->getMock();
5053
$container->expects($this->once())
5154
->method('get')
52-
->with('bazinga_geocoder.geocoder')
55+
->with(ProviderAggregator::class)
5356
->will($this->returnValue($geocoder));
5457

5558
$kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel')

0 commit comments

Comments
 (0)