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

fromIpAddressProperlyCreatesExceptionWithoutPrev()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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