Skip to content

Commit 283046b

Browse files
committed
Use short array syntax; add return types; require return types
1 parent 46987f5 commit 283046b

29 files changed

+296
-291
lines changed

http-kernel-fixtures/404.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
$resp = new Symfony\Component\HttpFoundation\Response('Sorry, page not found', 404, array('Content-Type' => 'text/plain'));
3+
$resp = new Symfony\Component\HttpFoundation\Response('Sorry, page not found', 404, ['Content-Type' => 'text/plain']);

phpstan.dist.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ parameters:
66
- http-kernel-fixtures
77
- web-fixtures
88
checkMissingIterableValueType: false
9-
ignoreErrors:
10-
- '#^Method Behat\\Mink\\Tests\\Driver\\[^:]+Test(Case)?\:\:test\w*\(\) has no return type specified\.$#'
11-
- '#^Method Behat\\Mink\\Tests\\Driver\\[^:]+Test(Case)?\:\:provide\w*\(\) has no return type specified\.$#'
12-
- '#^Method Behat\\Mink\\Tests\\Driver\\[^:]+Test(Case)?\:\:\w*DataProvider\(\) has no return type specified\.$#'
139

1410
includes:
1511
- vendor/phpstan/phpstan-phpunit/extension.neon

src/FixturesKernel.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch =
2525

2626
private function handleFixtureRequest(Request $request): Response
2727
{
28-
$fixturesDir = realpath(__DIR__.'/../web-fixtures');
29-
$overwriteDir = realpath(__DIR__.'/../http-kernel-fixtures');
28+
$fixturesDir = realpath(__DIR__ . '/../web-fixtures');
29+
$overwriteDir = realpath(__DIR__ . '/../http-kernel-fixtures');
3030

3131
require_once $fixturesDir . '/utils.php';
3232

3333
$file = $request->getPathInfo();
3434

35-
$path = file_exists($overwriteDir.$file) ? $overwriteDir.$file : $fixturesDir.$file;
35+
$path = file_exists($overwriteDir . $file) ? $overwriteDir . $file : $fixturesDir . $file;
3636

3737
/** @var Response|null $resp */
3838
$resp = null;
@@ -79,7 +79,17 @@ private function saveSession(Request $request, Response $response): void
7979

8080
$params = session_get_cookie_params();
8181

82-
$cookie = Cookie::create($session->getName(), $session->getId(), 0 === $params['lifetime'] ? 0 : time() + $params['lifetime'], $params['path'], $params['domain'], $params['secure'], $params['httponly']);
82+
$cookie = Cookie::create(
83+
$session->getName(),
84+
$session->getId(),
85+
0 === $params['lifetime']
86+
? 0
87+
: time() + $params['lifetime'],
88+
$params['path'],
89+
$params['domain'],
90+
$params['secure'],
91+
$params['httponly']
92+
);
8393

8494
$response->headers->setCookie($cookie);
8595
}

tests/AbstractConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function mapRemoteFilePath($file)
2626
return $file;
2727
}
2828

29-
$pattern = '/^'.preg_quote($_SERVER['TEST_MACHINE_BASE_PATH'], '/').'/';
29+
$pattern = '/^' . preg_quote($_SERVER['TEST_MACHINE_BASE_PATH'], '/') . '/';
3030
$basePath = $_SERVER['DRIVER_MACHINE_BASE_PATH'];
3131

3232
return preg_replace($pattern, $basePath, $file, 1) ?? $file;
@@ -48,7 +48,7 @@ public function getWebFixturesUrl()
4848

4949
/**
5050
* @param string $testCase The name of the TestCase class
51-
* @param string $test The name of the test method
51+
* @param string $test The name of the test method
5252
*
5353
* @return string|null A message explaining why the test should be skipped, or null to run the test
5454
*/

tests/Basic/BasicAuthTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ final class BasicAuthTest extends TestCase
99
/**
1010
* @dataProvider setBasicAuthDataProvider
1111
*/
12-
public function testSetBasicAuth(string $user, string $pass, string $pageText)
12+
public function testSetBasicAuth(string $user, string $pass, string $pageText): void
1313
{
1414
$session = $this->getSession();
1515

@@ -20,15 +20,15 @@ public function testSetBasicAuth(string $user, string $pass, string $pageText)
2020
$this->assertStringContainsString($pageText, $session->getPage()->getContent());
2121
}
2222

