Visitar URL original
Clear _SERVER global for Http\Factory\ServerRequestFactoryTest · phpmyadmin/phpmyadmin@97d46a1 · GitHub
Skip to content

Commit 97d46a1

Browse files
committed
Clear _SERVER global for Http\Factory\ServerRequestFactoryTest
This fixes some test failures. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 7010529 commit 97d46a1

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎psalm-baseline.xml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13820,6 +13820,13 @@
1382013820
</PossiblyUnusedMethod>
1382113821
</file>
1382213822
<file src="tests/unit/Http/Factory/ServerRequestFactoryTest.php">
13823+
<PossiblyUndefinedArrayOffset>
13824+
<code><![CDATA[$_SERVER['PHP_SELF']]]></code>
13825+
<code><![CDATA[$_SERVER['REQUEST_TIME']]]></code>
13826+
<code><![CDATA[$_SERVER['REQUEST_TIME_FLOAT']]]></code>
13827+
<code><![CDATA[$_SERVER['SCRIPT_NAME']]]></code>
13828+
<code><![CDATA[$_SERVER['argv']]]></code>
13829+
</PossiblyUndefinedArrayOffset>
1382313830
<PossiblyUnusedMethod>
1382413831
<code><![CDATA[providerForTestCreate]]></code>
1382513832
<code><![CDATA[providerForTestCreateServerRequest]]></code>

‎tests/unit/Http/Factory/ServerRequestFactoryTest.php‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@
4040
#[Medium]
4141
final class ServerRequestFactoryTest extends TestCase
4242
{
43+
protected function setUp(): void
44+
{
45+
parent::setUp();
46+
47+
// Clear _SERVER global
48+
$_SERVER = [
49+
'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'],
50+
'REQUEST_TIME' => $_SERVER['REQUEST_TIME'],
51+
'REQUEST_TIME_FLOAT' => $_SERVER['REQUEST_TIME_FLOAT'],
52+
'PHP_SELF' => $_SERVER['PHP_SELF'],
53+
'argv' => $_SERVER['argv'],
54+
];
55+
}
56+
4357
/**
4458
* @psalm-param class-string<ServerRequestFactoryInterface> $provider
4559
* @psalm-param class-string<ServerRequestInterface> $expectedServerRequest
@@ -123,6 +137,8 @@ public function testFromGlobals(string $provider, string $uriFactoryProvider, st
123137
$_SERVER['REQUEST_URI'] = '/test-page.php';
124138
$_SERVER['REQUEST_METHOD'] = 'GET';
125139
$_SERVER['HTTP_HOST'] = 'phpmyadmin.local';
140+
$_SERVER['SERVER_PORT'] = '80';
141+
$_SERVER['HTTPS'] = 'off';
126142

127143
(new ReflectionProperty(ServerRequestFactory::class, 'getAllHeaders'))->setValue(null, null);
128144

@@ -165,6 +181,8 @@ public function testFromGlobals2(string $provider, string $uriFactoryProvider, s
165181
$_SERVER['REQUEST_URI'] = '/test-page.php';
166182
$_SERVER['REQUEST_METHOD'] = 'POST';
167183
$_SERVER['HTTP_HOST'] = 'phpmyadmin.local';
184+
$_SERVER['SERVER_PORT'] = '443';
185+
$_SERVER['HTTPS'] = 'on';
168186

169187
$getAllHeaders = static fn (): array => ['Content-Type' => 'application/x-www-form-urlencoded'];
170188
(new ReflectionProperty(ServerRequestFactory::class, 'getAllHeaders'))->setValue(null, $getAllHeaders);
@@ -175,7 +193,7 @@ public function testFromGlobals2(string $provider, string $uriFactoryProvider, s
175193
self::assertSame(['application/x-www-form-urlencoded'], $serverRequest->getHeader('Content-Type'));
176194
self::assertSame('POST', $serverRequest->getMethod());
177195
self::assertSame(
178-
'http://phpmyadmin.local/test-page.php?foo=bar&blob=baz',
196+
'https://phpmyadmin.local/test-page.php?foo=bar&blob=baz',
179197
$serverRequest->getUri()->__toString(),
180198
);
181199
self::assertTrue($serverRequest->isPost());

0 commit comments

Comments
 (0)