2018-11-17 20:40:47 +03:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Common\Exception;
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
|
|
|
|
|
|
|
class WrongIpExceptionTest extends TestCase
|
|
|
|
{
|
2019-02-17 22:28:34 +03:00
|
|
|
/** @test */
|
2018-11-17 20:40:47 +03:00
|
|
|
public function fromIpAddressProperlyCreatesExceptionWithoutPrev()
|
|
|
|
{
|
|
|
|
$e = WrongIpException::fromIpAddress('1.2.3.4');
|
|
|
|
|
|
|
|
$this->assertEquals('Provided IP "1.2.3.4" is invalid', $e->getMessage());
|
|
|
|
$this->assertEquals(0, $e->getCode());
|
|
|
|
$this->assertNull($e->getPrevious());
|
|
|
|
}
|
2019-02-17 22:28:34 +03:00
|
|
|
/** @test */
|
2018-11-17 20:40:47 +03:00
|
|
|
public function fromIpAddressProperlyCreatesExceptionWithPrev()
|
|
|
|
{
|
|
|
|
$prev = new Exception('Previous error');
|
|
|
|
$e = WrongIpException::fromIpAddress('1.2.3.4', $prev);
|
|
|
|
|
|
|
|
$this->assertEquals('Provided IP "1.2.3.4" is invalid', $e->getMessage());
|
|
|
|
$this->assertEquals(0, $e->getCode());
|
|
|
|
$this->assertSame($prev, $e->getPrevious());
|
|
|
|
}
|
|
|
|
}
|