Skip to content

Commit d549552

Browse files
authored
Merge pull request #100 from uuf6429/chore/phpstan-improvements
PHPStan improvements
1 parent afd1e9d commit d549552

20 files changed

+148
-106
lines changed

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

0 commit comments

Comments
 (0)