Skip to content

Commit 9917f08

Browse files
Add support for Symfony 6 (#509)
1 parent 6da0256 commit 9917f08

File tree

16 files changed

+122
-54
lines changed

16 files changed

+122
-54
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup PHP
1616
uses: shivammathur/setup-php@v2
1717
with:
18-
php-version: '7.4' # PHP CS Fixer isn't compatible with PHP 8 yet https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/4702
18+
php-version: '8.0'
1919
tools: php-cs-fixer, cs2pr
2020

2121
- name: PHP Coding Standards Fixer
@@ -58,7 +58,7 @@ jobs:
5858
runs-on: ubuntu-latest
5959
strategy:
6060
matrix:
61-
php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0']
61+
php-versions: ['8.0']
6262
fail-fast: false
6363
name: PHP ${{ matrix.php-versions }} Test on ubuntu-latest
6464
steps:
@@ -88,6 +88,43 @@ jobs:
8888
- name: Run tests
8989
run: vendor/bin/simple-phpunit
9090

91+
phpunit-dev:
92+
runs-on: ubuntu-latest
93+
strategy:
94+
matrix:
95+
php-versions: ['8.0']
96+
fail-fast: false
97+
name: PHP ${{ matrix.php-versions }} Test dev dependencies on ubuntu-latest
98+
steps:
99+
- name: Checkout
100+
uses: actions/checkout@v2
101+
102+
- name: Setup PHP
103+
uses: shivammathur/setup-php@v2
104+
with:
105+
php-version: ${{ matrix.php-versions }}
106+
extensions: zip
107+
108+
- name: Get composer cache directory
109+
id: composercache
110+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
111+
112+
- name: Cache dependencies
113+
uses: actions/cache@v2
114+
with:
115+
path: ${{ steps.composercache.outputs.dir }}
116+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
117+
restore-keys: ${{ runner.os }}-composer-
118+
119+
- name: Allow dev dependencies
120+
run: composer config minimum-stability dev
121+
122+
- name: Install dependencies
123+
run: composer install --prefer-dist
124+
125+
- name: Run tests
126+
run: vendor/bin/simple-phpunit
127+
91128
phpunit-lowest:
92129
runs-on: ubuntu-latest
93130
name: PHP 8.0 (lowest) Test on ubuntu-latest

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
}
1818
],
1919
"require": {
20-
"php": ">=7.1",
20+
"php": ">=8.0",
2121
"ext-dom": "*",
2222
"ext-libxml": "*",
2323
"php-webdriver/webdriver": "^1.8.2",
24-
"symfony/browser-kit": "^4.4 || ^5.0",
24+
"symfony/browser-kit": "^4.4 || ^5.0 || ^6.0",
2525
"symfony/deprecation-contracts": "^2.4",
26-
"symfony/dom-crawler": "^4.4 || ^5.0",
27-
"symfony/http-client": "^4.4.11 || ^5.2",
26+
"symfony/dom-crawler": "^4.4 || ^5.0 || ^6.0",
27+
"symfony/http-client": "^4.4.11 || ^5.2 || ^6.0",
2828
"symfony/polyfill-php72": "^1.9",
29-
"symfony/process": "^4.4 || ^5.0"
29+
"symfony/process": "^4.4 || ^5.0 || ^6.0"
3030
},
3131
"autoload": {
3232
"psr-4": { "Symfony\\Component\\Panther\\": "src/" }
@@ -43,9 +43,9 @@
4343
"sort-packages": true
4444
},
4545
"require-dev": {
46-
"symfony/css-selector": "^4.4 || ^5.0",
47-
"symfony/framework-bundle": "^4.4 || ^5.0",
48-
"symfony/mime": "^4.4 || ^5.0",
49-
"symfony/phpunit-bridge": "^5.2"
46+
"symfony/css-selector": "^4.4 || ^5.0 || ^6.0",
47+
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0",
48+
"symfony/mime": "^4.4 || ^5.0 || ^6.0",
49+
"symfony/phpunit-bridge": "^5.2 || ^6.0"
5050
}
5151
}

