DefaultLookupAdapterTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetCountry() 0 14 2
A testGetCountryWithoutGeoIpModule() 0 11 2
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