mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Removed workarounds from UrlValidator that were required for guzzle 6.5.0
This commit is contained in:
@@ -7,17 +7,14 @@ namespace ShlinkioTest\Shlink\Core\Util;
|
||||
use Fig\Http\Message\RequestMethodInterface;
|
||||
use GuzzleHttp\ClientInterface;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
|
||||
use Shlinkio\Shlink\Core\Util\UrlValidator;
|
||||
use Zend\Diactoros\Request;
|
||||
use Zend\Diactoros\Response;
|
||||
|
||||
use function Functional\map;
|
||||
use function range;
|
||||
|
||||
class UrlValidatorTest extends TestCase
|
||||
{
|
||||
/** @var UrlValidator */
|
||||
@@ -31,39 +28,17 @@ class UrlValidatorTest extends TestCase
|
||||
$this->urlValidator = new UrlValidator($this->httpClient->reveal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideAttemptThatThrows
|
||||
*/
|
||||
public function exceptionIsThrownWhenUrlIsInvalid(int $attemptThatThrows): void
|
||||
/** @test */
|
||||
public function exceptionIsThrownWhenUrlIsInvalid(): void
|
||||
{
|
||||
$callNum = 1;
|
||||
$e = new ClientException('', $this->prophesize(Request::class)->reveal());
|
||||
$request = $this->httpClient->request(Argument::cetera())->willThrow(ClientException::class);
|
||||
|
||||
$request = $this->httpClient->request(Argument::cetera())->will(
|
||||
function () use ($e, $attemptThatThrows, &$callNum) {
|
||||
if ($callNum === $attemptThatThrows) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$callNum++;
|
||||
return new Response('php://memory', 302, ['Location' => 'http://foo.com']);
|
||||
}
|
||||
);
|
||||
|
||||
$request->shouldBeCalledTimes($attemptThatThrows);
|
||||
$request->shouldBeCalledOnce();
|
||||
$this->expectException(InvalidUrlException::class);
|
||||
|
||||
$this->urlValidator->validateUrl('http://foobar.com/12345/hello?foo=bar');
|
||||
}
|
||||
|
||||
public function provideAttemptThatThrows(): iterable
|
||||
{
|
||||
return map(range(1, 15), function (int $attempt) {
|
||||
return [$attempt];
|
||||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function expectedUrlIsCalledWhenTryingToVerify(): void
|
||||
{
|
||||
@@ -72,23 +47,11 @@ class UrlValidatorTest extends TestCase
|
||||
$request = $this->httpClient->request(
|
||||
RequestMethodInterface::METHOD_GET,
|
||||
$expectedUrl,
|
||||
Argument::cetera()
|
||||
[RequestOptions::ALLOW_REDIRECTS => ['max' => 15]]
|
||||
)->willReturn(new Response());
|
||||
|
||||
$this->urlValidator->validateUrl($expectedUrl);
|
||||
|
||||
$request->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function urlIsConsideredValidWhenTooManyRedirectsAreReturned(): void
|
||||
{
|
||||
$request = $this->httpClient->request(Argument::cetera())->willReturn(
|
||||
new Response('php://memory', 302, ['Location' => 'http://foo.com'])
|
||||
);
|
||||
|
||||
$this->urlValidator->validateUrl('http://foobar.com');
|
||||
|
||||
$request->shouldHaveBeenCalledTimes(15);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user