2018-11-17 21:23:25 +03:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\Exception;
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
|
|
|
|
use Throwable;
|
|
|
|
|
|
|
|
class InvalidUrlExceptionTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider providePrevious
|
|
|
|
*/
|
2019-02-17 22:28:34 +03:00
|
|
|
public function properlyCreatesExceptionFromUrl(?Throwable $prev): void
|
2018-11-17 21:23:25 +03:00
|
|
|
{
|
|
|
|
$e = InvalidUrlException::fromUrl('http://the_url.com', $prev);
|
|
|
|
|
|
|
|
$this->assertEquals('Provided URL "http://the_url.com" is not an existing and valid URL', $e->getMessage());
|
|
|
|
$this->assertEquals($prev !== null ? $prev->getCode() : -1, $e->getCode());
|
|
|
|
$this->assertEquals($prev, $e->getPrevious());
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:28:34 +03:00
|
|
|
public function providePrevious(): iterable
|
2018-11-17 21:23:25 +03:00
|
|
|
{
|
2019-02-17 22:28:34 +03:00
|
|
|
yield 'null previous' => [null];
|
|
|
|
yield 'instance previous' => [new Exception('Previous error', 10)];
|
2018-11-17 21:23:25 +03:00
|
|
|
}
|
|
|
|
}
|