You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
laravel-geo-layer/tests/Unit/GeocodingServiceTest.php

67 lines
1.9 KiB
PHP

<?php
namespace Unit;
use Ae3\LaravelGeoLayer\app\Services\GeocodingService;
use Ae3\LaravelGeoLayer\Tests\TestCase;
use Mockery;
class GeocodingServiceTest extends TestCase
{
/**
* @var GeocodingService
*/
private GeocodingService $geocodingService;
private $mockedGeocoder;
/**
* Set up the test
*/
public function setUp(): void
{
parent::setUp();
$this->mockedGeocoder = Mockery::mock('overload:Spatie\Geocoder\Geocoder');
// Configurando o mock para esperar a chamada de setApiKey
$this->mockedGeocoder->shouldReceive('setApiKey')->once()->withAnyArgs();
$this->mockedGeocoder->shouldReceive('setRegion')->once()->withAnyArgs();
$this->mockedGeocoder->shouldReceive('setCountry')->once()->withAnyArgs();
$this->mockedGeocoder->shouldReceive('setBounds')->once()->withAnyArgs();
// Configurando o mock para esperar a chamada de getCoordinatesForAddress
$this->mockedGeocoder->shouldReceive('getCoordinatesForAddress')
->once()
->with('Brussels, Belgium')
->andReturn(['lat' => '50.85045', 'lng' => '4.34878']);
$this->geocodingService = new GeocodingService();
}
/**
* Test getCoordinatesForAddress function
*/
public function testGetCoordinatesForAddress(): void
{
// Mocking Geocoder response
$this->mockedGeocoder->shouldReceive('getCoordinatesForAddress')
->once()
->with('Brussels, Belgium')
->andReturn(['lat' => '50.85045', 'lng' => '4.34878']);
// Testing the function
$result = $this->geocodingService->getCoordinatesForAddress('Brussels, Belgium');
$this->assertEquals(['lat' => '50.85045', 'lng' => '4.34878'], $result);
}
/**
* Tear down the test
*/
public function tearDown(): void
{
Mockery::close();
parent::tearDown();
}
}