From 796185384b15e6028c4de7a708d143d44f6c978c Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Thu, 3 Oct 2024 23:10:57 +0200 Subject: [PATCH] - --- src/Client.php | 19 +++++++++--------- src/Cookie/CookieJar.php | 2 +- src/DomCrawler/Crawler.php | 18 ++++++++--------- src/DomCrawler/Field/ChoiceFormField.php | 10 +++++----- src/DomCrawler/Field/FileFormField.php | 4 ++-- src/DomCrawler/Field/InputFormField.php | 2 +- src/DomCrawler/Field/TextareaFormField.php | 2 +- src/DomCrawler/Form.php | 8 ++++---- src/DomCrawler/Image.php | 2 +- src/DomCrawler/Link.php | 2 +- src/Exception/ExceptionInterface.php | 2 ++ src/Exception/InvalidArgumentException.php | 2 ++ src/Exception/LogicException.php | 2 ++ src/Exception/RuntimeException.php | 2 ++ src/ExceptionThrower.php | 2 +- src/PantherTestCaseTrait.php | 14 ++++++------- src/ProcessManager/ChromeManager.php | 2 +- src/ProcessManager/FirefoxManager.php | 2 +- src/ProcessManager/SeleniumManager.php | 4 ++-- src/ProcessManager/WebServerManager.php | 4 ++-- .../WebServerReadinessProbeTrait.php | 4 ++-- src/ServerExtensionLegacy.php | 6 +++--- src/WebDriver/WebDriverCheckbox.php | 20 +++++++++---------- src/WebDriver/WebDriverMouse.php | 2 +- src/WebTestAssertionsTrait.php | 4 ++-- tests/DomCrawler/CrawlerTest.php | 2 +- tests/DomCrawler/Field/FileFormFieldTest.php | 2 +- tests/DummyKernel.php | 2 +- tests/TestCase.php | 2 +- 29 files changed, 79 insertions(+), 70 deletions(-) diff --git a/src/Client.php b/src/Client.php index 75d059e2..e723d786 100644 --- a/src/Client.php +++ b/src/Client.php @@ -41,6 +41,7 @@ use Symfony\Component\Panther\DomCrawler\Link as PantherLink; use Symfony\Component\Panther\Exception\InvalidArgumentException; use Symfony\Component\Panther\Exception\LogicException; +use Symfony\Component\Panther\Exception\RuntimeException; use Symfony\Component\Panther\ProcessManager\BrowserManagerInterface; use Symfony\Component\Panther\ProcessManager\ChromeManager; use Symfony\Component\Panther\ProcessManager\FirefoxManager; @@ -66,7 +67,7 @@ final class Client extends AbstractBrowser implements WebDriver, JavaScriptExecu /** * @param string[]|null $arguments */ - public static function createChromeClient(string $chromeDriverBinary = null, array $arguments = null, array $options = [], string $baseUri = null): self + public static function createChromeClient(?string $chromeDriverBinary = null, ?array $arguments = null, array $options = [], ?string $baseUri = null): self { return new self(new ChromeManager($chromeDriverBinary, $arguments, $options), $baseUri); } @@ -74,17 +75,17 @@ public static function createChromeClient(string $chromeDriverBinary = null, arr /** * @param string[]|null $arguments */ - public static function createFirefoxClient(string $geckodriverBinary = null, array $arguments = null, array $options = [], string $baseUri = null): self + public static function createFirefoxClient(?string $geckodriverBinary = null, ?array $arguments = null, array $options = [], ?string $baseUri = null): self { return new self(new FirefoxManager($geckodriverBinary, $arguments, $options), $baseUri); } - public static function createSeleniumClient(string $host = null, WebDriverCapabilities $capabilities = null, string $baseUri = null, array $options = []): self + public static function createSeleniumClient(?string $host = null, ?WebDriverCapabilities $capabilities = null, ?string $baseUri = null, array $options = []): self { return new self(new SeleniumManager($host, $capabilities, $options), $baseUri); } - public function __construct(BrowserManagerInterface $browserManager, string $baseUri = null) + public function __construct(BrowserManagerInterface $browserManager, ?string $baseUri = null) { $this->browserManager = $browserManager; $this->baseUri = $baseUri; @@ -254,7 +255,7 @@ public function refreshCrawler(): PantherCrawler return $this->crawler = $this->createCrawler(); } - public function request(string $method, string $uri, array $parameters = [], array $files = [], array $server = [], string $content = null, bool $changeHistory = true): PantherCrawler + public function request(string $method, string $uri, array $parameters = [], array $files = [], array $server = [], ?string $content = null, bool $changeHistory = true): PantherCrawler { if ('GET' !== $method) { throw new InvalidArgumentException('Only the GET method is supported when using WebDriver.'); @@ -268,7 +269,7 @@ public function request(string $method, string $uri, array $parameters = [], arr foreach (['parameters', 'files', 'server'] as $arg) { if ([] !== $$arg) { - throw new InvalidArgumentException(sprintf('The parameter "$%s" is not supported when using WebDriver.', $arg)); + throw new InvalidArgumentException(\sprintf('The parameter "$%s" is not supported when using WebDriver.', $arg)); } } @@ -770,14 +771,14 @@ public function ping(int $timeout = 1000): bool } /** - * @return \LogicException|\RuntimeException + * @return LogicException|RuntimeException */ private function createException(string $implementableClass): \Exception { if (null === $this->webDriver) { - return new \LogicException(sprintf('WebDriver not started yet. Call method `start()` first before calling any `%s` method.', $implementableClass)); + return new LogicException(\sprintf('WebDriver not started yet. Call method `start()` first before calling any `%s` method.', $implementableClass)); } - return new \RuntimeException(sprintf('"%s" does not implement "%s".', \get_class($this->webDriver), $implementableClass)); + return new RuntimeException(\sprintf('"%s" does not implement "%s".', \get_class($this->webDriver), $implementableClass)); } } diff --git a/src/Cookie/CookieJar.php b/src/Cookie/CookieJar.php index 3cd571dd..ef9e75cf 100644 --- a/src/Cookie/CookieJar.php +++ b/src/Cookie/CookieJar.php @@ -133,7 +133,7 @@ private function webDriverToSymfony(WebDriverCookie $cookie): Cookie return new Cookie($cookie->getName(), $cookie->getValue(), $expiry, $cookie->getPath(), (string) $cookie->getDomain(), (bool) $cookie->isSecure(), (bool) $cookie->isHttpOnly()); } - private function getWebDriverCookie(string $name, string $path = '/', string $domain = null): ?WebDriverCookie + private function getWebDriverCookie(string $name, string $path = '/', ?string $domain = null): ?WebDriverCookie { try { $cookie = $this->webDriver->manage()->getCookieNamed($name); diff --git a/src/DomCrawler/Crawler.php b/src/DomCrawler/Crawler.php index bf2ab0b1..06204336 100644 --- a/src/DomCrawler/Crawler.php +++ b/src/DomCrawler/Crawler.php @@ -36,7 +36,7 @@ final class Crawler extends BaseCrawler implements WebDriverElement /** * @param WebDriverElement[] $elements */ - public function __construct(array $elements = [], WebDriver $webDriver = null, string $uri = null) + public function __construct(array $elements = [], ?WebDriver $webDriver = null, ?string $uri = null) { $this->uri = $uri; $this->webDriver = $webDriver; @@ -179,7 +179,7 @@ public function ancestors(): static /** * @see https://github.com/symfony/symfony/issues/26432 */ - public function children(string $selector = null): static + public function children(?string $selector = null): static { $xpath = 'child::*'; if (null !== $selector) { @@ -205,7 +205,7 @@ public function nodeName(): string return $this->getElementOrThrow()->getTagName(); } - public function text(string $default = null, bool $normalizeWhitespace = true): string + public function text(?string $default = null, bool $normalizeWhitespace = true): string { if (!$normalizeWhitespace) { throw new InvalidArgumentException('Panther only supports getting normalized text.'); @@ -222,7 +222,7 @@ public function text(string $default = null, bool $normalizeWhitespace = true): } } - public function html(string $default = null): string + public function html(?string $default = null): string { try { $element = $this->getElementOrThrow(); @@ -276,19 +276,19 @@ public function filter($selector): static public function selectLink($value): static { return $this->selectFromXpath( - sprintf('descendant-or-self::a[contains(concat(\' \', normalize-space(string(.)), \' \'), %1$s) or ./img[contains(concat(\' \', normalize-space(string(@alt)), \' \'), %1$s)]]', self::xpathLiteral(' '.$value.' ')) + \sprintf('descendant-or-self::a[contains(concat(\' \', normalize-space(string(.)), \' \'), %1$s) or ./img[contains(concat(\' \', normalize-space(string(@alt)), \' \'), %1$s)]]', self::xpathLiteral(' '.$value.' ')) ); } public function selectImage($value): static { - return $this->selectFromXpath(sprintf('descendant-or-self::img[contains(normalize-space(string(@alt)), %s)]', self::xpathLiteral($value))); + return $this->selectFromXpath(\sprintf('descendant-or-self::img[contains(normalize-space(string(@alt)), %s)]', self::xpathLiteral($value))); } public function selectButton($value): static { return $this->selectFromXpath( - sprintf( + \sprintf( 'descendant-or-self::input[((contains(%1$s, "submit") or contains(%1$s, "button")) and contains(concat(\' \', normalize-space(string(@value)), \' \'), %2$s)) or (contains(%1$s, "image") and contains(concat(\' \', normalize-space(string(@alt)), \' \'), %2$s)) or @id=%3$s or @name=%3$s] | descendant-or-self::button[contains(concat(\' \', normalize-space(string(.)), \' \'), %2$s) or @id=%3$s or @name=%3$s]', 'translate(@type, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")', self::xpathLiteral(' '.$value.' '), @@ -332,7 +332,7 @@ public function images(): array return $images; } - public function form(array $values = null, $method = null): Form + public function form(?array $values = null, $method = null): Form { $form = new Form($this->getElementOrThrow(), $this->webDriver); if (null !== $values) { @@ -395,7 +395,7 @@ private function selectFromXpath(string $xpath): self /** * @param WebDriverElement[]|null $nodes */ - private function createSubCrawler(array $nodes = null): self + private function createSubCrawler(?array $nodes = null): self { return new self($nodes ?? [], $this->webDriver, $this->uri); } diff --git a/src/DomCrawler/Field/ChoiceFormField.php b/src/DomCrawler/Field/ChoiceFormField.php index 5690ecfb..0f456059 100644 --- a/src/DomCrawler/Field/ChoiceFormField.php +++ b/src/DomCrawler/Field/ChoiceFormField.php @@ -54,7 +54,7 @@ public function select($value): void public function tick(): void { if ('checkbox' !== $type = $this->element->getAttribute('type')) { - throw new LogicException(sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->element->getAttribute('name'), $type)); + throw new LogicException(\sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->element->getAttribute('name'), $type)); } $this->setValue(true); @@ -68,7 +68,7 @@ public function tick(): void public function untick(): void { if ('checkbox' !== $type = $this->element->getAttribute('type')) { - throw new LogicException(sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->element->getAttribute('name'), $type)); + throw new LogicException(\sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->element->getAttribute('name'), $type)); } $this->setValue(false); @@ -116,7 +116,7 @@ public function setValue($value): void { if (\is_bool($value)) { if ('checkbox' !== $this->type) { - throw new InvalidArgumentException(sprintf('Invalid argument of type "%s"', \gettype($value))); + throw new InvalidArgumentException(\sprintf('Invalid argument of type "%s"', \gettype($value))); } if ($value) { @@ -191,12 +191,12 @@ protected function initialize(): void { $tagName = $this->element->getTagName(); if ('input' !== $tagName && 'select' !== $tagName) { - throw new LogicException(sprintf('A ChoiceFormField can only be created from an input or select tag (%s given).', $tagName)); + throw new LogicException(\sprintf('A ChoiceFormField can only be created from an input or select tag (%s given).', $tagName)); } $type = strtolower((string) $this->element->getAttribute('type')); if ('input' === $tagName && 'checkbox' !== $type && 'radio' !== $type) { - throw new LogicException(sprintf('A ChoiceFormField can only be created from an input tag with a type of checkbox or radio (given type is %s).', $type)); + throw new LogicException(\sprintf('A ChoiceFormField can only be created from an input tag with a type of checkbox or radio (given type is %s).', $type)); } $this->type = 'select' === $tagName ? 'select' : $type; diff --git a/src/DomCrawler/Field/FileFormField.php b/src/DomCrawler/Field/FileFormField.php index e52b9b33..ac948476 100644 --- a/src/DomCrawler/Field/FileFormField.php +++ b/src/DomCrawler/Field/FileFormField.php @@ -68,12 +68,12 @@ protected function initialize(): void { $tagName = $this->element->getTagName(); if ('input' !== $tagName) { - throw new LogicException(sprintf('A FileFormField can only be created from an input tag (%s given).', $tagName)); + throw new LogicException(\sprintf('A FileFormField can only be created from an input tag (%s given).', $tagName)); } $type = strtolower($this->element->getAttribute('type')); if ('file' !== $type) { - throw new LogicException(sprintf('A FileFormField can only be created from an input tag with a type of file (given type is %s).', $type)); + throw new LogicException(\sprintf('A FileFormField can only be created from an input tag with a type of file (given type is %s).', $type)); } $value = $this->element->getAttribute('value'); diff --git a/src/DomCrawler/Field/InputFormField.php b/src/DomCrawler/Field/InputFormField.php index 5b51a716..5da1f6ef 100644 --- a/src/DomCrawler/Field/InputFormField.php +++ b/src/DomCrawler/Field/InputFormField.php @@ -49,7 +49,7 @@ protected function initialize(): void { $tagName = $this->element->getTagName(); if ('input' !== $tagName && 'button' !== $tagName) { - throw new LogicException(sprintf('An InputFormField can only be created from an input or button tag (%s given).', $tagName)); + throw new LogicException(\sprintf('An InputFormField can only be created from an input or button tag (%s given).', $tagName)); } $type = strtolower((string) $this->element->getAttribute('type')); diff --git a/src/DomCrawler/Field/TextareaFormField.php b/src/DomCrawler/Field/TextareaFormField.php index 73106f4f..715d3b24 100644 --- a/src/DomCrawler/Field/TextareaFormField.php +++ b/src/DomCrawler/Field/TextareaFormField.php @@ -37,7 +37,7 @@ protected function initialize(): void { $tagName = $this->element->getTagName(); if ('textarea' !== $tagName) { - throw new LogicException(sprintf('A TextareaFormField can only be created from a textarea tag (%s given).', $tagName)); + throw new LogicException(\sprintf('A TextareaFormField can only be created from a textarea tag (%s given).', $tagName)); } } } diff --git a/src/DomCrawler/Form.php b/src/DomCrawler/Form.php index 951f0153..7fd1dd88 100644 --- a/src/DomCrawler/Form.php +++ b/src/DomCrawler/Form.php @@ -62,7 +62,7 @@ private function setElement(WebDriverElement $element): void try { $form = $this->webDriver->findElement(WebDriverBy::id($formId)); } catch (NoSuchElementException $e) { - throw new LogicException(sprintf('The selected node has an invalid form attribute (%s).', $formId)); + throw new LogicException(\sprintf('The selected node has an invalid form attribute (%s).', $formId)); } $this->element = $form; @@ -78,7 +78,7 @@ private function setElement(WebDriverElement $element): void } } while ('form' !== $element->getTagName()); } elseif ('form' !== $tagName = $element->getTagName()) { - throw new LogicException(sprintf('Unable to submit on a "%s" tag.', $tagName)); + throw new LogicException(\sprintf('Unable to submit on a "%s" tag.', $tagName)); } $this->element = $element; @@ -168,7 +168,7 @@ public function getFiles(): array continue; } - if ($field instanceof Field\FileFormField) { + if ($field instanceof FileFormField) { $files[$field->getName()] = $field->getValue(); } } @@ -272,7 +272,7 @@ protected function getRawUri(): string private function getFormElement(string $name): WebDriverElement { return $this->element->findElement(WebDriverBy::xpath( - sprintf('.//input[@name=%1$s] | .//textarea[@name=%1$s] | .//select[@name=%1$s] | .//button[@name=%1$s] | .//input[@name=%2$s] | .//textarea[@name=%2$s] | .//select[@name=%2$s] | .//button[@name=%2$s]', XPathEscaper::escapeQuotes($name), XPathEscaper::escapeQuotes($name.'[]')) + \sprintf('.//input[@name=%1$s] | .//textarea[@name=%1$s] | .//select[@name=%1$s] | .//button[@name=%1$s] | .//input[@name=%2$s] | .//textarea[@name=%2$s] | .//select[@name=%2$s] | .//button[@name=%2$s]', XPathEscaper::escapeQuotes($name), XPathEscaper::escapeQuotes($name.'[]')) )); } diff --git a/src/DomCrawler/Image.php b/src/DomCrawler/Image.php index 88eccc1c..c88ad40e 100644 --- a/src/DomCrawler/Image.php +++ b/src/DomCrawler/Image.php @@ -30,7 +30,7 @@ final class Image extends BaseImage public function __construct(WebDriverElement $element) { if ('img' !== $tagName = $element->getTagName()) { - throw new LogicException(sprintf('Unable to visualize a "%s" tag.', $tagName)); + throw new LogicException(\sprintf('Unable to visualize a "%s" tag.', $tagName)); } $this->element = $element; diff --git a/src/DomCrawler/Link.php b/src/DomCrawler/Link.php index 3e04760d..78cdc328 100644 --- a/src/DomCrawler/Link.php +++ b/src/DomCrawler/Link.php @@ -31,7 +31,7 @@ public function __construct(WebDriverElement $element, string $currentUri) { $tagName = $element->getTagName(); if ('a' !== $tagName && 'area' !== $tagName && 'link' !== $tagName) { - throw new LogicException(sprintf('Unable to navigate from a "%s" tag.', $tagName)); + throw new LogicException(\sprintf('Unable to navigate from a "%s" tag.', $tagName)); } $this->element = $element; diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 007772f3..3bbe2830 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Symfony\Component\Panther\Exception; /** diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 69c3a30b..b1843a07 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Symfony\Component\Panther\Exception; /** diff --git a/src/Exception/LogicException.php b/src/Exception/LogicException.php index 54da0f43..f5ff4760 100644 --- a/src/Exception/LogicException.php +++ b/src/Exception/LogicException.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Symfony\Component\Panther\Exception; /** diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index 12ba78dd..d75d3260 100644 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Symfony\Component\Panther\Exception; /** diff --git a/src/ExceptionThrower.php b/src/ExceptionThrower.php index 5a0d530a..d13069cb 100644 --- a/src/ExceptionThrower.php +++ b/src/ExceptionThrower.php @@ -22,6 +22,6 @@ trait ExceptionThrower { private function createNotSupportedException(string $method): \InvalidArgumentException { - return new \InvalidArgumentException(sprintf('The "%s" method is not supported when using WebDriver.', $method)); + return new \InvalidArgumentException(\sprintf('The "%s" method is not supported when using WebDriver.', $method)); } } diff --git a/src/PantherTestCaseTrait.php b/src/PantherTestCaseTrait.php index 901a932c..df730cee 100644 --- a/src/PantherTestCaseTrait.php +++ b/src/PantherTestCaseTrait.php @@ -119,7 +119,7 @@ public static function startWebServer(array $options = []): void self::$webServerManager = new WebServerManager(...array_values($options)); self::$webServerManager->start(); - self::$baseUri = sprintf('http://%s:%s', $options['hostname'], $options['port']); + self::$baseUri = \sprintf('http://%s:%s', $options['hostname'], $options['port']); } public static function isWebServerStarted(): bool @@ -181,19 +181,19 @@ protected static function createPantherClient(array $options = [], array $kernel $browserArguments = $options['browser_arguments'] ?? null; if (null !== $browserArguments && !\is_array($browserArguments)) { - throw new \TypeError(sprintf('Expected key "browser_arguments" to be an array or null, "%s" given.', get_debug_type($browserArguments))); + throw new \TypeError(\sprintf('Expected key "browser_arguments" to be an array or null, "%s" given.', get_debug_type($browserArguments))); } if (PantherTestCase::FIREFOX === $browser) { - self::$pantherClients[0] = self::$pantherClient = Client::createFirefoxClient(null, $browserArguments, $managerOptions, self::$baseUri); + self::$pantherClients[0] = self::$pantherClient = PantherClient::createFirefoxClient(null, $browserArguments, $managerOptions, self::$baseUri); } else { try { - self::$pantherClients[0] = self::$pantherClient = Client::createChromeClient(null, $browserArguments, $managerOptions, self::$baseUri); + self::$pantherClients[0] = self::$pantherClient = PantherClient::createChromeClient(null, $browserArguments, $managerOptions, self::$baseUri); } catch (RuntimeException $e) { if (PantherTestCase::CHROME === $browser) { throw $e; } - self::$pantherClients[0] = self::$pantherClient = Client::createFirefoxClient(null, $browserArguments, $managerOptions, self::$baseUri); + self::$pantherClients[0] = self::$pantherClient = PantherClient::createFirefoxClient(null, $browserArguments, $managerOptions, self::$baseUri); } if (null === $browser) { @@ -237,7 +237,7 @@ protected static function createHttpBrowserClient(array $options = [], array $ke if (null === self::$httpBrowserClient) { $httpClientOptions = $options['http_client_options'] ?? []; if (!\is_array($httpClientOptions)) { - throw new \TypeError(sprintf('Expected key "http_client_options" to be an array, "%s" given.', get_debug_type($httpClientOptions))); + throw new \TypeError(\sprintf('Expected key "http_client_options" to be an array, "%s" given.', get_debug_type($httpClientOptions))); } // The ScopingHttpClient can't be used cause the HttpBrowser only supports absolute URLs, @@ -250,7 +250,7 @@ protected static function createHttpBrowserClient(array $options = [], array $ke } $urlComponents = parse_url(self::$baseUri); - self::$httpBrowserClient->setServerParameter('HTTP_HOST', sprintf('%s:%s', $urlComponents['host'], $urlComponents['port'])); + self::$httpBrowserClient->setServerParameter('HTTP_HOST', \sprintf('%s:%s', $urlComponents['host'], $urlComponents['port'])); if ('https' === $urlComponents['scheme']) { self::$httpBrowserClient->setServerParameter('HTTPS', 'true'); } diff --git a/src/ProcessManager/ChromeManager.php b/src/ProcessManager/ChromeManager.php index 3b50170a..f9d6f604 100644 --- a/src/ProcessManager/ChromeManager.php +++ b/src/ProcessManager/ChromeManager.php @@ -35,7 +35,7 @@ final class ChromeManager implements BrowserManagerInterface /** * @throws RuntimeException */ - public function __construct(string $chromeDriverBinary = null, array $arguments = null, array $options = []) + public function __construct(?string $chromeDriverBinary = null, ?array $arguments = null, array $options = []) { $this->options = $options ? array_merge($this->getDefaultOptions(), $options) : $this->getDefaultOptions(); $this->process = $this->createProcess($chromeDriverBinary ?: $this->findChromeDriverBinary()); diff --git a/src/ProcessManager/FirefoxManager.php b/src/ProcessManager/FirefoxManager.php index a15304a9..d7465da1 100644 --- a/src/ProcessManager/FirefoxManager.php +++ b/src/ProcessManager/FirefoxManager.php @@ -34,7 +34,7 @@ final class FirefoxManager implements BrowserManagerInterface /** * @throws RuntimeException */ - public function __construct(string $geckodriverBinary = null, array $arguments = null, array $options = []) + public function __construct(?string $geckodriverBinary = null, ?array $arguments = null, array $options = []) { $this->options = array_merge($this->getDefaultOptions(), $options); $this->process = new Process([$geckodriverBinary ?: $this->findGeckodriverBinary(), '--port='.$this->options['port']], null, null, null, null); diff --git a/src/ProcessManager/SeleniumManager.php b/src/ProcessManager/SeleniumManager.php index a49fd649..77e49e66 100644 --- a/src/ProcessManager/SeleniumManager.php +++ b/src/ProcessManager/SeleniumManager.php @@ -29,8 +29,8 @@ final class SeleniumManager implements BrowserManagerInterface public function __construct( ?string $host = 'http://127.0.0.1:4444/wd/hub', - WebDriverCapabilities $capabilities = null, - ?array $options = [] + ?WebDriverCapabilities $capabilities = null, + ?array $options = [], ) { $this->host = $host; $this->capabilities = $capabilities ?? DesiredCapabilities::chrome(); diff --git a/src/ProcessManager/WebServerManager.php b/src/ProcessManager/WebServerManager.php index 68b51613..9000a0ec 100644 --- a/src/ProcessManager/WebServerManager.php +++ b/src/ProcessManager/WebServerManager.php @@ -32,7 +32,7 @@ final class WebServerManager /** * @throws RuntimeException */ - public function __construct(string $documentRoot, string $hostname, int $port, string $router = '', string $readinessPath = '', array $env = null) + public function __construct(string $documentRoot, string $hostname, int $port, string $router = '', string $readinessPath = '', ?array $env = null) { $this->hostname = $hostname; $this->port = $port; @@ -57,7 +57,7 @@ public function __construct(string $documentRoot, string $hostname, int $port, s [ '-dvariables_order=EGPCS', '-S', - sprintf('%s:%d', $this->hostname, $this->port), + \sprintf('%s:%d', $this->hostname, $this->port), '-t', $documentRoot, $router, diff --git a/src/ProcessManager/WebServerReadinessProbeTrait.php b/src/ProcessManager/WebServerReadinessProbeTrait.php index 74c5be65..668a0a8d 100644 --- a/src/ProcessManager/WebServerReadinessProbeTrait.php +++ b/src/ProcessManager/WebServerReadinessProbeTrait.php @@ -37,7 +37,7 @@ private function checkPortAvailable(string $hostname, int $port, bool $throw = t if (\is_resource($resource)) { fclose($resource); if ($throw) { - throw new RuntimeException(sprintf('The port %d is already in use.', $port)); + throw new RuntimeException(\sprintf('The port %d is already in use.', $port)); } } } @@ -51,7 +51,7 @@ public function waitUntilReady(Process $process, string $url, string $service, b while (true) { $status = $process->getStatus(); if (Process::STATUS_TERMINATED === $status) { - throw new RuntimeException(sprintf('Could not start %s. Exit code: %d (%s). Error output: %s', $service, $process->getExitCode(), $process->getExitCodeText(), $process->getErrorOutput())); + throw new RuntimeException(\sprintf('Could not start %s. Exit code: %d (%s). Error output: %s', $service, $process->getExitCode(), $process->getExitCodeText(), $process->getErrorOutput())); } if (Process::STATUS_STARTED !== $status) { diff --git a/src/ServerExtensionLegacy.php b/src/ServerExtensionLegacy.php index 8cbdbd8b..7088365c 100644 --- a/src/ServerExtensionLegacy.php +++ b/src/ServerExtensionLegacy.php @@ -55,12 +55,12 @@ public function executeAfterLastTest(): void public function executeAfterTestError(string $test, string $message, float $time): void { - $this->pause(sprintf('Error: %s', $message)); + $this->pause(\sprintf('Error: %s', $message)); } public function executeAfterTestFailure(string $test, string $message, float $time): void { - $this->pause(sprintf('Failure: %s', $message)); + $this->pause(\sprintf('Failure: %s', $message)); } private static function reset(): void @@ -75,7 +75,7 @@ public static function takeScreenshots(string $type, string $test): void } foreach (self::$registeredClients as $i => $client) { - $screenshotPath = sprintf('%s/%s_%s_%s-%d.png', + $screenshotPath = \sprintf('%s/%s_%s_%s-%d.png', $_SERVER['PANTHER_ERROR_SCREENSHOT_DIR'], date('Y-m-d_H-i-s'), $type, diff --git a/src/WebDriver/WebDriverCheckbox.php b/src/WebDriver/WebDriverCheckbox.php index 635dda6a..0b3055fa 100644 --- a/src/WebDriver/WebDriverCheckbox.php +++ b/src/WebDriver/WebDriverCheckbox.php @@ -176,7 +176,7 @@ private function byValue($value, $select = true): void } if (!$matched) { - throw new NoSuchElementException(sprintf('Cannot locate option with value: %s', $value)); + throw new NoSuchElementException(\sprintf('Cannot locate option with value: %s', $value)); } } @@ -184,7 +184,7 @@ private function byIndex($index, $select = true): void { $options = $this->getRelatedElements(); if (!isset($options[$index])) { - throw new NoSuchElementException(sprintf('Cannot locate option with index: %d', $index)); + throw new NoSuchElementException(\sprintf('Cannot locate option with index: %d', $index)); } $select ? $this->selectOption($options[$index]) : $this->deselectOption($options[$index]); @@ -193,15 +193,15 @@ private function byIndex($index, $select = true): void private function byVisibleText($text, $partial = false, $select = true): void { foreach ($this->getRelatedElements() as $element) { - $normalizeFilter = sprintf($partial ? 'contains(normalize-space(.), %s)' : 'normalize-space(.) = %s', XPathEscaper::escapeQuotes($text)); + $normalizeFilter = \sprintf($partial ? 'contains(normalize-space(.), %s)' : 'normalize-space(.) = %s', XPathEscaper::escapeQuotes($text)); $xpath = 'ancestor::label'; - $xpathNormalize = sprintf('%s[%s]', $xpath, $normalizeFilter); + $xpathNormalize = \sprintf('%s[%s]', $xpath, $normalizeFilter); if (null !== $id = $element->getAttribute('id')) { - $idFilter = sprintf('@for = %s', XPathEscaper::escapeQuotes($id)); + $idFilter = \sprintf('@for = %s', XPathEscaper::escapeQuotes($id)); - $xpath .= sprintf(' | //label[%s]', $idFilter); - $xpathNormalize .= sprintf(' | //label[%s and %s]', $idFilter, $normalizeFilter); + $xpath .= \sprintf(' | //label[%s]', $idFilter); + $xpathNormalize .= \sprintf(' | //label[%s and %s]', $idFilter, $normalizeFilter); } try { @@ -231,16 +231,16 @@ private function byVisibleText($text, $partial = false, $select = true): void private function getRelatedElements($value = null): array { - $valueSelector = $value ? sprintf(' and @value = %s', XPathEscaper::escapeQuotes($value)) : ''; + $valueSelector = $value ? \sprintf(' and @value = %s', XPathEscaper::escapeQuotes($value)) : ''; if (null === $formId = $this->element->getAttribute('form')) { $form = $this->element->findElement(WebDriverBy::xpath('ancestor::form')); if ('' === $formId = (string) $form->getAttribute('id')) { - return $form->findElements(WebDriverBy::xpath(sprintf('.//input[@name = %s%s]', XPathEscaper::escapeQuotes($this->name), $valueSelector))); + return $form->findElements(WebDriverBy::xpath(\sprintf('.//input[@name = %s%s]', XPathEscaper::escapeQuotes($this->name), $valueSelector))); } } return $this->element->findElements(WebDriverBy::xpath( - sprintf('//form[@id = %1$s]//input[@name = %2$s%3$s] | //input[@form = %1$s and @name = %2$s%3$s]', XPathEscaper::escapeQuotes($formId), XPathEscaper::escapeQuotes($this->name), $valueSelector) + \sprintf('//form[@id = %1$s]//input[@name = %2$s%3$s] | //input[@form = %1$s and @name = %2$s%3$s]', XPathEscaper::escapeQuotes($formId), XPathEscaper::escapeQuotes($this->name), $valueSelector) )); } diff --git a/src/WebDriver/WebDriverMouse.php b/src/WebDriver/WebDriverMouse.php index 3f9adaf9..f9cd7a58 100644 --- a/src/WebDriver/WebDriverMouse.php +++ b/src/WebDriver/WebDriverMouse.php @@ -110,7 +110,7 @@ private function toCoordinates($cssSelector): WebDriverCoordinates $element = $this->client->getCrawler()->filter($cssSelector)->getElement(0); if (!$element instanceof WebDriverLocatable) { - throw new RuntimeException(sprintf('The element of "%s" CSS selector does not implement "%s".', $cssSelector, WebDriverLocatable::class)); + throw new RuntimeException(\sprintf('The element of "%s" CSS selector does not implement "%s".', $cssSelector, WebDriverLocatable::class)); } return $element->getCoordinates(); diff --git a/src/WebTestAssertionsTrait.php b/src/WebTestAssertionsTrait.php index 09cb761d..5e8098be 100644 --- a/src/WebTestAssertionsTrait.php +++ b/src/WebTestAssertionsTrait.php @@ -194,7 +194,7 @@ public static function assertSelectorWillBeDisabled(string $locator): void self::assertSelectorAttributeContains($locator, 'disabled', 'true'); } - public static function assertSelectorAttributeContains(string $locator, string $attribute, string $text = null): void + public static function assertSelectorAttributeContains(string $locator, string $attribute, ?string $text = null): void { if (null === $text) { self::assertNull(self::getAttribute($locator, $attribute)); @@ -259,7 +259,7 @@ private static function findElement(string $locator): WebDriverElement { $client = self::getClient(); if (!$client instanceof PantherClient) { - throw new LogicException(sprintf('Using a client that is not an instance of "%s" is not supported.', PantherClient::class)); + throw new LogicException(\sprintf('Using a client that is not an instance of "%s" is not supported.', PantherClient::class)); } $by = $client::createWebDriverByFromLocator($locator); diff --git a/tests/DomCrawler/CrawlerTest.php b/tests/DomCrawler/CrawlerTest.php index cc313b8a..94b09d4a 100644 --- a/tests/DomCrawler/CrawlerTest.php +++ b/tests/DomCrawler/CrawlerTest.php @@ -81,7 +81,7 @@ public function testFilterXpath(callable $clientFactory): void $this->assertSame('36', $crawler->text(null, true)); break; default: - $this->fail(sprintf('Unexpected index "%d".', $i)); + $this->fail(\sprintf('Unexpected index "%d".', $i)); } }); } diff --git a/tests/DomCrawler/Field/FileFormFieldTest.php b/tests/DomCrawler/Field/FileFormFieldTest.php index 13cbc928..7e4ad01b 100644 --- a/tests/DomCrawler/Field/FileFormFieldTest.php +++ b/tests/DomCrawler/Field/FileFormFieldTest.php @@ -126,7 +126,7 @@ public function testPreventIsNotCanonicalError(callable $clientFactory): void $fileFormField = $form['file_upload']; $this->assertInstanceOf(FileFormField::class, $fileFormField); - $nonCanonicalPath = sprintf('%s/../fixtures/%s', self::$webServerDir, self::$uploadFileName); + $nonCanonicalPath = \sprintf('%s/../fixtures/%s', self::$webServerDir, self::$uploadFileName); $fileFormField->upload($nonCanonicalPath); $fileFormField->setValue($nonCanonicalPath); diff --git a/tests/DummyKernel.php b/tests/DummyKernel.php index 87141281..a0ebb123 100644 --- a/tests/DummyKernel.php +++ b/tests/DummyKernel.php @@ -85,7 +85,7 @@ public function getRootDir(): string public function getContainer(): ContainerInterface { - return new class() implements ContainerInterface { + return new class implements ContainerInterface { public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE): ?object { return new \stdClass(); diff --git a/tests/TestCase.php b/tests/TestCase.php index 2541a58b..d59d043f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -49,6 +49,6 @@ protected function request(callable $clientFactory, string $path): Crawler protected function getUploadFilePath(string $fileName): string { - return sprintf('%s/%s', self::$webServerDir, $fileName); + return \sprintf('%s/%s', self::$webServerDir, $fileName); } }