diff --git a/AbstractBrowser.php b/AbstractBrowser.php index f8c89871..977dd28a 100644 --- a/AbstractBrowser.php +++ b/AbstractBrowser.php @@ -111,7 +111,7 @@ public function getMaxRedirects() */ public function insulate(bool $insulated = true) { - if ($insulated && !class_exists('Symfony\\Component\\Process\\Process')) { + if ($insulated && !class_exists(\Symfony\Component\Process\Process::class)) { throw new \LogicException('Unable to isolate requests as the Symfony Process Component is not installed.'); } @@ -147,7 +147,7 @@ public function setServerParameter(string $key, string $value) */ public function getServerParameter(string $key, $default = '') { - return isset($this->server[$key]) ? $this->server[$key] : $default; + return $this->server[$key] ?? $default; } public function xmlHttpRequest(string $method, string $uri, array $parameters = [], array $files = [], array $server = [], string $content = null, bool $changeHistory = true): Crawler @@ -503,7 +503,7 @@ protected function filterResponse($response) */ protected function createCrawlerFromContent(string $uri, string $content, string $type) { - if (!class_exists('Symfony\Component\DomCrawler\Crawler')) { + if (!class_exists(Crawler::class)) { return null; } @@ -647,7 +647,7 @@ protected function getAbsoluteUri(string $uri) } else { $currentUri = sprintf('http%s://%s/', isset($this->server['HTTPS']) ? 's' : '', - isset($this->server['HTTP_HOST']) ? $this->server['HTTP_HOST'] : 'localhost' + $this->server['HTTP_HOST'] ?? 'localhost' ); } diff --git a/Cookie.php b/Cookie.php index c24661de..a416966a 100644 --- a/Cookie.php +++ b/Cookie.php @@ -22,7 +22,7 @@ class Cookie * Handles dates as defined by RFC 2616 section 3.3.1, and also some other * non-standard, but common formats. */ - private static $dateFormats = [ + private const DATE_FORMATS = [ 'D, d M Y H:i:s T', 'D, d-M-y H:i:s T', 'D, d-M-Y H:i:s T', @@ -92,7 +92,7 @@ public function __toString() if (null !== $this->expires) { $dateTime = \DateTime::createFromFormat('U', $this->expires, new \DateTimeZone('GMT')); - $cookie .= '; expires='.str_replace('+0000', '', $dateTime->format(self::$dateFormats[0])); + $cookie .= '; expires='.str_replace('+0000', '', $dateTime->format(self::DATE_FORMATS[0])); } if ('' !== $this->domain) { @@ -205,7 +205,7 @@ private static function parseDate(string $dateValue): ?string $dateValue = substr($dateValue, 1, -1); } - foreach (self::$dateFormats as $dateFormat) { + foreach (self::DATE_FORMATS as $dateFormat) { if (false !== $date = \DateTime::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT'))) { return $date->format('U'); } diff --git a/LICENSE b/LICENSE index 9e936ec0..9ff2d0d6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2020 Fabien Potencier +Copyright (c) 2004-2021 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/AbstractBrowserTest.php b/Tests/AbstractBrowserTest.php index 4292cd55..b71f5454 100644 --- a/Tests/AbstractBrowserTest.php +++ b/Tests/AbstractBrowserTest.php @@ -13,7 +13,9 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\BrowserKit\CookieJar; +use Symfony\Component\BrowserKit\Exception\BadMethodCallException; use Symfony\Component\BrowserKit\History; +use Symfony\Component\BrowserKit\Request; use Symfony\Component\BrowserKit\Response; class AbstractBrowserTest extends TestCase @@ -45,7 +47,7 @@ public function testGetRequest() public function testGetRequestNull() { - $this->expectException('Symfony\Component\BrowserKit\Exception\BadMethodCallException'); + $this->expectException(BadMethodCallException::class); $this->expectExceptionMessage('The "request()" method must be called before "Symfony\\Component\\BrowserKit\\AbstractBrowser::getRequest()".'); $client = $this->getBrowser(); @@ -77,12 +79,12 @@ public function testGetResponse() $client->request('GET', 'http://example.com/'); $this->assertSame('foo', $client->getResponse()->getContent(), '->getCrawler() returns the Response of the last request'); - $this->assertInstanceOf('Symfony\Component\BrowserKit\Response', $client->getResponse(), '->getCrawler() returns the Response of the last request'); + $this->assertInstanceOf(Response::class, $client->getResponse(), '->getCrawler() returns the Response of the last request'); } public function testGetResponseNull() { - $this->expectException('Symfony\Component\BrowserKit\Exception\BadMethodCallException'); + $this->expectException(BadMethodCallException::class); $this->expectExceptionMessage('The "request()" method must be called before "Symfony\\Component\\BrowserKit\\AbstractBrowser::getResponse()".'); $client = $this->getBrowser(); @@ -91,7 +93,7 @@ public function testGetResponseNull() public function testGetInternalResponseNull() { - $this->expectException('Symfony\Component\BrowserKit\Exception\BadMethodCallException'); + $this->expectException(BadMethodCallException::class); $this->expectExceptionMessage('The "request()" method must be called before "Symfony\\Component\\BrowserKit\\AbstractBrowser::getInternalResponse()".'); $client = $this->getBrowser(); @@ -118,7 +120,7 @@ public function testGetCrawler() public function testGetCrawlerNull() { - $this->expectException('Symfony\Component\BrowserKit\Exception\BadMethodCallException'); + $this->expectException(BadMethodCallException::class); $this->expectExceptionMessage('The "request()" method must be called before "Symfony\\Component\\BrowserKit\\AbstractBrowser::getCrawler()".'); $client = $this->getBrowser(); @@ -285,7 +287,7 @@ public function testClickLinkNotFound() $client->clickLink('foo'); $this->fail('->clickLink() throws a \InvalidArgumentException if the link could not be found'); } catch (\Exception $e) { - $this->assertInstanceOf('InvalidArgumentException', $e, '->clickLink() throws a \InvalidArgumentException if the link could not be found'); + $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->clickLink() throws a \InvalidArgumentException if the link could not be found'); } } @@ -344,7 +346,7 @@ public function testSubmitFormNotFound() ], 'POST'); $this->fail('->submitForm() throws a \InvalidArgumentException if the form could not be found'); } catch (\Exception $e) { - $this->assertInstanceOf('InvalidArgumentException', $e, '->submitForm() throws a \InvalidArgumentException if the form could not be found'); + $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->submitForm() throws a \InvalidArgumentException if the form could not be found'); } } @@ -395,7 +397,7 @@ public function testFollowRedirect() $client->followRedirect(); $this->fail('->followRedirect() throws a \LogicException if the request was not redirected'); } catch (\Exception $e) { - $this->assertInstanceOf('LogicException', $e, '->followRedirect() throws a \LogicException if the request was not redirected'); + $this->assertInstanceOf(\LogicException::class, $e, '->followRedirect() throws a \LogicException if the request was not redirected'); } $client->setNextResponse(new Response('', 302, ['Location' => 'http://www.example.com/redirected'])); @@ -425,7 +427,7 @@ public function testFollowRedirect() $client->followRedirect(); $this->fail('->followRedirect() throws a \LogicException if the request did not respond with 30x HTTP Code'); } catch (\Exception $e) { - $this->assertInstanceOf('LogicException', $e, '->followRedirect() throws a \LogicException if the request did not respond with 30x HTTP Code'); + $this->assertInstanceOf(\LogicException::class, $e, '->followRedirect() throws a \LogicException if the request did not respond with 30x HTTP Code'); } } @@ -455,7 +457,7 @@ public function testFollowRedirectWithMaxRedirects() $client->followRedirect(); $this->fail('->followRedirect() throws a \LogicException if the request was redirected and limit of redirections was reached'); } catch (\Exception $e) { - $this->assertInstanceOf('LogicException', $e, '->followRedirect() throws a \LogicException if the request was redirected and limit of redirections was reached'); + $this->assertInstanceOf(\LogicException::class, $e, '->followRedirect() throws a \LogicException if the request was redirected and limit of redirections was reached'); } $client->setNextResponse(new Response('', 302, ['Location' => 'http://www.example.com/redirected'])); @@ -738,7 +740,7 @@ public function testInsulatedRequests() $client->request('GET', 'http://www.example.com/foo/foobar'); $this->fail('->request() throws a \RuntimeException if the script has an error'); } catch (\Exception $e) { - $this->assertInstanceOf('RuntimeException', $e, '->request() throws a \RuntimeException if the script has an error'); + $this->assertInstanceOf(\RuntimeException::class, $e, '->request() throws a \RuntimeException if the script has an error'); } } @@ -826,12 +828,12 @@ public function testInternalRequest() 'NEW_SERVER_KEY' => 'new-server-key-value', ]); - $this->assertInstanceOf('Symfony\Component\BrowserKit\Request', $client->getInternalRequest()); + $this->assertInstanceOf(Request::class, $client->getInternalRequest()); } public function testInternalRequestNull() { - $this->expectException('Symfony\Component\BrowserKit\Exception\BadMethodCallException'); + $this->expectException(BadMethodCallException::class); $this->expectExceptionMessage('The "request()" method must be called before "Symfony\\Component\\BrowserKit\\AbstractBrowser::getInternalRequest()".'); $client = $this->getBrowser(); diff --git a/Tests/CookieJarTest.php b/Tests/CookieJarTest.php index d88f0234..414f5dc6 100644 --- a/Tests/CookieJarTest.php +++ b/Tests/CookieJarTest.php @@ -77,8 +77,8 @@ public function testUpdateFromSetCookie() $cookieJar->set(new Cookie('bar', 'bar')); $cookieJar->updateFromSetCookie($setCookies); - $this->assertInstanceOf('Symfony\Component\BrowserKit\Cookie', $cookieJar->get('foo')); - $this->assertInstanceOf('Symfony\Component\BrowserKit\Cookie', $cookieJar->get('bar')); + $this->assertInstanceOf(Cookie::class, $cookieJar->get('foo')); + $this->assertInstanceOf(Cookie::class, $cookieJar->get('bar')); $this->assertEquals('foo', $cookieJar->get('foo')->getValue(), '->updateFromSetCookie() updates cookies from a Set-Cookie header'); $this->assertEquals('bar', $cookieJar->get('bar')->getValue(), '->updateFromSetCookie() keeps existing cookies'); } @@ -103,9 +103,9 @@ public function testUpdateFromSetCookieWithMultipleCookies() $barCookie = $cookieJar->get('bar', '/', '.blog.symfony.com'); $phpCookie = $cookieJar->get('PHPSESSID'); - $this->assertInstanceOf('Symfony\Component\BrowserKit\Cookie', $fooCookie); - $this->assertInstanceOf('Symfony\Component\BrowserKit\Cookie', $barCookie); - $this->assertInstanceOf('Symfony\Component\BrowserKit\Cookie', $phpCookie); + $this->assertInstanceOf(Cookie::class, $fooCookie); + $this->assertInstanceOf(Cookie::class, $barCookie); + $this->assertInstanceOf(Cookie::class, $phpCookie); $this->assertEquals('foo', $fooCookie->getValue()); $this->assertEquals('bar', $barCookie->getValue()); $this->assertEquals('id', $phpCookie->getValue()); diff --git a/Tests/CookieTest.php b/Tests/CookieTest.php index 5f99eb11..a9b34139 100644 --- a/Tests/CookieTest.php +++ b/Tests/CookieTest.php @@ -104,7 +104,7 @@ public function testFromStringWithUrl() public function testFromStringThrowsAnExceptionIfCookieIsNotValid() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); Cookie::fromString('foo'); } @@ -117,7 +117,7 @@ public function testFromStringIgnoresInvalidExpiresDate() public function testFromStringThrowsAnExceptionIfUrlIsNotValid() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); Cookie::fromString('foo=bar', 'foobar'); } @@ -200,7 +200,7 @@ public function testIsExpired() public function testConstructException() { - $this->expectException('UnexpectedValueException'); + $this->expectException(\UnexpectedValueException::class); $this->expectExceptionMessage('The cookie expiration time "string" is not valid.'); new Cookie('foo', 'bar', 'string'); } diff --git a/Tests/HistoryTest.php b/Tests/HistoryTest.php index aa09b05b..8f3cfae1 100644 --- a/Tests/HistoryTest.php +++ b/Tests/HistoryTest.php @@ -55,7 +55,7 @@ public function testCurrent() $history->current(); $this->fail('->current() throws a \LogicException if the history is empty'); } catch (\Exception $e) { - $this->assertInstanceOf('LogicException', $e, '->current() throws a \LogicException if the history is empty'); + $this->assertInstanceOf(\LogicException::class, $e, '->current() throws a \LogicException if the history is empty'); } $history->add(new Request('http://www.example.com/', 'get')); @@ -72,7 +72,7 @@ public function testBack() $history->back(); $this->fail('->back() throws a \LogicException if the history is already on the first page'); } catch (\Exception $e) { - $this->assertInstanceOf('LogicException', $e, '->current() throws a \LogicException if the history is already on the first page'); + $this->assertInstanceOf(\LogicException::class, $e, '->current() throws a \LogicException if the history is already on the first page'); } $history->add(new Request('http://www.example1.com/', 'get')); @@ -91,7 +91,7 @@ public function testForward() $history->forward(); $this->fail('->forward() throws a \LogicException if the history is already on the last page'); } catch (\Exception $e) { - $this->assertInstanceOf('LogicException', $e, '->forward() throws a \LogicException if the history is already on the last page'); + $this->assertInstanceOf(\LogicException::class, $e, '->forward() throws a \LogicException if the history is already on the last page'); } $history->back(); diff --git a/Tests/HttpBrowserTest.php b/Tests/HttpBrowserTest.php index 1397d9b1..4cd44aff 100644 --- a/Tests/HttpBrowserTest.php +++ b/Tests/HttpBrowserTest.php @@ -73,7 +73,7 @@ public function testMultiPartRequestWithSingleFile() ->method('request') ->with('POST', 'http://example.com/', $this->callback(function ($options) { $this->assertStringContainsString('Content-Type: multipart/form-data', implode('', $options['headers'])); - $this->assertInstanceOf('\Generator', $options['body']); + $this->assertInstanceOf(\Generator::class, $options['body']); $this->assertStringContainsString('my_file', implode('', iterator_to_array($options['body']))); return true; @@ -183,7 +183,7 @@ protected function expectClientToSendRequestWithFiles(HttpClientInterface $clien ->method('request') ->with('POST', 'http://example.com/', $this->callback(function ($options) use ($fileContents) { $this->assertStringContainsString('Content-Type: multipart/form-data', implode('', $options['headers'])); - $this->assertInstanceOf('\Generator', $options['body']); + $this->assertInstanceOf(\Generator::class, $options['body']); $body = implode('', iterator_to_array($options['body'], false)); foreach ($fileContents as $content) { $this->assertStringContainsString($content, $body); @@ -201,7 +201,7 @@ protected function expectClientToNotSendRequestWithFiles(HttpClientInterface $cl ->method('request') ->with('POST', 'http://example.com/', $this->callback(function ($options) use ($fileContents) { $this->assertStringContainsString('Content-Type: multipart/form-data', implode('', $options['headers'])); - $this->assertInstanceOf('\Generator', $options['body']); + $this->assertInstanceOf(\Generator::class, $options['body']); $body = implode('', iterator_to_array($options['body'], false)); foreach ($fileContents as $content) { $this->assertStringNotContainsString($content, $body); diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index 5d7c7d6b..a7327b0f 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -52,7 +52,7 @@ public function testGetServer() $this->assertEquals(['foo' => 'bar'], $request->getServer(), '->getServer() returns the server parameters of the request'); } - public function testAllParameterValuesAreConvertedToString(): void + public function testAllParameterValuesAreConvertedToString() { $parameters = [ 'foo' => 1, diff --git a/Tests/TestClient.php b/Tests/TestClient.php index 0efa48b9..64e4937e 100644 --- a/Tests/TestClient.php +++ b/Tests/TestClient.php @@ -43,7 +43,7 @@ protected function doRequest($request): Response protected function getScript($request) { - $r = new \ReflectionClass('Symfony\Component\BrowserKit\Response'); + $r = new \ReflectionClass(Response::class); $path = $r->getFileName(); return <<getFileName(); return <<