phpstan.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ parameters:
77
- vendor/bin/.phpunit/phpunit/vendor/autoload.php
88
inferPrivatePropertyTypeFromConstructor: true
99
ignoreErrors:
10-
- message: '#.+#'
11-
path: tests/DummyKernel.php
1210
# False positive
1311
- '#Call to an undefined method ReflectionType::getName\(\)\.#'
1412
# To fix in PHP WebDriver

src/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ public function start(): void
139139
$this->isFirefox = false;
140140
}
141141

142-
public function getRequest()
142+
public function getRequest(): object
143143
{
144144
throw new \LogicException('HttpFoundation Request object is not available when using WebDriver.');
145145
}
146146

147-
public function getResponse()
147+
public function getResponse(): object
148148
{
149149
throw new \LogicException('HttpFoundation Response object is not available when using WebDriver.');
150150
}
@@ -190,7 +190,7 @@ public function setServerParameter($key, $value): void
190190
throw new \InvalidArgumentException('Server parameters cannot be set when using WebDriver.');
191191
}
192192

193-
public function getServerParameter($key, $default = '')
193+
public function getServerParameter($key, $default = ''): mixed
194194
{
195195
throw new \InvalidArgumentException('Server parameters cannot be retrieved when using WebDriver.');
196196
}

src/DomCrawler/Crawler.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(array $elements = [], ?WebDriver $webDriver = null,
3838
{
3939
$this->uri = $uri;
4040
$this->webDriver = $webDriver;
41-
$this->elements = $elements ?? [];
41+
$this->elements = $elements;
4242
}
4343

4444
public function clear(): void
@@ -86,7 +86,7 @@ public function addNode(\DOMNode $node): void
8686
throw $this->createNotSupportedException(__METHOD__);
8787
}
8888

89-
public function eq($position): self
89+
public function eq($position): static
9090
{
9191
if (isset($this->elements[$position])) {
9292
return $this->createSubCrawler([$this->elements[$position]]);
@@ -105,12 +105,12 @@ public function each(\Closure $closure): array
105105
return $data;
106106
}
107107

108-
public function slice($offset = 0, $length = null): self
108+
public function slice($offset = 0, $length = null): static
109109
{
110110
return $this->createSubCrawler(\array_slice($this->elements, $offset, $length));
111111
}
112112

113-
public function reduce(\Closure $closure): self
113+
public function reduce(\Closure $closure): static
114114
{
115115
$elements = [];
116116
foreach ($this->elements as $i => $element) {
@@ -122,22 +122,22 @@ public function reduce(\Closure $closure): self
122122
return $this->createSubCrawler($elements);
123123
}
124124

125-
public function last(): self
125+
public function last(): static
126126
{
127127
return $this->eq(\count($this->elements) - 1);
128128
}
129129

130-
public function siblings(): self
130+
public function siblings(): static
131131
{
132132
return $this->createSubCrawlerFromXpath('(preceding-sibling::* | following-sibling::*)');
133133
}
134134

135-
public function nextAll(): self
135+
public function nextAll(): static
136136
{
137137
return $this->createSubCrawlerFromXpath('following-sibling::*');
138138
}
139139

140-
public function previousAll(): self
140+
public function previousAll(): static
141141
{
142142
return $this->createSubCrawlerFromXpath('preceding-sibling::*');
143143
}
@@ -149,15 +149,15 @@ public function parents(): self
149149
return $this->ancestors();
150150
}
151151

152-
public function ancestors(): self
152+
public function ancestors(): static
153153
{
154154
return $this->createSubCrawlerFromXpath('ancestor::*', true);
155155
}
156156

157157
/**
158158
* @see https://github.com/symfony/symfony/issues/26432
159159
*/
160-
public function children(string $selector = null): self
160+
public function children(string $selector = null): static
161161
{
162162
$xpath = 'child::*';
163163
if (null !== $selector) {
@@ -219,7 +219,7 @@ public function html(string $default = null): string
219219
}
220220
}
221221

222-
public function evaluate($xpath): self
222+
public function evaluate($xpath): static
223223
{
224224
throw $this->createNotSupportedException(__METHOD__);
225225
}
@@ -241,29 +241,29 @@ public function extract($attributes): array
241241
return $data;
242242
}
243243

