Skip to content

Commit a9cca9b

Browse files
committed
feature #517 minor: More cleanups and type declarations for v2 (chalasr)
This PR was merged into the 2.0.x-dev branch. Discussion ---------- minor: More cleanups and type declarations for v2 Also removes support for Symfony 4.4 (1.x supports it). Commits ------- 18f8ce4 minor: More cleanups and type declarations for v2
2 parents 0d26a6b + 18f8ce4 commit a9cca9b

22 files changed

+64
-115
lines changed

composer.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
"ext-dom": "*",
2222
"ext-libxml": "*",
2323
"php-webdriver/webdriver": "^1.8.2",
24-
"symfony/browser-kit": "^4.4 || ^5.0 || ^6.0",
25-
"symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0",
24+
"symfony/browser-kit": "^5.3 || ^6.0",
25+
"symfony/dependency-injection": "^5.3 || ^6.0",
2626
"symfony/deprecation-contracts": "^2.4 || ^3",
27-
"symfony/dom-crawler": "^4.4 || ^5.0 || ^6.0",
28-
"symfony/http-client": "^4.4.11 || ^5.2 || ^6.0",
29-
"symfony/http-kernel": "^4.4 || ^5.0 || ^6.0",
30-
"symfony/process": "^4.4 || ^5.0 || ^6.0"
27+
"symfony/dom-crawler": "^5.3 || ^6.0",
28+
"symfony/http-client": "^5.3 || ^6.0",
29+
"symfony/http-kernel": "^5.3 || ^6.0",
30+
"symfony/process": "^5.3 || ^6.0"
3131
},
3232
"autoload": {
3333
"psr-4": { "Symfony\\Component\\Panther\\": "src/" }
@@ -44,9 +44,9 @@
4444
"sort-packages": true
4545
},
4646
"require-dev": {
47-
"symfony/css-selector": "^4.4 || ^5.0 || ^6.0",
48-
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0",
49-
"symfony/mime": "^4.4 || ^5.0 || ^6.0",
50-
"symfony/phpunit-bridge": "^5.2 || ^6.0"
47+
"symfony/css-selector": "^5.3 || ^6.0",
48+
"symfony/framework-bundle": "^5.3 || ^6.0",
49+
"symfony/mime": "^5.3 || ^6.0",
50+
"symfony/phpunit-bridge": "^5.3 || ^6.0"
5151
}
5252
}

phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ parameters:
1616
# Require a redesign of the underlying Symfony components
1717
- '#Call to an undefined method DOMNode::getTagName\(\)\.#'
1818
- '#Return type \(void\) of method Symfony\\Component\\Panther\\DomCrawler\\Crawler::clear\(\) should be compatible with return type \(Facebook\\WebDriver\\WebDriverElement\) of method Facebook\\WebDriver\\WebDriverElement::clear\(\)#'
19-
- '#Method Symfony\\Component\\Panther\\DomCrawler\\Crawler::getIterator\(\) should return ArrayIterator<int, DOMNode> but returns ArrayIterator<\(int\|string\), Facebook\\WebDriver\\WebDriverElement>\.#'

