55
66/**
77 * @coversDefaultClass \DominionEnterprises\NetAcuity\NetAcuity
8+ * @covers ::__construct
9+ * @covers ::<private>
810 */
911final class NetAcuityTest extends PHPUnit_Framework_TestCase
1012{
@@ -25,11 +27,7 @@ public function createNonIntApiId()
2527 * Verify that geo lookup works.
2628 *
2729 * @test
28- * @covers ::__construct
2930 * @covers ::getGeo
30- * @covers ::_buildQuery
31- * @covers ::_query
32- * @covers ::_parseResponse
3331 */
3432 public function getGeo ()
3533 {
@@ -74,7 +72,6 @@ public function getGeo()
7472 * Verify that ip address must be a string.
7573 *
7674 * @test
77- * @covers ::__construct
7875 * @covers ::getGeo
7976 * @expectedException InvalidArgumentException
8077 */
@@ -84,4 +81,68 @@ public function getGeoNonStringIp()
8481 $ client = new NetAcuity ($ socket , 1 );
8582 $ client ->getGeo (1 );
8683 }
84+
85+ /**
86+ * @test
87+ * @covers ::getGeo
88+ * @expectedException \UnexpectedValueException
89+ * @expectedExceptionMessage Net acuity returned less than 22 fields
90+ */
91+ public function getGeoNotEnoughFields ()
92+ {
93+ $ socket = $ this ->getMockBuilder ('\Socket\Raw\Socket ' )->disableOriginalConstructor ()->setMethods (['write ' , 'read ' ])->getMock ();
94+ $ socket ->expects ($ this ->once ())->method ('write ' )->with ("4;1;1.2.3.4 \r\n" )->will ($ this ->returnValue (13 ));
95+ $ socket ->expects ($ this ->once ())->method ('read ' )->with (1024 )->will (
96+ $ this ->returnValue ('xxxxUSA;something;reserved;broadband;2;123.456;789.101;12345;112;1314;1516;1;US;1;123;2;3;4;5;6;7 ' )
97+ );
98+
99+ $ client = new NetAcuity ($ socket , 1 );
100+ $ client ->getGeo ('1.2.3.4 ' );
101+ }
102+
103+ /**
104+ *
105+ * @test
106+ * @covers ::getGeo
107+ */
108+ public function getGeoWithExtraField ()
109+ {
110+ $ socket = $ this ->getMockBuilder ('\Socket\Raw\Socket ' )->disableOriginalConstructor ()->setMethods (['write ' , 'read ' ])->getMock ();
111+ $ socket ->expects ($ this ->once ())->method ('write ' )->with ("4;1;1.2.3.4 \r\n" )->will ($ this ->returnValue (13 ));
112+ $ socket ->expects ($ this ->once ())->method ('read ' )->with (1024 )->will (
113+ $ this ->returnValue (
114+ 'xxxxUSA;something;reserved;broadband;2;123.456;789.101;12345;112;1314;1516;1;US;1;123;2;3;4;5;6;7;UTC;extra dataxxx '
115+ )
116+ );
117+
118+ $ client = new NetAcuity ($ socket , 1 );
119+
120+ $ this ->assertSame (
121+ [
122+ 'country ' => 'USA ' ,
123+ 'region ' => 'something ' ,
124+ 'city ' => 'reserved ' ,
125+ 'conn-speed ' => 'broadband ' ,
126+ 'metro-code ' => '2 ' ,
127+ 'latitude ' => '123.456 ' ,
128+ 'longitude ' => '789.101 ' ,
129+ 'zip-code ' => '12345 ' ,
130+ 'country-code ' => '112 ' ,
131+ 'region-code ' => '1314 ' ,
132+ 'city-code ' => '1516 ' ,
133+ 'continent-code ' => '1 ' ,
134+ 'two-letter-country ' => 'US ' ,
135+ 'internal-code ' => '1 ' ,
136+ 'area-code ' => '123 ' ,
137+ 'country-conf ' => '2 ' ,
138+ 'region-conf ' => '3 ' ,
139+ 'city-conf ' => '4 ' ,
140+ 'postal-conf ' => '5 ' ,
141+ 'gmt-offset ' => '6 ' ,
142+ 'in-dist ' => '7 ' ,
143+ 'timezone-name ' => 'UTC ' ,
144+ ],
145+ $ client ->getGeo ('1.2.3.4 ' )
146+ );
147+ }
87148}
0 commit comments