mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 21:41:19 +08:00
Add void return to method in tests. (#20602)
This commit is contained in:
@ -8,6 +8,9 @@
|
||||
|
||||
namespace yiiunit\framework\web;
|
||||
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
use stdClass;
|
||||
use yii\web\Request;
|
||||
use yiiunit\TestCase;
|
||||
|
||||
@ -17,7 +20,7 @@ use yiiunit\TestCase;
|
||||
*/
|
||||
class RequestTest extends TestCase
|
||||
{
|
||||
public function testParseAcceptHeader()
|
||||
public function testParseAcceptHeader(): void
|
||||
{
|
||||
$request = new Request();
|
||||
|
||||
@ -40,7 +43,7 @@ class RequestTest extends TestCase
|
||||
text/x-dvi; q=0.8, text/x-c'));
|
||||
}
|
||||
|
||||
public function testPreferredLanguage()
|
||||
public function testPreferredLanguage(): void
|
||||
{
|
||||
$this->mockApplication([
|
||||
'language' => 'en',
|
||||
@ -84,7 +87,7 @@ class RequestTest extends TestCase
|
||||
/**
|
||||
* @see https://github.com/yiisoft/yii2/issues/14542
|
||||
*/
|
||||
public function testCsrfTokenContainsASCIIOnly()
|
||||
public function testCsrfTokenContainsASCIIOnly(): void
|
||||
{
|
||||
$this->mockWebApplication();
|
||||
|
||||
@ -95,7 +98,7 @@ class RequestTest extends TestCase
|
||||
$this->assertMatchesRegularExpression('~[-_=a-z0-9]~i', $token);
|
||||
}
|
||||
|
||||
public function testCsrfTokenValidation()
|
||||
public function testCsrfTokenValidation(): void
|
||||
{
|
||||
$this->mockWebApplication();
|
||||
|
||||
@ -139,7 +142,7 @@ class RequestTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testIssue15317()
|
||||
public function testIssue15317(): void
|
||||
{
|
||||
$this->mockWebApplication();
|
||||
$_COOKIE[(new Request())->csrfParam] = '';
|
||||
@ -148,7 +151,7 @@ class RequestTest extends TestCase
|
||||
$request->enableCookieValidation = false;
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||
\Yii::$app->security->unmaskToken('');
|
||||
Yii::$app->security->unmaskToken('');
|
||||
$this->assertFalse($request->validateCsrfToken(''));
|
||||
|
||||
// When an empty CSRF token is given it is regenerated.
|
||||
@ -158,7 +161,7 @@ class RequestTest extends TestCase
|
||||
/**
|
||||
* Test CSRF token validation by POST param.
|
||||
*/
|
||||
public function testCsrfTokenPost()
|
||||
public function testCsrfTokenPost(): void
|
||||
{
|
||||
$this->mockWebApplication();
|
||||
|
||||
@ -186,7 +189,7 @@ class RequestTest extends TestCase
|
||||
/**
|
||||
* Test CSRF token validation by POST param.
|
||||
*/
|
||||
public function testCsrfTokenHeader()
|
||||
public function testCsrfTokenHeader(): void
|
||||
{
|
||||
$this->mockWebApplication();
|
||||
|
||||
@ -212,7 +215,7 @@ class RequestTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testCustomSafeMethodsCsrfTokenValidation()
|
||||
public function testCustomSafeMethodsCsrfTokenValidation(): void
|
||||
{
|
||||
$this->mockWebApplication();
|
||||
|
||||
@ -248,7 +251,7 @@ class RequestTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testCsrfHeaderValidation()
|
||||
public function testCsrfHeaderValidation(): void
|
||||
{
|
||||
$this->mockWebApplication();
|
||||
|
||||
@ -273,7 +276,7 @@ class RequestTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testCustomHeaderCsrfHeaderValidation()
|
||||
public function testCustomHeaderCsrfHeaderValidation(): void
|
||||
{
|
||||
$this->mockWebApplication();
|
||||
|
||||
@ -293,7 +296,7 @@ class RequestTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testCustomUnsafeMethodsCsrfHeaderValidation()
|
||||
public function testCustomUnsafeMethodsCsrfHeaderValidation(): void
|
||||
{
|
||||
$this->mockWebApplication();
|
||||
|
||||
@ -320,7 +323,7 @@ class RequestTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testNoCsrfTokenCsrfHeaderValidation()
|
||||
public function testNoCsrfTokenCsrfHeaderValidation(): void
|
||||
{
|
||||
$this->mockWebApplication();
|
||||
|
||||
@ -330,7 +333,7 @@ class RequestTest extends TestCase
|
||||
$this->assertEquals($request->getCsrfToken(), null);
|
||||
}
|
||||
|
||||
public function testResolve()
|
||||
public function testResolve(): void
|
||||
{
|
||||
$this->mockWebApplication([
|
||||
'components' => [
|
||||
@ -497,7 +500,7 @@ class RequestTest extends TestCase
|
||||
* @param array $server
|
||||
* @param array $expected
|
||||
*/
|
||||
public function testGetHostInfo($server, $expected)
|
||||
public function testGetHostInfo($server, $expected): void
|
||||
{
|
||||
$original = $_SERVER;
|
||||
$_SERVER = $server;
|
||||
@ -535,7 +538,7 @@ class RequestTest extends TestCase
|
||||
$_SERVER = $original;
|
||||
}
|
||||
|
||||
public function testSetHostInfo()
|
||||
public function testSetHostInfo(): void
|
||||
{
|
||||
$request = new Request();
|
||||
|
||||
@ -548,27 +551,27 @@ class RequestTest extends TestCase
|
||||
$this->assertSame('servername.com', $request->getHostName());
|
||||
}
|
||||
|
||||
public function testGetScriptFileWithEmptyServer()
|
||||
public function testGetScriptFileWithEmptyServer(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$_SERVER = [];
|
||||
|
||||
$this->expectException(\yii\base\InvalidConfigException::class);
|
||||
$this->expectException(InvalidConfigException::class);
|
||||
|
||||
$request->getScriptFile();
|
||||
}
|
||||
|
||||
public function testGetScriptUrlWithEmptyServer()
|
||||
public function testGetScriptUrlWithEmptyServer(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$_SERVER = [];
|
||||
|
||||
$this->expectException(\yii\base\InvalidConfigException::class);
|
||||
$this->expectException(InvalidConfigException::class);
|
||||
|
||||
$request->getScriptUrl();
|
||||
}
|
||||
|
||||
public function testGetServerName()
|
||||
public function testGetServerName(): void
|
||||
{
|
||||
$request = new Request();
|
||||
|
||||
@ -579,7 +582,7 @@ class RequestTest extends TestCase
|
||||
$this->assertNull($request->getServerName());
|
||||
}
|
||||
|
||||
public function testGetServerPort()
|
||||
public function testGetServerPort(): void
|
||||
{
|
||||
$request = new Request();
|
||||
|
||||
@ -680,7 +683,7 @@ class RequestTest extends TestCase
|
||||
* @param array $server
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testGetIsSecureConnection($server, $expected)
|
||||
public function testGetIsSecureConnection($server, $expected): void
|
||||
{
|
||||
$original = $_SERVER;
|
||||
$_SERVER = $server;
|
||||
@ -734,7 +737,7 @@ class RequestTest extends TestCase
|
||||
* @param array $server
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testGetIsSecureConnectionWithoutTrustedHost($server, $expected)
|
||||
public function testGetIsSecureConnectionWithoutTrustedHost($server, $expected): void
|
||||
{
|
||||
$original = $_SERVER;
|
||||
$_SERVER = $server;
|
||||
@ -898,7 +901,7 @@ class RequestTest extends TestCase
|
||||
* @param array $server
|
||||
* @param string $expected
|
||||
*/
|
||||
public function testGetUserIP($server, $expected)
|
||||
public function testGetUserIP($server, $expected): void
|
||||
{
|
||||
$original = $_SERVER;
|
||||
$_SERVER = $server;
|
||||
@ -954,7 +957,7 @@ class RequestTest extends TestCase
|
||||
* @param array $server
|
||||
* @param string $expected
|
||||
*/
|
||||
public function testGetUserIPWithoutTrustedHost($server, $expected)
|
||||
public function testGetUserIPWithoutTrustedHost($server, $expected): void
|
||||
{
|
||||
$original = $_SERVER;
|
||||
$_SERVER = $server;
|
||||
@ -1001,7 +1004,7 @@ class RequestTest extends TestCase
|
||||
* @param array $server
|
||||
* @param string $expected
|
||||
*/
|
||||
public function testGetMethod($server, $expected)
|
||||
public function testGetMethod($server, $expected): void
|
||||
{
|
||||
$original = $_SERVER;
|
||||
$_SERVER = $server;
|
||||
@ -1033,7 +1036,7 @@ class RequestTest extends TestCase
|
||||
* @param array $server
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testGetIsAjax($server, $expected)
|
||||
public function testGetIsAjax($server, $expected): void
|
||||
{
|
||||
$original = $_SERVER;
|
||||
$_SERVER = $server;
|
||||
@ -1066,7 +1069,7 @@ class RequestTest extends TestCase
|
||||
* @param array $server
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testGetIsPjax($server, $expected)
|
||||
public function testGetIsPjax($server, $expected): void
|
||||
{
|
||||
$original = $_SERVER;
|
||||
$_SERVER = $server;
|
||||
@ -1076,7 +1079,7 @@ class RequestTest extends TestCase
|
||||
$_SERVER = $original;
|
||||
}
|
||||
|
||||
public function testGetOrigin()
|
||||
public function testGetOrigin(): void
|
||||
{
|
||||
$_SERVER['HTTP_ORIGIN'] = 'https://www.w3.org';
|
||||
$request = new Request();
|
||||
@ -1106,7 +1109,7 @@ class RequestTest extends TestCase
|
||||
* @param string $secret
|
||||
* @param array $expected
|
||||
*/
|
||||
public function testHttpAuthCredentialsFromHttpAuthorizationHeader($secret, $expected)
|
||||
public function testHttpAuthCredentialsFromHttpAuthorizationHeader($secret, $expected): void
|
||||
{
|
||||
$original = $_SERVER;
|
||||
|
||||
@ -1125,7 +1128,7 @@ class RequestTest extends TestCase
|
||||
$_SERVER = $original;
|
||||
}
|
||||
|
||||
public function testHttpAuthCredentialsFromServerSuperglobal()
|
||||
public function testHttpAuthCredentialsFromServerSuperglobal(): void
|
||||
{
|
||||
$original = $_SERVER;
|
||||
list($user, $pw) = ['foo', 'bar'];
|
||||
@ -1142,7 +1145,7 @@ class RequestTest extends TestCase
|
||||
$_SERVER = $original;
|
||||
}
|
||||
|
||||
public function testGetBodyParam()
|
||||
public function testGetBodyParam(): void
|
||||
{
|
||||
$request = new Request();
|
||||
|
||||
@ -1156,7 +1159,7 @@ class RequestTest extends TestCase
|
||||
$this->assertSame('default', $request->getBodyParam('unexisting', 'default'));
|
||||
|
||||
// @see https://github.com/yiisoft/yii2/issues/14135
|
||||
$bodyParams = new \stdClass();
|
||||
$bodyParams = new stdClass();
|
||||
$bodyParams->someParam = 'some value';
|
||||
$bodyParams->{'param.dot'} = 'value.dot';
|
||||
$request->setBodyParams($bodyParams);
|
||||
@ -1178,7 +1181,7 @@ class RequestTest extends TestCase
|
||||
/**
|
||||
* @dataProvider getBodyParamsDataProvider
|
||||
*/
|
||||
public function testGetBodyParams($contentType, $rawBody, array $expected)
|
||||
public function testGetBodyParams($contentType, $rawBody, array $expected): void
|
||||
{
|
||||
$_SERVER['CONTENT_TYPE'] = $contentType;
|
||||
$request = new Request();
|
||||
@ -1213,7 +1216,7 @@ class RequestTest extends TestCase
|
||||
/**
|
||||
* @dataProvider trustedHostAndInjectedXForwardedForDataProvider
|
||||
*/
|
||||
public function testTrustedHostAndInjectedXForwardedFor($remoteAddress, $xForwardedFor, $ipHeaders, $trustedHosts, $expectedUserIp)
|
||||
public function testTrustedHostAndInjectedXForwardedFor($remoteAddress, $xForwardedFor, $ipHeaders, $trustedHosts, $expectedUserIp): void
|
||||
{
|
||||
$_SERVER['REMOTE_ADDR'] = $remoteAddress;
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = $xForwardedFor;
|
||||
@ -1242,7 +1245,7 @@ class RequestTest extends TestCase
|
||||
/**
|
||||
* @dataProvider trustedHostAndXForwardedPortDataProvider
|
||||
*/
|
||||
public function testTrustedHostAndXForwardedPort($remoteAddress, $requestPort, $xForwardedPort, $trustedHosts, $expectedPort)
|
||||
public function testTrustedHostAndXForwardedPort($remoteAddress, $requestPort, $xForwardedPort, $trustedHosts, $expectedPort): void
|
||||
{
|
||||
$_SERVER['REMOTE_ADDR'] = $remoteAddress;
|
||||
$_SERVER['SERVER_PORT'] = $requestPort;
|
||||
@ -1261,7 +1264,7 @@ class RequestTest extends TestCase
|
||||
* ["POST", "DELETE", "DELETE"]
|
||||
* ["POST", "CUSTOM", "CUSTOM"]
|
||||
*/
|
||||
public function testRequestMethodCanNotBeDowngraded($requestMethod, $requestOverrideMethod, $expectedMethod)
|
||||
public function testRequestMethodCanNotBeDowngraded($requestMethod, $requestOverrideMethod, $expectedMethod): void
|
||||
{
|
||||
$request = new Request();
|
||||
|
||||
@ -1300,7 +1303,7 @@ class RequestTest extends TestCase
|
||||
/**
|
||||
* @dataProvider alreadyResolvedIpDataProvider
|
||||
*/
|
||||
public function testAlreadyResolvedIp($remoteAddress, $xForwardedFor, $xForwardedProto, $trustedHosts, $expectedRemoteAddress, $expectedUserIp, $expectedIsSecureConnection)
|
||||
public function testAlreadyResolvedIp($remoteAddress, $xForwardedFor, $xForwardedProto, $trustedHosts, $expectedRemoteAddress, $expectedUserIp, $expectedIsSecureConnection): void
|
||||
{
|
||||
$_SERVER['REMOTE_ADDR'] = $remoteAddress;
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = $xForwardedFor;
|
||||
@ -1365,7 +1368,7 @@ class RequestTest extends TestCase
|
||||
/**
|
||||
* @dataProvider parseForwardedHeaderDataProvider
|
||||
*/
|
||||
public function testParseForwardedHeaderParts($remoteAddress, $forwardedHeader, $expectedHostInfo, $expectedUserIp)
|
||||
public function testParseForwardedHeaderParts($remoteAddress, $forwardedHeader, $expectedHostInfo, $expectedUserIp): void
|
||||
{
|
||||
$_SERVER['REMOTE_ADDR'] = $remoteAddress;
|
||||
$_SERVER['HTTP_HOST'] = 'example.com';
|
||||
@ -1388,7 +1391,7 @@ class RequestTest extends TestCase
|
||||
$this->assertSame($expectedHostInfo, $request->hostInfo, 'Host info fail!');
|
||||
}
|
||||
|
||||
public function testForwardedNotTrusted()
|
||||
public function testForwardedNotTrusted(): void
|
||||
{
|
||||
$_SERVER['REMOTE_ADDR'] = '192.168.10.10';
|
||||
$_SERVER['HTTP_HOST'] = 'example.com';
|
||||
|
||||
Reference in New Issue
Block a user