Overview

Namespaces

  • GeoIp2
    • Database
    • Exception
    • Model
    • Record
    • Test
      • Database
      • Model
      • WebService
    • WebService
  • MaxMind
    • MinFraud
      • Model
  • PHP

Classes

  • GeoIp2\Database\Reader
  • GeoIp2\Model\AnonymousIp
  • GeoIp2\Model\Asn
  • GeoIp2\Model\City
  • GeoIp2\Model\ConnectionType
  • GeoIp2\Model\Country
  • GeoIp2\Model\Domain
  • GeoIp2\Model\Enterprise
  • GeoIp2\Model\Insights
  • GeoIp2\Model\Isp
  • GeoIp2\Record\AbstractPlaceRecord
  • GeoIp2\Record\AbstractRecord
  • GeoIp2\Record\City
  • GeoIp2\Record\Continent
  • GeoIp2\Record\Country
  • GeoIp2\Record\Location
  • GeoIp2\Record\MaxMind
  • GeoIp2\Record\Postal
  • GeoIp2\Record\RepresentedCountry
  • GeoIp2\Record\Subdivision
  • GeoIp2\Record\Traits
  • GeoIp2\Test\Database\ReaderTest
  • GeoIp2\Test\Model\CountryTest
  • GeoIp2\Test\Model\InsightsTest
  • GeoIp2\Test\Model\NameTest
  • GeoIp2\Test\WebService\ClientTest
  • GeoIp2\WebService\Client
  • MaxMind\MinFraud
  • MaxMind\MinFraud\Model\Address
  • MaxMind\MinFraud\Model\BillingAddress
  • MaxMind\MinFraud\Model\CreditCard
  • MaxMind\MinFraud\Model\Device
  • MaxMind\MinFraud\Model\Disposition
  • MaxMind\MinFraud\Model\Email
  • MaxMind\MinFraud\Model\Factors
  • MaxMind\MinFraud\Model\GeoIp2Country
  • MaxMind\MinFraud\Model\GeoIp2Location
  • MaxMind\MinFraud\Model\Insights
  • MaxMind\MinFraud\Model\IpAddress
  • MaxMind\MinFraud\Model\Issuer
  • MaxMind\MinFraud\Model\Score
  • MaxMind\MinFraud\Model\ScoreIpAddress
  • MaxMind\MinFraud\Model\ShippingAddress
  • MaxMind\MinFraud\Model\Subscores
  • MaxMind\MinFraud\Model\Warning

Interfaces

  • GeoIp2\ProviderInterface
  • JsonSerializable
  • Throwable

