testGetCountryMaxmindGeoIPBundleNotInstalled()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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