Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarStark committed Oct 3, 2024
1 parent bc90c44 commit fc51e59
Show file tree
Hide file tree
Showing 26 changed files with 60 additions and 52 deletions.
6 changes: 3 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,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));
}
}

Expand Down Expand Up @@ -775,9 +775,9 @@ public function ping(int $timeout = 1000): bool
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));
}
}
6 changes: 3 additions & 3 deletions src/DomCrawler/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.' '),
Expand Down
10 changes: 5 additions & 5 deletions src/DomCrawler/Field/ChoiceFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/DomCrawler/Field/FileFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/DomCrawler/Field/InputFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
2 changes: 1 addition & 1 deletion src/DomCrawler/Field/TextareaFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
8 changes: 4 additions & 4 deletions src/DomCrawler/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -168,7 +168,7 @@ public function getFiles(): array
continue;
}

if ($field instanceof Field\FileFormField) {
if ($field instanceof FileFormField) {
$files[$field->getName()] = $field->getValue();
}
}
Expand Down Expand Up @@ -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.'[]'))
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/DomCrawler/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/DomCrawler/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\Panther\Exception;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\Panther\Exception;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/LogicException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\Panther\Exception;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\Panther\Exception;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ExceptionThrower.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
14 changes: 7 additions & 7 deletions src/PantherTestCaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion src/ProcessManager/SeleniumManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class SeleniumManager implements BrowserManagerInterface
public function __construct(
?string $host = 'http://127.0.0.1:4444/wd/hub',
WebDriverCapabilities $capabilities = null,
?array $options = []
?array $options = [],
) {
$this->host = $host;
$this->capabilities = $capabilities ?? DesiredCapabilities::chrome();
Expand Down
2 changes: 1 addition & 1 deletion src/ProcessManager/WebServerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/ProcessManager/WebServerReadinessProbeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/ServerExtensionLegacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Loading

0 comments on commit fc51e59

Please sign in to comment.