2016-07-31 14:18:36 +03:00
|
|
|
<?php
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-07-31 14:18:36 +03:00
|
|
|
namespace ShlinkioTest\Shlink\Rest\Util;
|
|
|
|
|
2017-03-24 22:34:18 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-07-31 14:18:36 +03:00
|
|
|
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
|
|
|
|
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
|
|
|
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
|
|
|
|
use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
|
|
|
|
use Shlinkio\Shlink\Rest\Exception\AuthenticationException;
|
|
|
|
use Shlinkio\Shlink\Rest\Util\RestUtils;
|
|
|
|
|
|
|
|
class RestUtilsTest extends TestCase
|
|
|
|
{
|
2019-02-17 22:28:34 +03:00
|
|
|
/** @test */
|
2016-07-31 14:18:36 +03:00
|
|
|
public function correctCodeIsReturnedFromException()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
RestUtils::INVALID_SHORTCODE_ERROR,
|
|
|
|
RestUtils::getRestErrorCodeFromException(new InvalidShortCodeException())
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
RestUtils::INVALID_URL_ERROR,
|
|
|
|
RestUtils::getRestErrorCodeFromException(new InvalidUrlException())
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
RestUtils::INVALID_ARGUMENT_ERROR,
|
|
|
|
RestUtils::getRestErrorCodeFromException(new InvalidArgumentException())
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
RestUtils::INVALID_CREDENTIALS_ERROR,
|
|
|
|
RestUtils::getRestErrorCodeFromException(new AuthenticationException())
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
RestUtils::UNKNOWN_ERROR,
|
|
|
|
RestUtils::getRestErrorCodeFromException(new WrongIpException())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|