minFraud PHP API v1.0.0
  • Namespace
  • Class

Namespaces

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

Classes

  • GeoIp2\Database\Reader
  • GeoIp2\Model\AnonymousIp
  • 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\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

Exceptions

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