23-
public static function setBasicAuthDataProvider()
23+
public static function setBasicAuthDataProvider(): iterable
2424
{
25-
return array(
26-
array('mink-user', 'mink-password', 'is authenticated'),
27-
array('', '', 'is not authenticated'),
28-
);
25+
return [
26+
['mink-user', 'mink-password', 'is authenticated'],
27+
['', '', 'is not authenticated'],
28+
];
2929
}
3030

31-
public function testBasicAuthInUrl()
31+
public function testBasicAuthInUrl(): void
3232
{
3333
$session = $this->getSession();
3434

@@ -43,7 +43,7 @@ public function testBasicAuthInUrl()
4343
$this->assertStringContainsString('is not authenticated', $session->getPage()->getContent());
4444
}
4545

46-
public function testResetBasicAuth()
46+
public function testResetBasicAuth(): void
4747
{
4848
$session = $this->getSession();
4949

@@ -60,7 +60,7 @@ public function testResetBasicAuth()
6060
$this->assertStringNotContainsString('PHP_AUTH_USER', $session->getPage()->getContent());
6161
}
6262

63-
public function testResetWithBasicAuth()
63+
public function testResetWithBasicAuth(): void
6464
{
6565
$session = $this->getSession();
6666

tests/Basic/BestPracticesTest.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@
22

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

5+
use Behat\Mink\Driver\CoreDriver;
56
use Behat\Mink\Tests\Driver\TestCase;
67

78
/**
89
* This testcase ensures that the driver implementation follows recommended practices for drivers.
910
*/
1011
final class BestPracticesTest extends TestCase
1112
{
12-
public function testExtendsCoreDriver()
13+
public function testExtendsCoreDriver(): void
1314
{
1415
$driver = $this->createDriver();
1516

16-
$this->assertInstanceOf('Behat\Mink\Driver\CoreDriver', $driver);
17-
18-
return $driver;
17+
$this->assertInstanceOf(CoreDriver::class, $driver);
1918
}
2019

2120
/**
2221
* @depends testExtendsCoreDriver
2322
*/
24-
public function testImplementFindXpath()
23+
public function testImplementFindXpath(): void
2524
{
2625
$driver = $this->createDriver();
2726

@@ -33,25 +32,25 @@ public function testImplementFindXpath()
3332
/**
3433
* @dataProvider provideRequiredMethods
3534
*/
36-
public function testImplementBasicApi(string $method)
35+
public function testImplementBasicApi(string $method): void
3736
{
3837
$driver = $this->createDriver();
3938

4039
$this->assertImplementMethod($method, $driver, 'The driver is unusable when this method is not implemented.');
4140
}
4241

43-
public static function provideRequiredMethods()
42+
public static function provideRequiredMethods(): iterable
4443
{
45-
return array(
46-
array('start'),
47-
array('isStarted'),
48-
array('stop'),
49-
array('reset'),
50-
array('visit'),
51-
array('getCurrentUrl'),
52-
array('getContent'),
53-
array('click'),
54-
);
44+
return [
45+
['start'],
46+
['isStarted'],
47+
['stop'],
48+
['reset'],
49+
['visit'],
50+
['getCurrentUrl'],
51+
['getContent'],
52+
['click'],
53+
];
5554
}
5655

5756
private function assertImplementMethod(string $method, object $object, string $reason = ''): void
@@ -62,10 +61,10 @@ private function assertImplementMethod(string $method, object $object, string $r
6261
$message = sprintf('The driver should implement the `%s` method.', $method);
6362

6463
if ('' !== $reason) {
65-
$message .= ' '.$reason;
64+
$message .= ' ' . $reason;
6665
}
6766

68-
$this->assertNotSame('Behat\Mink\Driver\CoreDriver', $refMethod->getDeclaringClass()->name, $message);
67+
$this->assertNotSame(CoreDriver::class, $refMethod->getDeclaringClass()->name, $message);
6968
}
7069

7170
private function assertNotImplementMethod(string $method, object $object, string $reason = ''): void
@@ -76,9 +75,9 @@ private function assertNotImplementMethod(string $method, object $object, string
7675
$message = sprintf('The driver should not implement the `%s` method.', $method);
7776

7877
if ('' !== $reason) {
79-
$message .= ' '.$reason;
78+
$message .= ' ' . $reason;
8079
}
8180

82-
$this->assertSame('Behat\Mink\Driver\CoreDriver', $refMethod->getDeclaringClass()->name, $message);
81+
$this->assertSame(CoreDriver::class, $refMethod->getDeclaringClass()->name, $message);
8382
}
8483
}

tests/Basic/ContentTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66

77
final class ContentTest extends TestCase
88
{
9-
public function testOuterHtml()
9+
public function testOuterHtml(): void
1010
{
1111
$this->getSession()->visit($this->pathTo('/index.html'));
1212

1313
$element = $this->getAssertSession()->elementExists('css', '.travers');
1414

1515
$this->assertEquals(
16-
"<div class=\"travers\">\n <div class=\"sub\">el1</div>\n".
17-
" <div class=\"sub\">el2</div>\n <div class=\"sub\">\n".
18-
" <a href=\"some_url\">some <strong>deep</strong> url</a>\n".
16+
"<div class=\"travers\">\n <div class=\"sub\">el1</div>\n" .
17+
" <div class=\"sub\">el2</div>\n <div class=\"sub\">\n" .
18+
" <a href=\"some_url\">some <strong>deep</strong> url</a>\n" .
1919
" </div>\n </div>",
2020
$element->getOuterHtml()
2121
);
2222
}
2323

24-
public function testDumpingEmptyElements()
24+
public function testDumpingEmptyElements(): void
2525
{
2626
$this->getSession()->visit($this->pathTo('/index.html'));
2727

@@ -36,27 +36,27 @@ public function testDumpingEmptyElements()
3636
/**
3737
* @dataProvider getAttributeDataProvider
3838
*/
39-
public function testGetAttribute(string $attributeName, ?string $attributeValue)
39+
public function testGetAttribute(string $attributeName, ?string $attributeValue): void
4040
{
4141
$this->getSession()->visit($this->pathTo('/index.html'));
4242

43-
$element = $this->getSession()->getPage()->findById('attr-elem['.$attributeName.']');
43+
$element = $this->getSession()->getPage()->findById('attr-elem[' . $attributeName . ']');
4444

4545
$this->assertNotNull($element);
4646
$this->assertSame($attributeValue, $element->getAttribute($attributeName));
4747
}
4848

49-
public static function getAttributeDataProvider()
49+
public static function getAttributeDataProvider(): iterable
5050
{
51-
return array(
52-
array('with-value', 'some-value'),
53-
array('without-value', ''),
54-
array('with-empty-value', ''),
55-
array('with-missing', null),
56-
);
51+
return [
52+
['with-value', 'some-value'],
53+
['without-value', ''],
54+
['with-empty-value', ''],
55+
['with-missing', null],
56+
];
5757
}
5858

59-
public function testHtmlDecodingNotPerformed()
59+
public function testHtmlDecodingNotPerformed(): void
6060
{
6161
$session = $this->getSession();
6262
$webAssert = $this->getAssertSession();

tests/Basic/CookieTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ final class CookieTest extends TestCase
1111
*
1212
* @group issue140
1313
*/
14-
public function testIssue140()
14+
public function testIssue140(): void
1515
{
1616
$this->getSession()->visit($this->pathTo('/issue140.php'));
1717

@@ -23,7 +23,7 @@ public function testIssue140()
2323
$this->assertEquals('some:value;', $this->getSession()->getPage()->getText());
2424
}
2525

26-
public function testCookie()
26+
public function testCookie(): void
2727
{
2828
$this->getSession()->visit($this->pathTo('/cookie_page2.php'));
2929
$this->assertStringContainsString('Previous cookie: NO', $this->getSession()->getPage()->getText());
@@ -47,7 +47,7 @@ public function testCookie()
4747
$this->assertStringContainsString('Previous cookie: NO', $this->getSession()->getPage()->getText());
4848
}
4949

50-
public function testCookieWithSemicolon()
50+
public function testCookieWithSemicolon(): void
5151
{
5252
$this->getSession()->visit($this->pathTo('/cookie_page2.php'));
5353
$this->getSession()->setCookie('srvr_cookie', 'foo;bar;baz');
@@ -59,7 +59,7 @@ public function testCookieWithSemicolon()
5959
/**
6060
* @dataProvider cookieWithPathsDataProvider
6161
*/
62-
public function testCookieWithPaths(string $cookieRemovalMode)
62+
public function testCookieWithPaths(string $cookieRemovalMode): void
6363
{
6464
// start clean
6565
$session = $this->getSession();
@@ -76,9 +76,9 @@ public function testCookieWithPaths(string $cookieRemovalMode)
7676
$session->visit($this->pathTo('/sub-folder/cookie_page2.php'));
7777
$this->assertStringContainsString('Previous cookie: srv_var_is_set_sub_folder', $session->getPage()->getText());
7878

79-
if ($cookieRemovalMode == 'session_reset') {
79+
if ($cookieRemovalMode === 'session_reset') {
8080
$session->reset();
81-
} elseif ($cookieRemovalMode == 'cookie_delete') {
81+
} elseif ($cookieRemovalMode === 'cookie_delete') {
8282
$session->setCookie('srvr_cookie', null);
8383
}
8484

@@ -87,18 +87,18 @@ public function testCookieWithPaths(string $cookieRemovalMode)
8787
$this->assertStringContainsString('Previous cookie: NO', $session->getPage()->getText());
8888
}
8989

90-
public static function cookieWithPathsDataProvider()
90+
public static function cookieWithPathsDataProvider(): iterable
9191
{
92-
return array(
93-
array('session_reset'),
94-
array('cookie_delete'),
95-
);
92+
return [
93+
['session_reset'],
94+
['cookie_delete'],
95+
];
9696
}
9797

9898
/**
9999
* @dataProvider cookieWithPathsDataProvider
100100
*/
101-
public function testCookieInSubPath(string $cookieRemovalMode)
101+
public function testCookieInSubPath(string $cookieRemovalMode): void
102102
{
103103
// Start clean.
104104
// The cookie is set when viewing the page.
@@ -112,9 +112,9 @@ public function testCookieInSubPath(string $cookieRemovalMode)
112112
$session->visit($this->pathTo('/sub-folder/cookie_page2.php'));
113113
$this->assertStringContainsString('Previous cookie: srv_var_is_set', $session->getPage()->getText());
114114

115-
if ($cookieRemovalMode == 'session_reset') {
115+
if ($cookieRemovalMode === 'session_reset') {
116116
$session->reset();
117-
} elseif ($cookieRemovalMode == 'cookie_delete') {
117+
} elseif ($cookieRemovalMode === 'cookie_delete') {
118118
$session->setCookie('srvr_cookie', null);
119119
}
120120

@@ -123,7 +123,7 @@ public function testCookieInSubPath(string $cookieRemovalMode)
123123
$this->assertStringContainsString('Previous cookie: NO', $session->getPage()->getText());
124124
}
125125

126-
public function testReset()
126+
public function testReset(): void
127127
{
128128
$this->getSession()->visit($this->pathTo('/cookie_page1.php'));
129129
$this->getSession()->visit($this->pathTo('/cookie_page2.php'));
@@ -169,7 +169,7 @@ public function testReset()
169169
$this->assertStringContainsString('array()', $this->getSession()->getPage()->getText());
170170
}
171171

172-
public function testHttpOnlyCookieIsDeleted()
172+
public function testHttpOnlyCookieIsDeleted(): void
173173
{
174174
$this->getSession()->restart();
175175
$this->getSession()->visit($this->pathTo('/cookie_page3.php'));
@@ -183,7 +183,7 @@ public function testHttpOnlyCookieIsDeleted()
183183
$this->assertEquals('Has Cookie: false', $this->findById('cookie-status')->getText());
184184
}
185185

186-
public function testSessionPersistsBetweenRequests()
186+
public function testSessionPersistsBetweenRequests(): void
187187
{
188188
$this->getSession()->visit($this->pathTo('/session_test.php'));
189189
$webAssert = $this->getAssertSession();

0 commit comments

Comments
 (0)