Moved check for URL validation config option to the UrlValidator itself

This commit is contained in:
Alejandro Celaya
2020-03-22 16:58:28 +01:00
parent d29ebb706e
commit 682a0768b7
5 changed files with 34 additions and 43 deletions

View File

@@ -13,17 +13,20 @@ use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
use Shlinkio\Shlink\Core\Options\UrlShortenerOptions;
use Shlinkio\Shlink\Core\Util\UrlValidator;
class UrlValidatorTest extends TestCase
{
private UrlValidator $urlValidator;
private ObjectProphecy $httpClient;
private UrlShortenerOptions $options;
public function setUp(): void
{
$this->httpClient = $this->prophesize(ClientInterface::class);
$this->urlValidator = new UrlValidator($this->httpClient->reveal());
$this->options = new UrlShortenerOptions(['validate_url' => true]);
$this->urlValidator = new UrlValidator($this->httpClient->reveal(), $this->options);
}
/** @test */
@@ -52,4 +55,15 @@ class UrlValidatorTest extends TestCase
$request->shouldHaveBeenCalledOnce();
}
/** @test */
public function noCheckIsPerformedWhenUrlValidationIsDisabled(): void
{
$request = $this->httpClient->request(Argument::cetera())->willReturn(new Response());
$this->options->validateUrl = false;
$this->urlValidator->validateUrl('');
$request->shouldNotHaveBeenCalled();
}
}