Working on unit tests.
This commit is contained in:
parent
fcc46d6bfd
commit
926a19c5b3
2 changed files with 65 additions and 49 deletions
|
@ -4,8 +4,8 @@ namespace joshtronic;
|
|||
|
||||
class GooglePlaces
|
||||
{
|
||||
public $client = '';
|
||||
private $key = '';
|
||||
private $client = '';
|
||||
private $base_url = 'https://maps.googleapis.com/maps/api/place';
|
||||
private $method = null;
|
||||
private $response = null;
|
||||
|
@ -104,10 +104,7 @@ class GooglePlaces
|
|||
|
||||
if (!in_array($value, array('json', 'xml')))
|
||||
{
|
||||
throw new \Exception('
|
||||
Invalid output, please specify either
|
||||
"json" or "xml".
|
||||
');
|
||||
throw new \Exception('Invalid output, please specify either "json" or "xml".');
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -117,10 +114,7 @@ class GooglePlaces
|
|||
|
||||
if (!in_array($value, array('prominence', 'distance')))
|
||||
{
|
||||
throw new \Exception('
|
||||
Invalid rank by value, please specify
|
||||
either "prominence" or "distance".
|
||||
');
|
||||
throw new \Exception('Invalid rank by value, please specify either "prominence" or "distance".');
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -153,10 +147,7 @@ class GooglePlaces
|
|||
case 'nearbysearch':
|
||||
if (!isset($parameters['location']))
|
||||
{
|
||||
throw new \Exception('
|
||||
You must specify a location before calling
|
||||
nearbysearch().
|
||||
');
|
||||
throw new \Exception('You must specify a location before calling nearbysearch().');
|
||||
}
|
||||
elseif (isset($parameters['rankby']))
|
||||
{
|
||||
|
@ -167,10 +158,7 @@ class GooglePlaces
|
|||
&& !isset($parameters['name'])
|
||||
&& !isset($parameters['types']))
|
||||
{
|
||||
throw new \Exception('
|
||||
You much specify at least one of the
|
||||
following: keyword, name, types.
|
||||
');
|
||||
throw new \Exception('You much specify at least one of the following: keyword, name, types.');
|
||||
}
|
||||
|
||||
if (isset($parameters['radius']))
|
||||
|
@ -182,9 +170,7 @@ class GooglePlaces
|
|||
case 'prominence':
|
||||
if (!isset($parameters['radius']))
|
||||
{
|
||||
throw new \Exception('
|
||||
You must specify a radius.
|
||||
');
|
||||
throw new \Exception('You must specify a radius.');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -195,10 +181,7 @@ class GooglePlaces
|
|||
case 'radarsearch':
|
||||
if (!isset($parameters['location']))
|
||||
{
|
||||
throw new \Exception('
|
||||
You must specify a location before calling
|
||||
nearbysearch().
|
||||
');
|
||||
throw new \Exception('You must specify a location before calling radarsearch().');
|
||||
}
|
||||
elseif (!isset($parameters['radius']))
|
||||
{
|
||||
|
@ -208,10 +191,7 @@ class GooglePlaces
|
|||
&& empty($parameters['name'])
|
||||
&& empty($parameters['types']))
|
||||
{
|
||||
throw new \Exception('
|
||||
A Radar Search request must include at least one
|
||||
of keyword, name, or types.
|
||||
');
|
||||
throw new \Exception('A Radar Search request must include at least one of keyword, name, or types.');
|
||||
}
|
||||
|
||||
if (isset($parameters['rankby']))
|
||||
|
@ -225,10 +205,7 @@ class GooglePlaces
|
|||
if (!(isset($parameters['reference'])
|
||||
^ isset($parameters['placeid'])))
|
||||
{
|
||||
throw new \Exception('
|
||||
You must specify either a placeid or a reference
|
||||
(but not both) before calling details().
|
||||
');
|
||||
throw new \Exception('You must specify either a placeid or a reference (but not both) before calling details().');
|
||||
}
|
||||
|
||||
if (isset($parameters['rankby']))
|
||||
|
@ -268,8 +245,6 @@ class GooglePlaces
|
|||
$querystring .= $variable . '=' . $value;
|
||||
}
|
||||
|
||||
var_dump($this->client);
|
||||
|
||||
$response = $this->client->get($url . '?' . $querystring);
|
||||
|
||||
if ($this->output == 'json')
|
||||
|
@ -316,11 +291,7 @@ class GooglePlaces
|
|||
|| $this->subradius < 200
|
||||
|| ($this->radius / $this->subradius) % 2)
|
||||
{
|
||||
throw new \Exception('
|
||||
Subradius should divide evenly into radius. Also, subradius
|
||||
should be 200 meters or so. (ex: 2000/200 = 10x10 grid. NOT
|
||||
2000/33 = 60.6x60.6 grid. NOT 2000/16 = 125x125 grid)
|
||||
');
|
||||
throw new \Exception('Subradius should divide evenly into radius. Also, subradius should be 200 meters or so. (ex: 2000/200 = 10x10 grid. NOT 2000/33 = 60.6x60.6 grid. NOT 2000/16 = 125x125 grid)');
|
||||
}
|
||||
|
||||
$center = explode(',', $this->location);
|
||||
|
|
|
@ -1,18 +1,22 @@
|
|||
<?php
|
||||
|
||||
//$places = new joshtronic\GooglePlaces('AIzaSyCT6dVNQaPTRsXwDqb1CjoUJncyzGqKDPY');
|
||||
|
||||
require_once '../src/GooglePlaces.php';
|
||||
require_once '../src/GooglePlacesInterface.php';
|
||||
require_once '../src/GooglePlacesClient.php';
|
||||
|
||||
class GooglePlacesTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $places;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->places = new joshtronic\GooglePlaces('');
|
||||
}
|
||||
|
||||
public function testSetVariable()
|
||||
{
|
||||
$places = new joshtronic\GooglePlaces('');
|
||||
$places->foo = 'bar';
|
||||
$this->assertEquals('bar', $places->foo);
|
||||
$this->places->foo = 'bar';
|
||||
$this->assertEquals('bar', $this->places->foo);
|
||||
}
|
||||
|
||||
public function testNearbySearchProximity()
|
||||
|
@ -21,12 +25,53 @@ class GooglePlacesTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
$client->expects($this->exactly(1))
|
||||
->method('get')
|
||||
->will($this->returnValue('some return i expect'));
|
||||
->will($this->returnValue('
|
||||
{
|
||||
"html_attributions" : [],
|
||||
"next_page_token" : "...",
|
||||
"results" : [
|
||||
{ },
|
||||
{ },
|
||||
{ },
|
||||
{ },
|
||||
{ }
|
||||
],
|
||||
"status" : "OK"
|
||||
}
|
||||
'));
|
||||
|
||||
$places = new joshtronic\GooglePlaces('', $client);
|
||||
$places->location = array(-33.86820, 151.1945860);
|
||||
$places->radius = 800;
|
||||
$results = $places->nearbySearch();
|
||||
$this->places->client = $client;
|
||||
$this->places->location = array(-33.86820, 151.1945860);
|
||||
$this->places->radius = 800;
|
||||
$results = $this->places->nearbySearch();
|
||||
|
||||
$this->assertTrue(is_array($results['results']));
|
||||
$this->assertEquals("OK", $results['status']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage You must specify a location before calling nearbysearch().
|
||||
*/
|
||||
public function testNearbySearchWithoutLocation()
|
||||
{
|
||||
$results = $this->places->nearbySearch();
|
||||
}
|
||||
|
||||
public function testMeters2Lng()
|
||||
{
|
||||
$this->assertEquals(
|
||||
0.0010818843545785356,
|
||||
$this->places->meters2lng(100, -33.86820)
|
||||
);
|
||||
}
|
||||
|
||||
public function testMeters2Lat()
|
||||
{
|
||||
$this->assertEquals(
|
||||
0.0008983120716174308,
|
||||
$this->places->meters2lat(100, 151.1945860)
|
||||
);
|
||||
}
|
||||
|
||||
public function testNearbySearchDistance()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue