Skip to content

Commit 28fb70a

Browse files
committed
Specify branch explicitly; fix Selenium2Driver workflow
1 parent d868dd1 commit 28fb70a

22 files changed

+161
-107
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
with:
4040
name: ${{ matrix.name }}
4141
driverRepoUrl: ${{ matrix.driverRepoUrl }}
42+
driverRepoBranch: ${{ matrix.driverRepoBranch }}
4243
php: ${{ matrix.php }}
4344
setUpCmd: ${{ matrix.setUpCmd }}
4445
testCmd: ${{ matrix.testCmd }}
@@ -49,18 +50,21 @@ jobs:
4950
include:
5051
- name: "BrowserKit (http client)"
5152
driverRepoUrl: "https://github.com/minkphp/MinkBrowserKitDriver.git"
53+
driverRepoBranch: "master"
5254
php: "7.2"
5355
# language=bash
5456
testCmd: ./vendor/bin/phpunit --colors=always --testdox --configuration ./phpunit.http_client.xml
5557

5658
- name: "BrowserKit (http kernel)"
5759
driverRepoUrl: "https://github.com/minkphp/MinkBrowserKitDriver.git"
60+
driverRepoBranch: "master"
5861
php: "7.2"
5962
# language=bash
6063
testCmd: ./vendor/bin/phpunit --colors=always --testdox
6164

6265
- name: "Selenium2"
6366
driverRepoUrl: "https://github.com/minkphp/MinkSelenium2Driver.git"
67+
driverRepoBranch: "master"
6468
php: "7.2"
6569
# language=bash
6670
setUpCmd: |
@@ -70,6 +74,7 @@ jobs:
7074
# language=bash
7175
testCmd: |
7276
export WEB_FIXTURES_BROWSER=firefox
77+
export SELENIUM_VERSION=2.53.1
7378
export DRIVER_MACHINE_BASE_PATH=/fixtures/
7479
export WEB_FIXTURES_HOST=http://host.docker.internal:8002
7580
./vendor/bin/phpunit --colors=always --testdox
@@ -79,6 +84,7 @@ jobs:
7984
8085
- name: "WebDriver-Classic"
8186
driverRepoUrl: "https://github.com/minkphp/webdriver-classic-driver.git"
87+
driverRepoBranch: "main"
8288
php: "7.4"
8389
# language=bash
8490
setUpCmd: |
@@ -102,6 +108,7 @@ jobs:
102108
with:
103109
name: ${{ matrix.name }}
104110
driverRepoUrl: ${{ matrix.driverRepoUrl }}
111+
driverRepoBranch: ${{ matrix.driverRepoBranch }}
105112
php: ${{ matrix.php }}
106113
setUpCmd: ${{ matrix.setUpCmd }}
107114
testCmd: ${{ matrix.testCmd }}
@@ -112,6 +119,7 @@ jobs:
112119
include:
113120
- name: "Chrome"
114121
driverRepoUrl: "https://gitlab.com/behat-chrome/chrome-mink-driver.git"
122+
driverRepoBranch: "main"
115123
php: "7.4"
116124
# language=bash
117125
setUpCmd: |

.github/workflows/test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ on:
99
description: Git URL of the driver repository
1010
required: true
1111
type: string
12+
driverRepoBranch:
13+
description: Driver repository branch to check out
14+
required: true
15+
type: string
1216
php:
1317
description: PHP version for running tests
1418
required: true
@@ -32,7 +36,7 @@ jobs:
3236
steps:
3337
- name: Set up workspace for driver repo
3438
# language=bash
35-
run: git clone ${{ inputs.driverRepoUrl }} .
39+
run: git clone --single-branch --branch "${{ inputs.driverRepoBranch }}" "${{ inputs.driverRepoUrl }}" .
3640

3741
- uses: shivammathur/setup-php@v2
3842
with:

http-kernel-fixtures/cookie_page2.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<body>
1010
Previous cookie: <?php
1111
/** @var \Symfony\Component\HttpFoundation\Request $request */
12-
echo $request->cookies->has('srvr_cookie') ? html_escape_value($request->cookies->get('srvr_cookie')) : 'NO';
12+
echo $request->cookies->has('srvr_cookie') ? html_escape_value($request->cookies->get('srvr_cookie') ?? '') : 'NO';
1313
?>
1414
</body>
1515
</html>

