httpClient = $this->prophesize(ClientInterface::class); $this->urlValidator = new UrlValidator($this->httpClient->reveal()); } /** @test */ public function exceptionIsThrownWhenUrlIsInvalid(): void { $request = $this->httpClient->request(Argument::cetera())->willThrow( new ClientException('', $this->prophesize(Request::class)->reveal()) ); $this->expectException(InvalidUrlException::class); $request->shouldBeCalledOnce(); $this->urlValidator->validateUrl('http://foobar.com/12345/hello?foo=bar'); } /** * @test * @dataProvider provideUrls */ public function expectedUrlIsCalledInOrderToVerifyProvidedUrl(string $providedUrl, string $expectedUrl): void { $request = $this->httpClient->request( RequestMethodInterface::METHOD_GET, $expectedUrl, Argument::cetera() )->will(function () { }); $this->urlValidator->validateUrl($providedUrl); $request->shouldHaveBeenCalledOnce(); } public function provideUrls(): iterable { yield 'regular domain' => ['http://foobar.com', 'http://foobar.com']; yield 'IDN' => ['https://cédric.laubacher.io/', 'https://xn--cdric-bsa.laubacher.io/']; } }