Skip to content

Commit

Permalink
Additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
midnite81 committed Jan 9, 2018
1 parent 21a4f9d commit 978fdd8
Showing 1 changed file with 68 additions and 10 deletions.
78 changes: 68 additions & 10 deletions tests/Services/GeoLocationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Midnite81\GeoLocation\Services\GeoLocation;
use Midnite81\GeoLocation\Services\IpLocation;
use Mockery;
use Mockery\Mock;
use PHPUnit\Framework\TestCase;

class GeoLocationTest extends TestCase
Expand All @@ -13,6 +15,11 @@ class GeoLocationTest extends TestCase
*/
protected $geolocation;

/**
* @var GeoLocation
*/
protected $mock;


/**
* @before
Expand All @@ -21,6 +28,9 @@ public function setup()
{
$this->geolocation = new GeoLocation();

$this->mock = Mockery::mock('Midnite81\GeoLocation\Services\GeoLocation[requestData]');
$this->mock->shouldAllowMockingProtectedMethods();
$this->mock->shouldReceive('requestData')->once()->andReturn($this->results());
}

/**
Expand All @@ -40,15 +50,63 @@ public function it_doesnt_except_erroneous_value_as_precision()
$location = $this->geolocation->get('127.0.0.1', 'address');
}

// /**
// * @test
// */
// public function it_accepts_city_as_a_precision()
// {
//
// $location = $this->geolocation->get('127.0.0.1', 'city');
//
// $this->assertInstanceOf(IpLocation::class, $location);
// }
/**
* @test
*/
public function it_accepts_city_as_a_precision()
{

$location = $this->mock->get('127.0.0.1', 'city');

$this->assertInstanceOf(IpLocation::class, $location);
}

/**
* @test
*/
public function it_accepts_country_as_a_precision()
{
$location = $this->mock->get('127.0.0.1', 'country');

$this->assertInstanceOf(IpLocation::class, $location);
}

/**
* @test
*/
public function get_city_returns_data()
{
$location = $this->mock->getCity('127.0.0.1', 'country');

$this->assertInstanceOf(IpLocation::class, $location);
}

/**
* @test
*/
public function get_country_returns_data()
{
$location = $this->mock->getCountry('127.0.0.1', 'country');

$this->assertInstanceOf(IpLocation::class, $location);
}

protected function results()
{
return json_encode([
'statusCode' => '200',
'statusMessage' => 'Success',
'ipAddress' => '127.0.0.1',
'countryCode' => 'gb',
'countryName' => 'England',
'regionName' => 'London',
'cityName' => 'Crystal Palace',
'zipCode' => 'S1 E22',
'latitude' => '50',
'longitude' => '50',
'timeZone' => '+00',
'addressString' => 'Crystal Palace, London, England'
]);
}

}

0 comments on commit 978fdd8

Please sign in to comment.