244-
public function filterXPath($xpath): self
244+
public function filterXPath($xpath): static
245245
{
246246
return $this->filterWebDriverBy(WebDriverBy::xpath($xpath));
247247
}
248248

249-
public function filter($selector): self
249+
public function filter($selector): static
250250
{
251251
return $this->filterWebDriverBy(WebDriverBy::cssSelector($selector));
252252
}
253253

254-
public function selectLink($value): self
254+
public function selectLink($value): static
255255
{
256256
return $this->selectFromXpath(
257257
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.' '))
258258
);
259259
}
260260

261-
public function selectImage($value): self
261+
public function selectImage($value): static
262262
{
263263
return $this->selectFromXpath(sprintf('descendant-or-self::img[contains(normalize-space(string(@alt)), %s)]', self::xpathLiteral($value)));
264264
}
265265

266-
public function selectButton($value): self
266+
public function selectButton($value): static
267267
{
268268
return $this->selectFromXpath(
269269
sprintf(

src/DomCrawler/Field/ChoiceFormField.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function untick(): void
7979
$this->setValue(false);
8080
}
8181

82-
public function getValue()
82+
public function getValue(): array|string|null
8383
{
8484
$type = $this->element->getAttribute('type');
8585

@@ -182,7 +182,7 @@ public function availableOptionValues(): array
182182
/**
183183
* Disables the internal validation of the field.
184184
*/
185-
public function disableValidation(): self
185+
public function disableValidation(): static
186186
{
187187
throw $this->createNotSupportedException(__METHOD__);
188188
}

src/DomCrawler/Field/FileFormField.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ final class FileFormField extends BaseFileFormField
2424

2525
/**
2626
* @var array
27+
*
28+
* @phpstan-ignore-next-line
2729
*/
2830
protected $value;
2931

30-
public function getValue()
32+
public function getValue(): array|string|null
3133
{
3234
return $this->value;
3335
}

src/DomCrawler/Field/FormFieldTrait.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(WebDriverElement $element)
3434
$this->initialize();
3535
}
3636

37-
public function getLabel(): void
37+
public function getLabel(): ?\DOMElement
3838
{
3939
throw $this->createNotSupportedException(__METHOD__);
4040
}
@@ -44,10 +44,7 @@ public function getName(): string
4444
return $this->element->getAttribute('name') ?? '';
4545
}
4646

47-
/**
48-
* @return string|array|null
49-
*/
50-
public function getValue()
47+
public function getValue(): array|string|null
5148
{
5249
return $this->element->getAttribute('value');
5350
}

src/DomCrawler/Form.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ public function getFormNode(): \DOMElement
103103
throw $this->createNotSupportedException(__METHOD__);
104104
}
105105

106-
public function setValues(array $values): self
106+
/**
107+
* Disables the internal validation of the field.
108+
*/
109+
public function setValues(array $values): static
107110
{
108111
foreach ($values as $name => $value) {
109112
$this->setValue($name, $value);
@@ -212,7 +215,12 @@ public function set(FormField $field): void
212215
$this->setValue($field->getName(), $field->getValue());
213216
}
214217

215-
public function get($name)
218+
/**
219+
* @param mixed $name
220+
*
221+
* @return FormField|FormField[]|FormField[][]
222+
*/
223+
public function get($name): FormField|array
216224
{
217225
return $this->getFormField($this->getFormElement($name));
218226
}
@@ -239,8 +247,7 @@ public function offsetExists($name): bool
239247
*
240248
* @return FormField|FormField[]|FormField[][]
241249
*/
242-
#[\ReturnTypeWillChange]
243-
public function offsetGet($name)
250+
public function offsetGet($name): FormField|array
244251
{
245252
return $this->get($name);
246253
}

src/DomCrawler/Link.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getElement(): WebDriverElement
4343
return $this->element;
4444
}
4545

46-
public function getNode()
46+
public function getNode(): \DOMElement
4747
{
4848
throw $this->createNotSupportedException(__METHOD__);
4949
}

0 commit comments

Comments
 (0)