shlink/module/Core/test/Exception/InvalidShortCodeExceptionTest.php

40 lines
1.2 KiB
PHP
Raw Normal View History

2018-11-17 12:23:25 -06:00
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Exception;
use Exception;
use PHPUnit\Framework\TestCase;
2018-11-17 12:26:07 -06:00
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
2018-11-17 12:23:25 -06:00
use Throwable;
class InvalidShortCodeExceptionTest extends TestCase
{
/**
* @test
* @dataProvider providePrevious
*/
2019-02-17 13:28:34 -06:00
public function properlyCreatesExceptionFromCharset(?Throwable $prev): void
2018-11-17 12:23:25 -06:00
{
$e = InvalidShortCodeException::fromCharset('abc123', 'def456', $prev);
$this->assertEquals('Provided short code "abc123" does not match the char set "def456"', $e->getMessage());
$this->assertEquals($prev !== null ? $prev->getCode() : -1, $e->getCode());
$this->assertEquals($prev, $e->getPrevious());
}
2019-02-17 13:28:34 -06:00
public function providePrevious(): iterable
2018-11-17 12:23:25 -06:00
{
2019-02-17 13:28:34 -06:00
yield 'null previous' => [null];
yield 'instance previous' => [new Exception('Previous error', 10)];
2018-11-17 12:23:25 -06:00
}
2019-02-17 13:28:34 -06:00
/** @test */
public function properlyCreatesExceptionFromNotFoundShortCode(): void
2018-11-17 12:23:25 -06:00
{
$e = InvalidShortCodeException::fromNotFoundShortCode('abc123');
$this->assertEquals('Provided short code "abc123" does not belong to a short URL', $e->getMessage());
}
}