From 9cb8f23e114e8b9be7b420336d65724f585f4a1a Mon Sep 17 00:00:00 2001 From: Antoine Corcy Date: Mon, 18 Mar 2013 11:21:58 +0100 Subject: [PATCH] Fixed: tests and enhanced test cover --- tests/Geocoder/Tests/GeocoderTest.php | 18 +++++++++- .../Provider/OpenStreetMapsProviderTest.php | 2 +- tests/Geocoder/Tests/Result/GeocodedTest.php | 34 +++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/tests/Geocoder/Tests/GeocoderTest.php b/tests/Geocoder/Tests/GeocoderTest.php index 8fe045ead..fb43db134 100644 --- a/tests/Geocoder/Tests/GeocoderTest.php +++ b/tests/Geocoder/Tests/GeocoderTest.php @@ -105,7 +105,7 @@ public function testGeocodeReturnsInstanceOfResultInterface() $this->assertInstanceOf('Geocoder\Result\Geocoded', $this->geocoder->geocode('foobar')); } - public function testEmpty() + public function testGeocodeEmpty() { $this->geocoder->registerProvider(new MockProviderWithRequestCount('test2')); $this->assertEmptyResult($this->geocoder->geocode('')); @@ -114,6 +114,22 @@ public function testEmpty() $this->assertEquals(0, $this->geocoder->getProvider('test2')->geocodeCount); } + public function testReverseReturnsInstanceOfResultInterface() + { + $this->geocoder->registerProvider(new MockProvider('test1')); + $this->assertInstanceOf('Geocoder\Result\ResultInterface', $this->geocoder->reverse(1, 2)); + $this->assertInstanceOf('Geocoder\Result\Geocoded', $this->geocoder->reverse(1, 2)); + } + + public function testReverseEmpty() + { + $this->geocoder->registerProvider(new MockProviderWithRequestCount('test2')); + $this->assertEmptyResult($this->geocoder->reverse('', '')); + $this->assertEquals(0, $this->geocoder->getProvider('test2')->geocodeCount); + $this->assertEmptyResult($this->geocoder->reverse(null, null)); + $this->assertEquals(0, $this->geocoder->getProvider('test2')->geocodeCount); + } + public function testUseCustomResultFactory() { $factoryMock = $this->getMock('Geocoder\Result\ResultFactory'); diff --git a/tests/Geocoder/Tests/Provider/OpenStreetMapsProviderTest.php b/tests/Geocoder/Tests/Provider/OpenStreetMapsProviderTest.php index 8f29ba877..6310dbf1b 100644 --- a/tests/Geocoder/Tests/Provider/OpenStreetMapsProviderTest.php +++ b/tests/Geocoder/Tests/Provider/OpenStreetMapsProviderTest.php @@ -193,7 +193,7 @@ public function testGetGeocodedDataWithRealIPv4WithLocale() $this->assertEquals(43.6156005859375, $result['bounds']['north'], '', 0.01); $this->assertEquals(1.45262920856476, $result['bounds']['east'], '', 0.01); $this->assertNull($result['streetNumber']); - $this->assertEquals('Avenue de Lyon', $result['streetName']); + $this->assertEquals('Rue du Faubourg Bonnefoy', $result['streetName']); $this->assertEquals(31506, $result['zipcode']); $this->assertEquals(4, $result['cityDistrict']); $this->assertEquals('Toulouse', $result['city']); diff --git a/tests/Geocoder/Tests/Result/GeocodedTest.php b/tests/Geocoder/Tests/Result/GeocodedTest.php index 81df25619..1c12a8908 100644 --- a/tests/Geocoder/Tests/Result/GeocodedTest.php +++ b/tests/Geocoder/Tests/Result/GeocodedTest.php @@ -29,17 +29,26 @@ public function testFromArray() 'east' => 0.1 ), 'city' => 'FOo CITY', + 'cityDistrict' => 'fOo city District', + 'streetName' => 'foo bar street', 'zipcode' => '65943', 'region' => 'FOO region', + 'county' => 'foo county', + 'countyCode' => 'foo', 'regionCode' => 'FOO', 'country' => 'FOO Country', + 'countryCode' => 'foo', 'timezone' => 'FOO/Timezone' ); $this->geocoded->fromArray($array); + $coordinates = $this->geocoded->getCoordinates(); $bounds = $this->geocoded->getBounds(); + $this->assertTrue(is_array($coordinates)); + $this->assertEquals(0.001, $coordinates[0]); + $this->assertEquals(1, $coordinates[1]); $this->assertEquals(0.001, $this->geocoded->getLatitude()); $this->assertEquals(1, $this->geocoded->getLongitude()); $this->assertArrayHasKey('south', $bounds); @@ -51,9 +60,14 @@ public function testFromArray() $this->assertEquals(3, $bounds['north']); $this->assertEquals(0.1, $bounds['east']); $this->assertEquals('Foo City', $this->geocoded->getCity()); + $this->assertEquals('Foo City District', $this->geocoded->getCityDistrict()); + $this->assertEquals('Foo Bar Street', $this->geocoded->getStreetName()); $this->assertEquals('65943', $this->geocoded->getZipcode()); $this->assertEquals('Foo Region', $this->geocoded->getRegion()); + $this->assertEquals('Foo County', $this->geocoded->getCounty()); + $this->assertEquals('FOO', $this->geocoded->getCountyCode()); $this->assertEquals('Foo Country', $this->geocoded->getCountry()); + $this->assertEquals('FOO', $this->geocoded->getCountryCode()); $this->assertEquals('FOO/Timezone', $this->geocoded->getTimezone()); $this->assertEquals('FOO', $this->geocoded->getRegionCode()); } @@ -235,4 +249,24 @@ public function testFromArrayWithLettersInStreetNumber() $this->geocoded->fromArray($array); $this->assertEquals('1A', $this->geocoded->getStreetNumber()); } + + public function testLowerizeViaReflection() + { + $method = new \ReflectionMethod( + $this->geocoded, 'lowerize' + ); + $method->setAccessible(true); + + $this->assertEquals('foo', $method->invoke($this->geocoded, 'FOO')); + } + + public function testUpperizeViaReflection() + { + $method = new \ReflectionMethod( + $this->geocoded, 'upperize' + ); + $method->setAccessible(true); + + $this->assertEquals('FOO', $method->invoke($this->geocoded, 'foo')); + } }