testGetCountryWithoutGeoIpModule()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
namespace Azine\GeoBlockingBundle\Tests\Adapter;
3
4
use Azine\GeoBlockingBundle\Adapter\DefaultLookupAdapter;
5
6
class DefaultLookupAdapterTest extends \PHPUnit_Framework_TestCase
7
{
8
    public function testGetCountry()
9
    {
10
        if (function_exists("geoip_country_code_by_name")) {
11
            $adapter = new DefaultLookupAdapter();
12
13
            $chIp = "194.150.248.201";
14
            $this->assertEquals("CH",$adapter->getCountry($chIp), "$chIp should be in Switzerland => CH");
15
16
            $usIp = "8.8.8.8";
17
            $this->assertEquals("US",$adapter->getCountry($usIp), "$usIp should be in the USA => US");
18
        } else {
19
            $this->markTestSkipped("php geoip-module seems not to be installed.");
20
        }
21
    }
22
23
    /**
24
     * @expectedException \InvalidArgumentException
25
     */
26
    public function testGetCountryWithoutGeoIpModule()
27
    {
28
        if (!function_exists("geoip_country_code_by_name")) {
29
            $adapter = new DefaultLookupAdapter();
30
            $chIp = "194.150.248.201";
31
            $this->assertEquals("CH",$adapter->getCountry($chIp), "$chIp should be in Switzerland => CH");
32
        } else {
33
            throw new \InvalidArgumentException("It seems, the geo-ip extension is installed, so this test doesn't make sense.");
34
        }
35
36
    }
37
}
38