Exceptions

  • BadFunctionCallException
  • BadMethodCallException
  • Exception
  • GeoIp2\Exception\AddressNotFoundException
  • GeoIp2\Exception\AuthenticationException
  • GeoIp2\Exception\GeoIp2Exception
  • GeoIp2\Exception\HttpException
  • GeoIp2\Exception\InvalidRequestException
  • GeoIp2\Exception\OutOfQueriesException
  • InvalidArgumentException
  • LogicException
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: namespace GeoIp2\Test\Database;
  4: 
  5: use GeoIp2\Database\Reader;
  6: 
  7: /**
  8:  * @coversNothing
  9:  */
 10: class ReaderTest extends \PHPUnit_Framework_TestCase
 11: {
 12:     public function databaseTypes()
 13:     {
 14:         return [['City', 'city'], ['Country', 'country']];
 15:     }
 16: 
 17:     /**
 18:      * @dataProvider databaseTypes
 19:      *
 20:      * @param mixed $type
 21:      * @param mixed $method
 22:      */
 23:     public function testDefaultLocale($type, $method)
 24:     {
 25:         $reader = new Reader("maxmind-db/test-data/GeoIP2-$type-Test.mmdb");
 26:         $record = $reader->$method('81.2.69.160');
 27:         $this->assertSame('United Kingdom', $record->country->name);
 28:         $reader->close();
 29:     }
 30: 
 31:     /**
 32:      * @dataProvider databaseTypes
 33:      *
 34:      * @param mixed $type
 35:      * @param mixed $method
 36:      */
 37:     public function testLocaleList($type, $method)
 38:     {
 39:         $reader = new Reader(
 40:             "maxmind-db/test-data/GeoIP2-$type-Test.mmdb",
 41:             ['xx', 'ru', 'pt-BR', 'es', 'en']
 42:         );
 43:         $record = $reader->$method('81.2.69.160');
 44:         $this->assertSame('Великобритания', $record->country->name);
 45:         $reader->close();
 46:     }
 47: 
 48:     /**
 49:      * @dataProvider databaseTypes
 50:      *
 51:      * @param mixed $type
 52:      * @param mixed $method
 53:      */
 54:     public function testHasIpAddress($type, $method)
 55:     {
 56:         $reader = new Reader("maxmind-db/test-data/GeoIP2-$type-Test.mmdb");
 57:         $record = $reader->$method('81.2.69.160');
 58:         $this->assertSame('81.2.69.160', $record->traits->ipAddress);
 59:         $reader->close();
 60:     }
 61: 
 62:     /**
 63:      * @expectedException \GeoIp2\Exception\AddressNotFoundException
 64:      * @expectedExceptionMessage The address 10.10.10.10 is not in the database.
 65:      */
 66:     public function testUnknownAddress()
 67:     {
 68:         $reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
 69:         $reader->city('10.10.10.10');
 70:         $reader->close();
 71:     }
 72: 
 73:     /**
 74:      * @expectedException \BadMethodCallException
 75:      * @expectedExceptionMessage The country method cannot be used to open a GeoIP2-City database
 76:      */
 77:     public function testIncorrectDatabase()
 78:     {
 79:         $reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
 80:         $reader->country('10.10.10.10');
 81:         $reader->close();
 82:     }
 83: 
 84:     /**
 85:      * @expectedException \BadMethodCallException
 86:      * @expectedExceptionMessage The domain method cannot be used to open a GeoIP2-City database
 87:      */
 88:     public function testIncorrectDatabaseFlat()
 89:     {
 90:         $reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
 91:         $reader->domain('10.10.10.10');
 92:         $reader->close();
 93:     }
 94: 
 95:     /**
 96:      * @expectedException \InvalidArgumentException
 97:      * @expectedExceptionMessage is not a valid IP address
 98:      */
 99:     public function testInvalidAddress()
100:     {
101:         $reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
102:         $reader->city('invalid');
103:         $reader->close();
104:     }
105: 
106:     public function testAnonymousIp()
107:     {
108:         $reader = new Reader('maxmind-db/test-data/GeoIP2-Anonymous-IP-Test.mmdb');
109:         $ipAddress = '1.2.0.1';
110: 
111:         $record = $reader->anonymousIp($ipAddress);
112:         $this->assertSame(true, $record->isAnonymous);
113:         $this->assertSame(true, $record->isAnonymousVpn);
114:         $this->assertSame(false, $record->isHostingProvider);
115:         $this->assertSame(false, $record->isPublicProxy);
116:         $this->assertSame(false, $record->isTorExitNode);
117:         $this->assertSame($ipAddress, $record->ipAddress);
118:         $reader->close();
119:     }
120: 
121:     public function testAsn()
122:     {
123:         $reader = new Reader('maxmind-db/test-data/GeoLite2-ASN-Test.mmdb');
124: 
125:         $ipAddress = '1.128.0.0';
126:         $record = $reader->asn($ipAddress);
127:         $this->assertSame(1221, $record->autonomousSystemNumber);
128:         $this->assertSame(
129:             'Telstra Pty Ltd',
130:             $record->autonomousSystemOrganization
131:         );
132: 
133:         $this->assertSame($ipAddress, $record->ipAddress);
134:         $reader->close();
135:     }
136: 
137:     public function testConnectionType()
138:     {
139:         $reader = new Reader('maxmind-db/test-data/GeoIP2-Connection-Type-Test.mmdb');
140:         $ipAddress = '1.0.1.0';
141: 
142:         $record = $reader->connectionType($ipAddress);
143:         $this->assertSame('Cable/DSL', $record->connectionType);
144:         $this->assertSame($ipAddress, $record->ipAddress);
145:         $reader->close();
146:     }
147: 
148:     public function testDomain()
149:     {
150:         $reader = new Reader('maxmind-db/test-data/GeoIP2-Domain-Test.mmdb');
151: 
152:         $ipAddress = '1.2.0.0';
153:         $record = $reader->domain($ipAddress);
154:         $this->assertSame('maxmind.com', $record->domain);
155:         $this->assertSame($ipAddress, $record->ipAddress);
156:         $reader->close();
157:     }
158: 
159:     public function testEnterprise()
160:     {
161:         $reader = new Reader('maxmind-db/test-data/GeoIP2-Enterprise-Test.mmdb');
162: 
163:         $ipAddress = '74.209.24.0';
164:         $record = $reader->enterprise($ipAddress);
165:         $this->assertSame(11, $record->city->confidence);
166:         $this->assertSame(99, $record->country->confidence);
167:         $this->assertSame(6252001, $record->country->geonameId);
168: 
169:         $this->assertSame(27, $record->location->accuracyRadius);
170: 
171:         $this->assertSame('Cable/DSL', $record->traits->connectionType);
172:         $this->assertSame(true, $record->traits->isLegitimateProxy);
173: 
174:         $this->assertSame($ipAddress, $record->traits->ipAddress);
175:         $reader->close();
176:     }
177: 
178:     public function testIsp()
179:     {
180:         $reader = new Reader('maxmind-db/test-data/GeoIP2-ISP-Test.mmdb');
181: 
182:         $ipAddress = '1.128.0.0';
183:         $record = $reader->isp($ipAddress);
184:         $this->assertSame(1221, $record->autonomousSystemNumber);
185:         $this->assertSame(
186:             'Telstra Pty Ltd',
187:             $record->autonomousSystemOrganization
188:         );
189: 
190:         $this->assertSame('Telstra Internet', $record->isp);
191:         $this->assertSame('Telstra Internet', $record->organization);
192: 
193:         $this->assertSame($ipAddress, $record->ipAddress);
194:         $reader->close();
195:     }
196: 
197:     public function testMetadata()
198:     {
199:         $reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
200:         $this->assertSame('GeoIP2-City', $reader->metadata()->databaseType);
201: 
202:         $reader->close();
203:     }
204: }
205: 
minFraud PHP API v1.4.0 API documentation generated by ApiGen