MaxmindLookupAdapterTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetCountryMaxmindGeoIPBundleNotInstalled() 0 6 1
A testGetCountryMaxmindGeoIPBundleInstalled() 0 13 2
1
<?php
2
namespace Azine\GeoBlockingBundle\Tests\Adapter;
3
4
use Azine\GeoBlockingBundle\Adapter\MaxmindLookupAdapter;
5
6
class MaxmindLookupAdapterTest extends \PHPUnit_Framework_TestCase
7
{
8
    /**
9
     * @expectedException \InvalidArgumentException
10
     */
11
    public function testGetCountryMaxmindGeoIPBundleNotInstalled()
12
    {
13
        $container = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock();
14
        $container->expects($this->once())->method("hasParameter")->with('maxmind_geoip_data_file_path')->will($this->returnValue(false));
15
        new MaxmindLookupAdapter($container);
16
    }
17
18
     public function testGetCountryMaxmindGeoIPBundleInstalled()
19
     {
20
         if (class_exists("Maxmind\lib\GeoIp")) {
21
             $container = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock();
22
             $container->expects($this->once())->method("hasParameter")->with('maxmind_geoip_data_file_path')->will($this->returnValue(__DIR__."/GeoLiteCity.dat"));
23
             $container->expects($this->once())->method("getParameter")->with('maxmind_geoip_data_file_path')->will($this->returnValue(__DIR__."/GeoLiteCity.dat"));
24
             $adapter = new MaxmindLookupAdapter($container);
25
             $country = $adapter->getCountry("8.8.8.8");
26
             $this->assertEquals("US", $country);
27
         } else {
28
            $this->markTestSkipped('The MaxMind library seems not to be installed/available.');
29
         }
30
     }
31
}
32