IpLocationTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetLocationForValidIp() 0 6 1
A testEmptyIpDirectNull() 0 5 1
A testGetLocationForInvalidIp() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lochmueller\LanguageDetection\Tests\Unit\Service;
6
7
use Lochmueller\LanguageDetection\Service\IpLocation;
8
use Lochmueller\LanguageDetection\Tests\Unit\AbstractUnitTest;
9
10
/**
11
 * @internal
12
 *
13
 * @coversNothing
14
 */
15
class IpLocationTest extends AbstractUnitTest
16
{
17
    /**
18
     * @covers \Lochmueller\LanguageDetection\Service\IpLocation
19
     */
20
    public function testGetLocationForValidIp(): void
21
    {
22
        $locationService = new IpLocation($this->getRequestFactory());
23
        $result = $locationService->getCountryCode('8.8.8.8');
24
25
        self::assertEquals('US', $result);
26
    }
27
28
    /**
29
     * @covers \Lochmueller\LanguageDetection\Service\IpLocation
30
     */
31
    public function testEmptyIpDirectNull(): void
32
    {
33
        $locationService = new IpLocation($this->getRequestFactory());
34
35
        self::assertNull($locationService->getCountryCode(''));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $locationService->getCountryCode('') targeting Lochmueller\LanguageDete...ation::getCountryCode() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
36
    }
37
38
    /**
39
     * @covers \Lochmueller\LanguageDetection\Service\IpLocation
40
     */
41
    public function testGetLocationForInvalidIp(): void
42
    {
43
        $locationService = new IpLocation($this->getRequestFactory());
44
        self::assertNull($locationService->getCountryCode('0.0.0.0'));
45
    }
46
}
47