Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: fix PHPUnit deprecation notices #871

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions tests/Cookie/Jar/NormalizeCookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class NormalizeCookieTest extends TestCase {
/**
* Verify that cookie normalization works on both prebaked and unbaked cookies when not passing a key.
*
* @dataProvider dataNormalization
* @dataProvider dataNormalizationWithoutKey
*
* @param mixed $cookie Cookie header value, possibly pre-parsed (object).
*
Expand All @@ -30,10 +30,25 @@ public function testNormalizationWithoutKey($cookie) {
$this->assertSame(self::COOKIE_VALUE, (string) $result, 'Cookie value is not the expected value');
}

/**
* Data provider.
*
* @return array
*/
public static function dataNormalizationWithoutKey() {
$data = self::dataNormalizationWithKey();

foreach ($data as $set_name => $set_value) {
unset($data[$set_name]['expected_name']);
}

return $data;
}

/**
* Verify that cookie normalization works on both prebaked and unbaked cookies when passing a key.
*
* @dataProvider dataNormalization
* @dataProvider dataNormalizationWithKey
*
* @param mixed $cookie Cookie header value, possibly pre-parsed (object).
*
Expand All @@ -55,7 +70,7 @@ public function testNormalizationWithKey($cookie, $expected_name) {
*
* @return array
*/
public static function dataNormalization() {
public static function dataNormalizationWithKey() {
return [
'unbaked cookie (string)' => [
'cookie' => self::COOKIE_VALUE,
Expand Down
6 changes: 3 additions & 3 deletions tests/Cookie/NormalizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public static function dataNormalizeAttributesExpiresUnsupportedType() {
foreach ($types as $key => $value) {
$data['Attribute normalization: expires: unsupported type - ' . $key] = [
'attributes' => [
'expires' => $value['input'],
'expires' => $value[0],
],
'expected' => [],
];
Expand All @@ -303,7 +303,7 @@ public static function dataNormalizeAttributesMaxAgeUnsupportedType() {
foreach ($types as $key => $value) {
$data['Attribute normalization: max-age: unsupported type - ' . $key] = [
'attributes' => [
'max-age' => $value['input'],
'max-age' => $value[0],
],
'expected' => [],
];
Expand All @@ -324,7 +324,7 @@ public static function dataNormalizeAttributesDomainUnsupportedType() {
foreach ($types as $key => $value) {
$data['Attribute normalization: domain: unsupported type - ' . $key] = [
'attributes' => [
'domain' => $value['input'],
'domain' => $value[0],
],
'expected' => [],
];
Expand Down
6 changes: 3 additions & 3 deletions tests/Cookie/PathMatchesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public static function dataPathMatchUndesiredInputTypes() {
if (in_array($key, TypeProviderHelper::GROUP_EMPTY, true)) {
$data['Match: "/" vs ' . $key] = [
'original' => '/',
'check' => $value['input'],
'check' => $value[0],
'matches' => true,
];

$data['Non-match: "/test" vs ' . $key] = [
'original' => '/test',
'check' => $value['input'],
'check' => $value[0],
'matches' => false,
];

Expand All @@ -98,7 +98,7 @@ public static function dataPathMatchUndesiredInputTypes() {
*/
$data['Non-match: "/" vs ' . $key] = [
'original' => '/',
'check' => $value['input'],
'check' => $value[0],
'matches' => false,
];
}
Expand Down
28 changes: 14 additions & 14 deletions tests/Cookie/UriMatchesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,28 @@ public static function dataUrlMatch() {
'domain' => 'example.com',
'path' => '/',
'check' => 'http://example.com/',
'matched' => true,
'matches' => true,
'domain_matches' => true,
],
'Domain handling: same domain name, same TLD, different subdomain' => [
'domain' => 'example.com',
'path' => '/',
'check' => 'http://www.example.com/',
'matched' => false,
'matches' => false,
'domain_matches' => true,
],
'Domain handling: same domain name, different TLD' => [
'domain' => 'example.com',
'path' => '/',
'check' => 'http://example.net/',
'matched' => false,
'matches' => false,
'domain_matches' => false,
],
'Domain handling: same domain name, different TLD, different subdomain' => [
'domain' => 'example.com',
'path' => '/',
'check' => 'http://www.example.net/',
'matched' => false,
'matches' => false,
'domain_matches' => false,
],

Expand All @@ -105,59 +105,59 @@ public static function dataUrlMatch() {
'domain' => 'example.com',
'path' => '/test',
'check' => 'http://example.com/',
'matched' => false,
'matches' => false,
'domain_matches' => false,
],
'Path handling "/test": same domain name, same TLD, different subdomain, URI provided without path' => [
'domain' => 'example.com',
'path' => '/test',
'check' => 'http://www.example.com/',
'matched' => false,
'matches' => false,
'domain_matches' => false,
],

'Path handling "/test": same domain name, same TLD, URI provided including path' => [
'domain' => 'example.com',
'path' => '/test',
'check' => 'http://example.com/test',
'matched' => true,
'matches' => true,
'domain_matches' => true,
],
'Path handling "/test": same domain name, same TLD, different subdomain, URI provided including path' => [
'domain' => 'example.com',
'path' => '/test',
'check' => 'http://www.example.com/test',
'matched' => false,
'matches' => false,
'domain_matches' => true,
],

'Path handling "/test": same domain name, same TLD, different path' => [
'domain' => 'example.com',
'path' => '/test',
'check' => 'http://example.com/testing',
'matched' => false,
'matches' => false,
'domain_matches' => false,
],
'Path handling "/test": same domain name, same TLD, different subdomain, different path' => [
'domain' => 'example.com',
'path' => '/test',
'check' => 'http://www.example.com/testing',
'matched' => false,
'matches' => false,
'domain_matches' => false,
],

'Path handling "/test": same domain name, same TLD, URI provided including path with trailing slash' => [
'domain' => 'example.com',
'path' => '/test',
'check' => 'http://example.com/test/',
'matched' => true,
'matches' => true,
'domain_matches' => true,
],
'Path handling "/test": same domain name, same TLD, different subdomain, URI provided including path with trailing slash' => [
'domain' => 'example.com',
'path' => '/test',
'check' => 'http://www.example.com/test/',
'matched' => false,
'matches' => false,
'domain_matches' => true,
],

Expand All @@ -166,14 +166,14 @@ public static function dataUrlMatch() {
'domain' => 'example.com',
'path' => '/test/',
'check' => 'http://example.com/',
'matched' => false,
'matches' => false,
'domain_matches' => false,
],
'Path handling "/test/" (incl trailing slash): same domain name, same TLD, different subdomain, URI provided without path' => [
'domain' => 'example.com',
'path' => '/test/',
'check' => 'http://www.example.com/',
'matched' => false,
'matches' => false,
'domain_matches' => false,
],
];
Expand Down
14 changes: 7 additions & 7 deletions tests/Exception/Http/StatusCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ public static function dataUnknownStatusCodes() {

return [
'null (or not passed)' => [
'expectedCode' => 0,
'expected_code' => 0,
],
'integer error code as data' => [
'expectedCode' => 0,
'data' => 507,
'expected_code' => 0,
'data' => 507,
],
'Response object with status code' => [
'expectedCode' => 12345,
'data' => $response_with_status,
'expected_code' => 12345,
'data' => $response_with_status,
],
'Response object without status code' => [
'expectedCode' => 0,
'data' => $response_without_status,
'expected_code' => 0,
'data' => $response_without_status,
],
];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Response/IsRedirectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static function dataNotRedirect() {
$except[] = 'boolean false'; // No need to double test `false`.
$invalid = TypeProviderHelper::getAllExcept($except);
foreach ($invalid as $key => $type) {
$data['Invalid status code: ' . $key] = [$type['input']];
$data['Invalid status code: ' . $key] = [$type[0]];
}

return $data;
Expand Down
98 changes: 26 additions & 72 deletions tests/TypeProviderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public static function cleanUp() {
* Typically, one or more of the predefined "groups" (see the constants)
* would be used here.
*
* @return array<string, mixed>
* @return array<string, array<mixed>>
*/
public static function getAllExcept(array ...$except) {
$except = array_flip(array_merge(...$except));
Expand All @@ -217,7 +217,7 @@ public static function getAllExcept(array ...$except) {
* Typically, one or more of the predefined "groups" (see the constants)
* would be used here.
*
* @return array<string, mixed>
* @return array<string, array<mixed>>
*/
public static function getSelection(array ...$selection) {
$selection = array_flip(array_merge(...$selection));
Expand All @@ -228,7 +228,7 @@ public static function getSelection(array ...$selection) {
/**
* Retrieve an array in data provider format with all typical PHP data types.
*
* @return array<string, mixed>
* @return array<string, array<mixed>>
*/
public static function getAll() {
if (isset(self::$memory_handle_open) === false) {
Expand All @@ -241,75 +241,29 @@ public static function getAll() {
}

return [
'null' => [
'input' => null,
],
'boolean false' => [
'input' => false,
],
'boolean true' => [
'input' => true,
],
'integer 0' => [
'input' => 0,
],
'negative integer' => [
'input' => -123,
],
'positive integer' => [
'input' => 786687,
],
'float 0.0' => [
'input' => 0.0,
],
'negative float' => [
'input' => 5.600e-3,
],
'positive float' => [
'input' => 124.7,
],
'empty string' => [
'input' => '',
],
'numeric string' => [
'input' => '123',
],
'textual string' => [
'input' => 'foobar',
],
'textual string starting with numbers' => [
'input' => '123 My Street',
],
'empty array' => [
'input' => [],
],
'array with values, no keys' => [
'input' => [1, 2, 3],
],
'array with values, string keys' => [
'input' => ['a' => 1, 'b' => 2],
],
'plain object' => [
'input' => new stdClass(),
],
'Stringable object' => [
'input' => new StringableObject('value'),
],
'ArrayIterator object' => [
'input' => new ArrayIterator([1, 2, 3]),
],
'ArrayAccess object' => [
'input' => new ArrayAccessibleObject(),
],
'Iterator object, no array access' => [
'input' => new EmptyIterator(),
],
'resource (open file handle)' => [
'input' => self::$memory_handle_open,
],
'resource (closed file handle)' => [
'input' => self::$memory_handle_closed,
],
'null' => [null],
'boolean false' => [false],
'boolean true' => [true],
'integer 0' => [0],
'negative integer' => [-123],
'positive integer' => [786687],
'float 0.0' => [0.0],
'negative float' => [5.600e-3],
'positive float' => [124.7],
'empty string' => [''],
'numeric string' => ['123'],
'textual string' => ['foobar'],
'textual string starting with numbers' => ['123 My Street'],
'empty array' => [[]],
'array with values, no keys' => [[1, 2, 3]],
'array with values, string keys' => [['a' => 1, 'b' => 2]],
'plain object' => [new stdClass()],
'Stringable object' => [new StringableObject('value')],
'ArrayIterator object' => [new ArrayIterator([1, 2, 3])],
'ArrayAccess object' => [new ArrayAccessibleObject()],
'Iterator object, no array access' => [new EmptyIterator()],
'resource (open file handle)' => [self::$memory_handle_open],
'resource (closed file handle)' => [self::$memory_handle_closed],
];
}
}
Loading