http-kernel-fixtures/sub-folder/cookie_page1.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/** @var \Symfony\Component\HttpFoundation\Request $request */
33
$requestUri = $request->server->get('REQUEST_URI');
4+
assert(is_string($requestUri));
45
$resp = new Symfony\Component\HttpFoundation\Response();
56
$cook = Symfony\Component\HttpFoundation\Cookie::create('srvr_cookie', 'srv_var_is_set_sub_folder', 0, dirname($requestUri));
67
$resp->headers->setCookie($cook);

http-kernel-fixtures/sub-folder/cookie_page4.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22
/** @var \Symfony\Component\HttpFoundation\Request $request */
33
$resp = new Symfony\Component\HttpFoundation\Response();
4-
$cookiePath = dirname($request->server->get('REQUEST_URI')) . '/';
4+
$requestUri = $request->server->get('REQUEST_URI');
5+
assert(is_string($requestUri));
6+
$cookiePath = dirname($requestUri) . '/';
57
$cookie = Symfony\Component\HttpFoundation\Cookie::create('srvr_cookie', 'srv_var_is_set', 0, $cookiePath);
68
$resp->headers->setCookie($cookie);
79
?>

phpstan.dist.neon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
parameters:
2-
level: 8
2+
level: 9
33
paths:
44
- src
55
- tests
66
- http-kernel-fixtures
77
- web-fixtures
8-
checkMissingIterableValueType: false
98

109
includes:
1110
- vendor/phpstan/phpstan-phpunit/extension.neon

src/FixturesKernel.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Behat\Mink\Tests\Driver\Util;
44