src/Client.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,10 @@ final class Client extends AbstractBrowser implements WebDriver, JavaScriptExecu
5656
{
5757
use ExceptionThrower;
5858

59-
/**
60-
* @var WebDriver|null
61-
*/
62-
private $webDriver;
63-
private $browserManager;
64-
private $baseUri;
65-
private $isFirefox = false;
59+
private ?WebDriver $webDriver = null;
60+
private BrowserManagerInterface $browserManager;
61+
private ?string $baseUri = null;
62+
private bool $isFirefox = false;
6663

6764
/**
6865
* @param string[]|null $arguments

src/Cookie/CookieJar.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class CookieJar extends BaseCookieJar
2828
{
2929
use ExceptionThrower;
3030

31-
private $webDriver;
31+
private WebDriver $webDriver;
3232

3333
public function __construct(WebDriver $webDriver)
3434
{
@@ -146,7 +146,7 @@ private function getWebDriverCookie(string $name, string $path = '/', ?string $d
146146
}
147147

148148
$cookiePath = $cookie->getPath() ?? '/';
149-
if (0 !== strpos($path, $cookiePath)) {
149+
if (!str_starts_with($path, $cookiePath)) {
150150
return null;
151151
}
152152

src/DomCrawler/Crawler.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ final class Crawler extends BaseCrawler implements WebDriverElement
2828
{
2929
use ExceptionThrower;
3030

31-
private $elements;
32-
private $webDriver;
31+
private array $elements;
32+
private ?WebDriver $webDriver;
3333

3434
/**
3535
* @param WebDriverElement[] $elements
@@ -142,13 +142,6 @@ public function previousAll(): static
142142
return $this->createSubCrawlerFromXpath('preceding-sibling::*');
143143
}
144144

145-
public function parents(): self
146-
{
147-
trigger_deprecation('symfony/panther', '1.1', 'The %s() method is deprecated, use ancestors() instead.', __METHOD__);
148-
149-
return $this->ancestors();
150-
}
151-
152145
public function ancestors(): static
153146
{
154147
return $this->createSubCrawlerFromXpath('ancestor::*', true);

src/DomCrawler/Field/ChoiceFormField.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,8 @@ final class ChoiceFormField extends BaseChoiceFormField
2525
{
2626
use FormFieldTrait;
2727

28-
/**
29-
* @var string
30-
*/
31-
private $type;
32-
33-
/**
34-
* @var WebDriverSelectInterface
35-
*/
36-
private $selector;
28+
private string $type;
29+
private WebDriverSelectInterface $selector;
3730

3831
public function hasValue(): bool
3932
{

src/DomCrawler/Field/FileFormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function setValue($value): void
6060
*
6161
* @param string $path The path to the file
6262
*/
63-
public function setFilePath($path): void
63+
public function setFilePath(string $path): void
6464
{
6565
$this->element->sendKeys($this->sanitizeValue($path));
6666
}

src/DomCrawler/Field/FormFieldTrait.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ trait FormFieldTrait
2626
{
2727
use ExceptionThrower;
2828

29-
private $element;
29+
private WebDriverElement $element;
3030

3131
public function __construct(WebDriverElement $element)
3232
{
@@ -54,15 +54,12 @@ public function isDisabled(): bool
5454
return null !== $this->element->getAttribute('disabled');
5555
}
5656

57-
private function setTextValue($value): void
57+
private function setTextValue(?string $value): void
5858
{
5959
// Ensure to clean field before sending keys.
6060
// Unable to use $this->element->clear(); because it triggers a change event on it's own which is unexpected behavior.
6161

6262
$v = $this->getValue();
63-
if (\is_array($v)) {
64-
throw new \InvalidArgumentException('The value must not be an array');
65-
}
6663

6764
$existingValueLength = \strlen($v);
6865
$deleteKeys = str_repeat(WebDriverKeys::BACKSPACE.WebDriverKeys::DELETE, $existingValueLength);

src/DomCrawler/Field/TextareaFormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class TextareaFormField extends BaseTextareaFormField
2222
{
2323
use FormFieldTrait;
2424

25-
public function setValue($value): void
25+
public function setValue(?string $value): void
2626
{
2727
$this->setTextValue($value);
2828
}

src/DomCrawler/Form.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,9 @@ final class Form extends BaseForm
3737
{
3838
use ExceptionThrower;
3939

40-
/**
41-
* @var WebDriverElement
42-
*/
43-
private $button;
44-
45-
/**
46-
* @var WebDriverElement
47-
*/
48-
private $element;
49-
private $webDriver;
40+
private WebDriverElement $button;
41+
private WebDriverElement $element;
42+
private WebDriver $webDriver;
5043

5144
public function __construct(WebDriverElement $element, WebDriver $webDriver)
5245
{

src/DomCrawler/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class Image extends BaseImage
2424
{
2525
use ExceptionThrower;
2626

27-
private $element;
27+
private WebDriverElement $element;
2828

2929
public function __construct(WebDriverElement $element)
3030
{

src/DomCrawler/Link.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class Link extends BaseLink
2424
{
2525
use ExceptionThrower;
2626

27-
private $element;
27+
private WebDriverElement $element;
2828

2929
public function __construct(WebDriverElement $element, string $currentUri)
3030
{

src/PantherTestCaseTrait.php

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,45 +29,27 @@
2929
*/
3030
trait PantherTestCaseTrait
3131
{
32-
/**
33-
* @var bool
34-
*/
35-
public static $stopServerOnTeardown = true;
32+
public static bool $stopServerOnTeardown = true;
3633

37-
/**
38-
* @var string|null
39-
*/
40-
protected static $webServerDir;
34+
protected static ?string $webServerDir;
4135

42-
/**
43-
* @var WebServerManager|null
44-
*/
45-
protected static $webServerManager;
36+
protected static ?WebServerManager $webServerManager = null;
4637

47-
/**
48-
* @var string|null
49-
*/
50-
protected static $baseUri;
38+
protected static ?string $baseUri = null;
5139

52-
/**
53-
* @var HttpBrowserClient|null
54-
*/
55-
protected static $httpBrowserClient;
40+
protected static ?HttpBrowserClient $httpBrowserClient = null;
5641

5742
/**
5843
* @var PantherClient|null The primary Panther client instance created
5944
*/
60-
protected static $pantherClient;
45+
protected static ?PantherClient $pantherClient = null;
6146

6247
/**
6348
* @var PantherClient[] All Panther clients, the first one is the primary one (aka self::$pantherClient)
6449
*/
65-
protected static $pantherClients = [];
50+
protected static array $pantherClients = [];
6651

67-
/**
68-
* @var array
69-
*/
70-
protected static $defaultOptions = [
52+
protected static array $defaultOptions = [
7153
'webServerDir' => __DIR__.'/../../../../public', // the Flex directory structure
7254
'hostname' => '127.0.0.1',
7355
'port' => 9080,
@@ -251,7 +233,7 @@ private static function getWebServerDir(array $options): string
251233
return self::$defaultOptions['webServerDir'];
252234
}
253235

254-
if (0 === strpos($_SERVER['PANTHER_WEB_SERVER_DIR'], './')) {
236+
if (str_starts_with($_SERVER['PANTHER_WEB_SERVER_DIR'], './')) {
255237
return getcwd().substr($_SERVER['PANTHER_WEB_SERVER_DIR'], 1);
256238
}
257239

src/ProcessManager/ChromeManager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ final class ChromeManager implements BrowserManagerInterface
2727
{
2828
use WebServerReadinessProbeTrait;
2929

30-
private $process;
31-
private $arguments;
32-
private $options;
30+
private Process $process;
31+
private array $arguments;
32+
private array $options;
3333

3434
/**
3535
* @throws \RuntimeException
3636
*/
3737
public function __construct(?string $chromeDriverBinary = null, ?array $arguments = null, array $options = [])
3838
{
39-
$this->options = array_merge($this->getDefaultOptions(), $options);
39+
$this->options = $options ? array_merge($this->getDefaultOptions(), $options) : $this->getDefaultOptions();
4040
$this->process = $this->createProcess($chromeDriverBinary ?: $this->findChromeDriverBinary());
4141
$this->arguments = $arguments ?? $this->getDefaultArguments();
4242
}

src/ProcessManager/FirefoxManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ final class FirefoxManager implements BrowserManagerInterface
2626
{
2727
use WebServerReadinessProbeTrait;
2828

29-
private $process;
30-
private $arguments;
31-
private $options;
29+
private Process $process;
30+
private array $arguments;
31+
private array $options;
3232

3333
/**
3434
* @throws \RuntimeException

src/ProcessManager/SeleniumManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*/
2424
final class SeleniumManager implements BrowserManagerInterface
2525
{
26-
private $host;
27-
private $capabilities;
28-
private $options;
26+
private ?string $host;
27+
private WebDriverCapabilities $capabilities;
28+
private ?array $options;
2929

3030
public function __construct(
3131
?string $host = 'http://127.0.0.1:4444/wd/hub',

src/ProcessManager/WebServerManager.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ final class WebServerManager
2323
{
2424
use WebServerReadinessProbeTrait;
2525

26-
private $hostname;
27-
private $port;
28-
private $readinessPath;
29-
30-
/**
31-
* @var Process
32-
*/
33-
private $process;
26+
private string $hostname;
27+
private int $port;
28+
private string $readinessPath;
29+
private Process $process;
3430

3531
/**
3632
* @throws \RuntimeException

src/ServerExtension.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ final class ServerExtension implements BeforeFirstTestHook, AfterLastTestHook, B
2727
{
2828
use ServerTrait;
2929

30-
/** @var bool */
31-
private static $enabled = false;
30+
private static bool $enabled = false;
3231

3332
/** @var Client[] */
34-
private static $registeredClients = [];
33+
private static array $registeredClients = [];
3534

3635
public static function registerClient(Client $client): void
3736
{

src/ServerTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
trait ServerTrait
2222
{
23-
public $testing = false;
23+
public bool $testing = false;
2424

2525
private function keepServerOnTeardown(): void
2626
{

src/WebDriver/WebDriverCheckbox.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
*/
3636
class WebDriverCheckbox implements WebDriverSelectInterface
3737
{
38-
private $element;
39-
private $type;
40-
private $name;
38+
private WebDriverElement $element;
39+
private string $type;
40+
private string $name;
4141

4242
public function __construct(WebDriverElement $element)
4343
{
@@ -51,7 +51,7 @@ public function __construct(WebDriverElement $element)
5151
}
5252

5353
if (null === $name = $element->getAttribute('name')) {
54-
throw new WebDriverException('The input have a "name" attribute.');
54+
throw new WebDriverException('The input must have a "name" attribute.');
5555
}
5656

5757
$this->element = $element;

src/WebDriver/WebDriverMouse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
*/
2424
final class WebDriverMouse implements BaseWebDriverMouse
2525
{
26-
private $mouse;
27-
private $client;
26+
private BaseWebDriverMouse $mouse;
27+
private Client $client;
2828

2929
public function __construct(BaseWebDriverMouse $mouse, Client $client)
3030
{

tests/TestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*/
2424
abstract class TestCase extends PantherTestCase
2525
{
26-
protected static $uploadFileName = 'some-file.txt';
27-
protected static $anotherUploadFileName = 'another-file.txt';
28-
protected static $webServerDir = __DIR__.'/fixtures';
26+
protected static string $uploadFileName = 'some-file.txt';
27+
protected static string $anotherUploadFileName = 'another-file.txt';
28+
protected static ?string $webServerDir = __DIR__.'/fixtures';
2929

3030
public function clientFactoryProvider(): iterable
3131
{

0 commit comments

Comments
 (0)