11<?php
22namespace Geocoder \Tests \Provider ;
33
4+ use Geocoder \Tests \TestCase ;
45use Geocoder \Provider \MaxMindBinaryProvider ;
56
6- class MaxMindBinaryProviderTest extends \PHPUnit_Framework_TestCase
7+ class MaxMindBinaryProviderTest extends TestCase
78{
9+ private $ binaryFile ;
10+
11+ public function setUp ()
12+ {
13+ $ this ->binaryFile = __DIR__ . '/fixtures/GeoLiteCity.dat ' ;
14+ }
15+
816 public static function setUpBeforeClass ()
917 {
1018 if (false == function_exists ('geoip_open ' )) {
1119 throw new \PHPUnit_Framework_SkippedTestError ('The maxmind \'s official lib required to run these tests. ' );
1220 }
21+
1322 if (false == function_exists ('GeoIP_record_by_addr ' )) {
1423 throw new \PHPUnit_Framework_SkippedTestError ('The maxmind \'s official lib required to run these tests. ' );
1524 }
@@ -37,11 +46,8 @@ public function testThrowIfNotExistBinaryFileGiven()
3746 */
3847 public function testLocationResultContainsExpectedFields ($ ip )
3948 {
40- $ binaryFile = __DIR__ .'/fixtures/GeoLiteCity.dat ' ;
41-
42- $ provider = new MaxMindBinaryProvider ($ binaryFile );
43-
44- $ result = $ provider ->getGeocodedData ($ ip );
49+ $ provider = new MaxMindBinaryProvider ($ this ->binaryFile );
50+ $ result = $ provider ->getGeocodedData ($ ip );
4551
4652 $ this ->assertInternalType ('array ' , $ result );
4753
@@ -67,11 +73,8 @@ public function testLocationResultContainsExpectedFields($ip)
6773 */
6874 public function testFindLocationByIp ($ ip , $ expectedCity , $ expectedCountry )
6975 {
70- $ binaryFile = __DIR__ .'/fixtures/GeoLiteCity.dat ' ;
71-
72- $ provider = new MaxMindBinaryProvider ($ binaryFile );
73-
74- $ result = $ provider ->getGeocodedData ($ ip );
76+ $ provider = new MaxMindBinaryProvider ($ this ->binaryFile );
77+ $ result = $ provider ->getGeocodedData ($ ip );
7578
7679 $ this ->assertInternalType ('array ' , $ result );
7780
@@ -84,9 +87,7 @@ public function testFindLocationByIp($ip, $expectedCity, $expectedCountry)
8487
8588 public function testGetName ()
8689 {
87- $ binaryFile = __DIR__ .'/fixtures/GeoLiteCity.dat ' ;
88-
89- $ provider = new MaxMindBinaryProvider ($ binaryFile );
90+ $ provider = new MaxMindBinaryProvider ($ this ->binaryFile );
9091
9192 $ this ->assertEquals ('maxmind_binary ' , $ provider ->getName ());
9293 }
@@ -97,9 +98,7 @@ public function testGetName()
9798 */
9899 public function testThrowIfIpAddressCouldNotBeLocated ()
99100 {
100- $ binaryFile = __DIR__ .'/fixtures/GeoLiteCity.dat ' ;
101-
102- $ provider = new MaxMindBinaryProvider ($ binaryFile );
101+ $ provider = new MaxMindBinaryProvider ($ this ->binaryFile );
103102
104103 $ provider ->getGeocodedData ('127.0.0.1 ' );
105104 }
@@ -110,9 +109,7 @@ public function testThrowIfIpAddressCouldNotBeLocated()
110109 */
111110 public function testThrowIfInvalidIpAddressGiven ()
112111 {
113- $ binaryFile = __DIR__ .'/fixtures/GeoLiteCity.dat ' ;
114-
115- $ provider = new MaxMindBinaryProvider ($ binaryFile );
112+ $ provider = new MaxMindBinaryProvider ($ this ->binaryFile );
116113
117114 $ provider ->getGeocodedData ('invalidIp ' );
118115 }
@@ -123,11 +120,8 @@ public function testThrowIfInvalidIpAddressGiven()
123120 */
124121 public function testThrowOnReversedDataMethodUsage ()
125122 {
126- $ binaryFile = __DIR__ .'/fixtures/GeoLiteCity.dat ' ;
127-
128- $ provider = new MaxMindBinaryProvider ($ binaryFile );
123+ $ provider = new MaxMindBinaryProvider ($ this ->binaryFile );
129124
130125 $ provider ->getReversedData (array ());
131126 }
132-
133- }
127+ }
0 commit comments