5+
use Behat\Mink\Tests\Driver\TestCase;
56
use Symfony\Component\HttpFoundation\Cookie;
67
use Symfony\Component\HttpFoundation\Request;
78
use Symfony\Component\HttpFoundation\Response;
@@ -25,8 +26,8 @@ public function handle(Request $request, $type = 1 /* self::MAIN_REQUEST */ , $c
2526

2627
private function handleFixtureRequest(Request $request): Response
2728
{
28-
$fixturesDir = realpath(__DIR__ . '/../web-fixtures');
29-
$overwriteDir = realpath(__DIR__ . '/../http-kernel-fixtures');
29+
$fixturesDir = realpath(TestCase::WEB_FIXTURES_DIR);
30+
$overwriteDir = realpath(TestCase::KERNEL_FIXTURES_DIR);
3031

3132
require_once $fixturesDir . '/utils.php';
3233

@@ -61,7 +62,7 @@ private function prepareSession(Request $request): void
6162
$cookies = $request->cookies;
6263

6364
if ($cookies->has($session->getName())) {
64-
$session->setId($cookies->get($session->getName()));
65+
$session->setId((string) $cookies->get($session->getName()));
6566
} else {
6667
$session->migrate(false);
6768
}

tests/AbstractConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ abstract public function createDriver();
2222
*/
2323
public function mapRemoteFilePath($file)
2424
{
25-
if (!isset($_SERVER['TEST_MACHINE_BASE_PATH']) || !isset($_SERVER['DRIVER_MACHINE_BASE_PATH'])) {
25+
if (!isset($_SERVER['TEST_MACHINE_BASE_PATH'], $_SERVER['DRIVER_MACHINE_BASE_PATH'])) {
2626
return $file;
2727
}
2828

tests/Basic/BasicAuthTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ public function testSetBasicAuth(string $user, string $pass, string $pageText):
2020
$this->assertStringContainsString($pageText, $session->getPage()->getContent());
2121
}
2222

23+
/**
24+
* @return iterable<string, array{string, string, string}>
25+
*/
2326
public static function setBasicAuthDataProvider(): iterable
2427
{
25-
return [
26-
['mink-user', 'mink-password', 'is authenticated'],
27-
['', '', 'is not authenticated'],
28-
];
28+
yield 'valid credentials' => ['mink-user', 'mink-password', 'is authenticated'];
29+
yield 'no credentials' => ['', '', 'is not authenticated'];
2930
}
3031

3132
public function testBasicAuthInUrl(): void

tests/Basic/BestPracticesTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public function testImplementFindXpath(): void
2424
{
2525
$driver = $this->createDriver();
2626

27-
$this->assertNotImplementMethod('find', $driver, 'The driver should overwrite `findElementXpaths` rather than `find` for forward compatibility with Mink 2.');
28-
$this->assertImplementMethod('findElementXpaths', $driver, 'The driver must be able to find elements.');
29-
$this->assertNotImplementMethod('setSession', $driver, 'The driver should not deal with the Session directly for forward compatibility with Mink 2.');
27+
$this->assertMethodIsNotImplemented('find', $driver, 'The driver should overwrite `findElementXpaths` rather than `find` for forward compatibility with Mink 2.');
28+
$this->assertMethodIsImplemented('findElementXpaths', $driver, 'The driver must be able to find elements.');
29+
$this->assertMethodIsNotImplemented('setSession', $driver, 'The driver should not deal with the Session directly for forward compatibility with Mink 2.');
3030
}
3131

3232
/**
@@ -36,9 +36,12 @@ public function testImplementBasicApi(string $method): void
3636
{
3737
$driver = $this->createDriver();
3838

39-
$this->assertImplementMethod($method, $driver, 'The driver is unusable when this method is not implemented.');
39+
$this->assertMethodIsImplemented($method, $driver, 'The driver is unusable when this method is not implemented.');
4040
}
4141

42+
/**
43+
* @return iterable<array{string}>
44+
*/
4245
public static function provideRequiredMethods(): iterable
4346
{
4447
return [
@@ -53,7 +56,7 @@ public static function provideRequiredMethods(): iterable
5356
];
5457
}
5558

56-
private function assertImplementMethod(string $method, object $object, string $reason = ''): void
59+
private function assertMethodIsImplemented(string $method, object $object, string $reason = ''): void
5760
{
5861
$ref = new \ReflectionClass(get_class($object));
5962
$refMethod = $ref->getMethod($method);
@@ -67,7 +70,7 @@ private function assertImplementMethod(string $method, object $object, string $r
6770
$this->assertNotSame(CoreDriver::class, $refMethod->getDeclaringClass()->name, $message);
6871
}
6972

70-
private function assertNotImplementMethod(string $method, object $object, string $reason = ''): void
73+
private function assertMethodIsNotImplemented(string $method, object $object, string $reason = ''): void
7174
{
7275
$ref = new \ReflectionClass(get_class($object));
7376
$refMethod = $ref->getMethod($method);

tests/Basic/ContentTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public function testGetAttribute(string $attributeName, ?string $attributeValue)
6161
$this->assertSame($attributeValue, $element->getAttribute($attributeName));
6262
}
6363

64+
/**
65+
* @return iterable<array{string, mixed}>
66+
*/
6467
public static function getAttributeDataProvider(): iterable
6568
{
6669
return [

tests/Basic/CookieTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Behat\Mink\Tests\Driver\TestCase;
66

7+
/**
8+
* @phpstan-type TCookieRemovalMode 'session_reset'|'cookie_delete'
9+
*/
710
final class CookieTest extends TestCase
811
{
912
/**
@@ -87,6 +90,9 @@ public function testCookieWithPaths(string $cookieRemovalMode): void
8790
$this->assertStringContainsString('Previous cookie: NO', $session->getPage()->getText());
8891
}
8992

93+
/**
94+
* @phpstan-return iterable<array{TCookieRemovalMode}>
95+
*/
9096
public static function cookieWithPathsDataProvider(): iterable
9197
{
9298
return [
@@ -96,6 +102,7 @@ public static function cookieWithPathsDataProvider(): iterable
96102
}
97103

98104
/**
105+
* @phpstan-param TCookieRemovalMode $cookieRemovalMode
99106
* @dataProvider cookieWithPathsDataProvider
100107
*/
101108
public function testCookieInSubPath(string $cookieRemovalMode): void

tests/Basic/IFrameTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ public function testIFrame(string $iframeIdentifier, string $elementSelector, st
2929
}
3030

3131
/**
32-
* @return array
32+
* @return iterable<string, array{string, string, string}>
3333
*/
34-
public static function iFrameDataProvider()
34+
public static function iFrameDataProvider(): iterable
3535
{
36-
return array(
37-
'by name' => array('subframe_by_name', '#text', 'iFrame div text'),
38-
'by id' => array('subframe_by_id', '#foobar', 'Some accentués characters'),
39-
);
36+
yield 'by name' => ['subframe_by_name', '#text', 'iFrame div text'];
37+
yield 'by id' => ['subframe_by_id', '#foobar', 'Some accentués characters'];
4038
}
4139
}

tests/Form/GeneralTest.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ public function testFormSubmitWays(string $submitVia): void
7777
}
7878
}
7979

80+
/**
81+
* @return iterable<array{string}>
82+
*/
8083
public static function formSubmitWaysDataProvider(): iterable
8184
{
82-
return [
83-
['Save'],
84-
['input-type-image'],
85-
['button-without-type'],
86-
['button-type-submit'],
87-
];
85+
yield ['Save'];
86+
yield ['input-type-image'];
87+
yield ['button-without-type'];
88+
yield ['button-type-submit'];
8889
}
8990

9091
public function testFormSubmit(): void
@@ -189,7 +190,7 @@ public function testAdvancedForm(): void
189190
$notes->setValue('new notes');
190191
$this->assertEquals('new notes', $notes->getValue());
191192

192-
$about->attachFile($this->mapRemoteFilePath(__DIR__ . '/../../web-fixtures/some_file.txt'));
193+
$about->attachFile($this->mapRemoteFilePath(self::WEB_FIXTURES_DIR . '/some_file.txt'));
193194

194195
$button = $page->findButton('Register');
195196
$this->assertNotNull($button);
@@ -352,7 +353,7 @@ public function testSubmitEmptyTextarea(): void
352353
/**
353354
* @dataProvider provideInvalidValues
354355
*
355-
* @param mixed $value
356+
* @param array<array-key, mixed>|bool|string $value
356357
*/
357358
public function testSetInvalidValueInField(string $field, $value): void
358359
{
@@ -366,6 +367,9 @@ public function testSetInvalidValueInField(string $field, $value): void
366367
$color->setValue($value);
367368
}
368369

370+
/**
371+
* @return iterable<string, array{string, mixed}>
372+
*/
369373
public static function provideInvalidValues(): iterable
370374
{
371375
$trueValue = ['true', true];

tests/Form/Html5Test.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function testHtml5FormMethod(): void
163163
/**
164164
* @dataProvider provideInvalidValues
165165
*
166-
* @param mixed $value
166+
* @param array<array-key, mixed>|bool|string $value
167167
*/
168168
public function testSetInvalidValueInField(string $field, $value): void
169169
{
@@ -177,6 +177,9 @@ public function testSetInvalidValueInField(string $field, $value): void
177177
$color->setValue($value);
178178
}
179179

180+
/**
181+
* @return iterable<string, array{string, mixed}>
182+
*/
180183
public static function provideInvalidValues(): iterable
181184
{
182185
$trueValue = ['true', true];

tests/Form/RadioTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ public function testSetBooleanValue(bool $value): void
112112
$option->setValue($value);
113113
}
114114

115+
/**
116+
* @return iterable<array{bool}>
117+
*/
115118
public static function provideBooleanValues(): iterable
116119
{
117120
yield [true];

tests/Form/SelectTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public function testElementSelectedStateCheck(string $selectName, string $option
7878
$this->assertTrue($option->isSelected());
7979
}
8080

81+
/**
82+
* @return iterable<array{string, string, string}>
83+
*/
8184
public static function elementSelectedStateCheckDataProvider(): iterable
8285
{
8386
return [
@@ -119,6 +122,9 @@ public function testSetBooleanValue(bool $value): void
119122
$select->setValue($value);
120123
}
121124

125+
/**
126+
* @return iterable<array{bool}>
127+
*/
122128
public static function provideBooleanValues(): iterable
123129
{
124130
yield [true];

0 commit comments

Comments
 (0)