Passed
Pull Request — master (#456)
by Alejandro
06:37 queued 01:57
created

WrongIpExceptionTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 10
dl 0
loc 21
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromIpAddressProperlyCreatesExceptionWithPrev() 0 8 1
A fromIpAddressProperlyCreatesExceptionWithoutPrev() 0 7 1
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\IpGeolocation\Exception;
5
6
use Exception;
7
use PHPUnit\Framework\TestCase;
8
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
9
10
class WrongIpExceptionTest extends TestCase
11
{
12
    /** @test */
13
    public function fromIpAddressProperlyCreatesExceptionWithoutPrev(): void
14
    {
15
        $e = WrongIpException::fromIpAddress('1.2.3.4');
16
17
        $this->assertEquals('Provided IP "1.2.3.4" is invalid', $e->getMessage());
18
        $this->assertEquals(0, $e->getCode());
19
        $this->assertNull($e->getPrevious());
20
    }
21
22
    /** @test */
23
    public function fromIpAddressProperlyCreatesExceptionWithPrev(): void
24
    {
25
        $prev = new Exception('Previous error');
26
        $e = WrongIpException::fromIpAddress('1.2.3.4', $prev);
27
28
        $this->assertEquals('Provided IP "1.2.3.4" is invalid', $e->getMessage());
29
        $this->assertEquals(0, $e->getCode());
30
        $this->assertSame($prev, $e->getPrevious());
31
    }
32
}
33