Skip to content

Commit e650a71

Browse files
authored
refactor: fix remaining errors in Helpers' tests (#10481)
1 parent 590d8eb commit e650a71

19 files changed

Lines changed: 139 additions & 280 deletions

‎system/Helpers/number_helper.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
/**
2020
* Formats a numbers as bytes, based on size, and adds the appropriate suffix
2121
*
22-
* @param int|string $num Will be cast as int
22+
* @param float|int|string $num Will be cast as int
2323
* @param non-empty-string|null $locale [optional]
2424
*
2525
* @return bool|string
2626
*/
2727
function number_to_size($num, int $precision = 1, ?string $locale = null)
2828
{
29-
// Strip any formatting & ensure numeric input
3029
try {
31-
// @phpstan-ignore-next-line
30+
// Strip any formatting & ensure numeric input
31+
// @phpstan-ignore binaryOp.invalid
3232
$num = 0 + str_replace(',', '', (string) $num);
3333
} catch (ErrorException) {
3434
// Catch "Warning: A non-numeric value encountered"

‎tests/system/Helpers/Array/ArrayHelperDotKeyExistsTest.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#[Group('Others')]
2424
final class ArrayHelperDotKeyExistsTest extends CIUnitTestCase
2525
{
26+
/**
27+
* @var array<string, array<string, list<array<string, int|string>>>>
28+
*/
2629
private array $array = [
2730
'contacts' => [
2831
'friends' => [

‎tests/system/Helpers/Array/ArrayHelperRecursiveDiffTest.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#[Group('Others')]
2323
final class ArrayHelperRecursiveDiffTest extends CIUnitTestCase
2424
{
25+
/**
26+
* @var array<array-key, mixed>
27+
*/
2528
private array $compareWith;
2629

2730
protected function setUp(): void

‎tests/system/Helpers/Array/ArrayHelperSortValuesByNaturalTest.php‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#[Group('Others')]
2323
final class ArrayHelperSortValuesByNaturalTest extends CIUnitTestCase
2424
{
25+
/**
26+
* @var list<int|string>
27+
*/
2528
private array $arrayWithStringValues = [
2629
'apple10',
2730
'banana',
@@ -37,6 +40,10 @@ final class ArrayHelperSortValuesByNaturalTest extends CIUnitTestCase
3740
'Яблоко',
3841
'apple',
3942
];
43+
44+
/**
45+
* @var list<list<int|string>>
46+
*/
4047
private array $arrayWithArrayValues = [
4148
['apple', 'Banana'],
4249
['apple10', 'Apple'],

‎tests/system/Helpers/ArrayHelperTest.php‎

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,10 @@ public function testArrayDotIgnoresLastWildcard(): void
211211
}
212212

213213
/**
214-
* @param int|string $key
215-
* @param array|string|null $expected
214+
* @param array<array-key, mixed>|string|null $expected
216215
*/
217216
#[DataProvider('provideArrayDeepSearch')]
218-
public function testArrayDeepSearch($key, $expected): void
217+
public function testArrayDeepSearch(int|string $key, array|string|null $expected): void
219218
{
220219
$data = [
221220
'key1' => 'Value 1',
@@ -241,6 +240,9 @@ public function testArrayDeepSearch($key, $expected): void
241240
$this->assertSame($expected, $result);
242241
}
243242

243+
/**
244+
* @return iterable<array{int|string, array<array-key, mixed>|string|null}>
245+
*/
244246
public static function provideArrayDeepSearch(): iterable
245247
{
246248
return [
@@ -274,6 +276,11 @@ public function testArrayDeepSearchReturnNullEmptyArray(): void
274276
$this->assertNull(array_deep_search('key644', $data));
275277
}
276278

279+
/**
280+
* @param list<array{name: string, position: int, team: array{order: int}}> $data
281+
* @param array<string, int> $sortColumns
282+
* @param list<string> $expected
283+
*/
277284
#[DataProvider('provideSortByMultipleKeys')]
278285
public function testArraySortByMultipleKeysWithArray(array $data, array $sortColumns, array $expected): void
279286
{
@@ -283,6 +290,11 @@ public function testArraySortByMultipleKeysWithArray(array $data, array $sortCol
283290
$this->assertSame($expected, array_column($data, 'name'));
284291
}
285292

293+
/**
294+
* @param list<array{name: string, position: int, team: array{order: int}}> $data
295+
* @param array<string, int> $sortColumns
296+
* @param list<string> $expected
297+
*/
286298
#[DataProvider('provideSortByMultipleKeys')]
287299
public function testArraySortByMultipleKeysWithObjects(array $data, array $sortColumns, array $expected): void
288300
{
@@ -297,6 +309,11 @@ public function testArraySortByMultipleKeysWithObjects(array $data, array $sortC
297309
$this->assertSame($expected, array_column($data, 'name'));
298310
}
299311

312+
/**
313+
* @param list<array{name: string, position: int, team: array{order: int}}> $data
314+
* @param array<string, int> $sortColumns
315+
* @param list<string> $expected
316+
*/
300317
#[DataProvider('provideSortByMultipleKeys')]
301318
public function testArraySortByMultipleKeysFailsEmptyParameter(array $data, array $sortColumns, array $expected): void
302319
{
@@ -334,6 +351,9 @@ public function testArraySortByMultipleKeysFailsInconsistentArraySizes($data): v
334351
array_sort_by_multiple_keys($data, $sortColumns);
335352
}
336353

354+
/**
355+
* @return iterable<array{list<array{name: string, position: int, team: array{order: int}}>, array<string, int>, list<string>}>
356+
*/
337357
public static function provideSortByMultipleKeys(): iterable
338358
{
339359
$seed = [
@@ -387,12 +407,19 @@ public static function provideSortByMultipleKeys(): iterable
387407
];
388408
}
389409

410+
/**
411+
* @param array<array-key, mixed> $input
412+
* @param array<string, mixed> $expected
413+
*/
390414
#[DataProvider('provideArrayFlattening')]
391415
public function testArrayFlattening(array $input, array $expected): void
392416
{
393417
$this->assertSame($expected, array_flatten_with_dots($input));
394418
}
395419

420+
/**
421+
* @return iterable<string, array{array<array-key, mixed>, array<string, mixed>}>
422+
*/
396423
public static function provideArrayFlattening(): iterable
397424
{
398425
yield 'normal' => [
@@ -485,6 +512,11 @@ public static function provideArrayFlattening(): iterable
485512
];
486513
}
487514

515+
/**
516+
* @param list<string> $indexes
517+
* @param array<array-key, mixed> $data
518+
* @param array<array-key, mixed> $expected
519+
*/
488520
#[DataProvider('provideArrayGroupByIncludeEmpty')]
489521
public function testArrayGroupByIncludeEmpty(array $indexes, array $data, array $expected): void
490522
{
@@ -493,6 +525,9 @@ public function testArrayGroupByIncludeEmpty(array $indexes, array $data, array
493525
$this->assertSame($expected, $actual, 'array including empty not the same');
494526
}
495527

528+
/**
529+
* @return iterable<string, array{list<string>, array<array-key, mixed>, array<array-key, mixed>}>
530+
*/
496531
public static function provideArrayGroupByIncludeEmpty(): iterable
497532
{
498533
yield 'simple group-by test' => [
@@ -904,6 +939,11 @@ public static function provideArrayGroupByIncludeEmpty(): iterable
904939
];
905940
}
906941

942+
/**
943+
* @param list<string> $indexes
944+
* @param array<array-key, mixed> $data
945+
* @param array<array-key, mixed> $expected
946+
*/
907947
#[DataProvider('provideArrayGroupByExcludeEmpty')]
908948
public function testArrayGroupByExcludeEmpty(array $indexes, array $data, array $expected): void
909949
{
@@ -912,6 +952,9 @@ public function testArrayGroupByExcludeEmpty(array $indexes, array $data, array
912952
$this->assertSame($expected, $actual, 'array excluding empty not the same');
913953
}
914954

955+
/**
956+
* @return iterable<string, array{list<string>, array<array-key, mixed>, array<array-key, mixed>}>
957+
*/
915958
public static function provideArrayGroupByExcludeEmpty(): iterable
916959
{
917960
yield 'simple group-by test' => [

‎tests/system/Helpers/CookieHelperTest.php‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ protected function setUp(): void
5151
$this->value = 'hello world';
5252
$this->expire = 9999;
5353

54-
Services::injectMock('response', new MockResponse(new App()));
55-
$this->response = service('response');
56-
$request = new IncomingRequest(new App(), new SiteURI(new App()), null, new UserAgent());
54+
$response = new MockResponse(new App());
55+
Services::injectMock('response', $response);
56+
$this->response = $response;
57+
58+
$request = new IncomingRequest(new App(), new SiteURI(new App()), null, new UserAgent());
5759
Services::injectMock('request', $request);
5860

5961
helper('cookie');

‎tests/system/Helpers/FilesystemHelperTest.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,17 @@ public function testDirectoryMirrorSkipExistingFolder(): void
188188
// skips the existing folder
189189
directory_mirror($root . 'src', $root . 'dest');
190190

191-
$structure = vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure();
191+
$visitor = vfsStream::inspect(new vfsStreamStructureVisitor());
192+
$this->assertInstanceOf(vfsStreamStructureVisitor::class, $visitor);
193+
$structure = $visitor->getStructure();
192194
$this->assertSame([], $structure['root']['dest']['AnEmptyFolder']);
193195

194196
// skips the existing folder (the same as overwrite = true)
195197
directory_mirror($root . 'src', $root . 'dest', false);
196198

197-
$structure = vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure();
199+
$visitor = vfsStream::inspect(new vfsStreamStructureVisitor());
200+
$this->assertInstanceOf(vfsStreamStructureVisitor::class, $visitor);
201+
$structure = $visitor->getStructure();
198202
$this->assertSame([], $structure['root']['dest']['AnEmptyFolder']);
199203
}
200204

‎tests/system/Helpers/HTMLHelperTest.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
#[Group('Others')]
2727
final class HTMLHelperTest extends CIUnitTestCase
2828
{
29+
/**
30+
* @var list<string>
31+
*/
2932
private array $tracks;
3033

3134
/**

‎tests/system/Helpers/InflectorHelperTest.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ public function testOrdinal(string $suffix, int $number): void
252252
$this->assertSame($suffix, ordinal($number));
253253
}
254254

255+
/**
256+
* @return iterable<array{string, int}>
257+
*/
255258
public static function provideOrdinal(): iterable
256259
{
257260
return [

‎tests/system/Helpers/URLHelper/CurrentUrlTest.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function testCurrentURLReturnsAllowedHostname(): void
8989
$this->assertSame('http://www.example.jp/public/index.php/', current_url());
9090
}
9191

92-
private function createRequest(?App $config = null, $body = null, ?string $path = null): void
92+
private function createRequest(?App $config = null, ?string $body = null, ?string $path = null): void
9393
{
9494
$config ??= new App();
9595

@@ -281,6 +281,9 @@ public function testUrlIsWithSubfolder(string $currentPath, string $testPath, bo
281281
$this->assertSame($expected, url_is($testPath));
282282
}
283283

284+
/**
285+
* @return iterable<array{string, string, bool}>
286+
*/
284287
public static function provideUrlIs(): iterable
285288
{
286289
return [

0 commit comments

Comments
 (0)