Skip to content
Open
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
6 changes: 3 additions & 3 deletions system/Helpers/number_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
/**
* Formats a numbers as bytes, based on size, and adds the appropriate suffix
*
* @param int|string $num Will be cast as int
* @param float|int|string $num Will be cast as int
* @param non-empty-string|null $locale [optional]
*
* @return bool|string
*/
function number_to_size($num, int $precision = 1, ?string $locale = null)
{
// Strip any formatting & ensure numeric input
try {
// @phpstan-ignore-next-line
// Strip any formatting & ensure numeric input
// @phpstan-ignore binaryOp.invalid
$num = 0 + str_replace(',', '', (string) $num);
} catch (ErrorException) {
// Catch "Warning: A non-numeric value encountered"
Expand Down
3 changes: 3 additions & 0 deletions tests/system/Helpers/Array/ArrayHelperDotKeyExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#[Group('Others')]
final class ArrayHelperDotKeyExistsTest extends CIUnitTestCase
{
/**
* @var array<string, array<string, list<array<string, int|string>>>>
*/
private array $array = [
'contacts' => [
'friends' => [
Expand Down
3 changes: 3 additions & 0 deletions tests/system/Helpers/Array/ArrayHelperRecursiveDiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#[Group('Others')]
final class ArrayHelperRecursiveDiffTest extends CIUnitTestCase
{
/**
* @var array<array-key, mixed>
*/
private array $compareWith;

protected function setUp(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#[Group('Others')]
final class ArrayHelperSortValuesByNaturalTest extends CIUnitTestCase
{
/**
* @var list<int|string>
*/
private array $arrayWithStringValues = [
'apple10',
'banana',
Expand All @@ -37,6 +40,10 @@ final class ArrayHelperSortValuesByNaturalTest extends CIUnitTestCase
'Яблоко',
'apple',
];

/**
* @var list<list<int|string>>
*/
private array $arrayWithArrayValues = [
['apple', 'Banana'],
['apple10', 'Apple'],
Expand Down
49 changes: 46 additions & 3 deletions tests/system/Helpers/ArrayHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,10 @@ public function testArrayDotIgnoresLastWildcard(): void
}

/**
* @param int|string $key
* @param array|string|null $expected
* @param array<array-key, mixed>|string|null $expected
*/
#[DataProvider('provideArrayDeepSearch')]
public function testArrayDeepSearch($key, $expected): void
public function testArrayDeepSearch(int|string $key, array|string|null $expected): void
{
$data = [
'key1' => 'Value 1',
Expand All @@ -241,6 +240,9 @@ public function testArrayDeepSearch($key, $expected): void
$this->assertSame($expected, $result);
}

/**
* @return iterable<array{int|string, array<array-key, mixed>|string|null}>
*/
public static function provideArrayDeepSearch(): iterable
{
return [
Expand Down Expand Up @@ -274,6 +276,11 @@ public function testArrayDeepSearchReturnNullEmptyArray(): void
$this->assertNull(array_deep_search('key644', $data));
}

/**
* @param list<array{name: string, position: int, team: array{order: int}}> $data
* @param array<string, int> $sortColumns
* @param list<string> $expected
*/
#[DataProvider('provideSortByMultipleKeys')]
public function testArraySortByMultipleKeysWithArray(array $data, array $sortColumns, array $expected): void
{
Expand All @@ -283,6 +290,11 @@ public function testArraySortByMultipleKeysWithArray(array $data, array $sortCol
$this->assertSame($expected, array_column($data, 'name'));
}

/**
* @param list<array{name: string, position: int, team: array{order: int}}> $data
* @param array<string, int> $sortColumns
* @param list<string> $expected
*/
#[DataProvider('provideSortByMultipleKeys')]
public function testArraySortByMultipleKeysWithObjects(array $data, array $sortColumns, array $expected): void
{
Expand All @@ -297,6 +309,11 @@ public function testArraySortByMultipleKeysWithObjects(array $data, array $sortC
$this->assertSame($expected, array_column($data, 'name'));
}

/**
* @param list<array{name: string, position: int, team: array{order: int}}> $data
* @param array<string, int> $sortColumns
* @param list<string> $expected
*/
#[DataProvider('provideSortByMultipleKeys')]
public function testArraySortByMultipleKeysFailsEmptyParameter(array $data, array $sortColumns, array $expected): void
{
Expand Down Expand Up @@ -334,6 +351,9 @@ public function testArraySortByMultipleKeysFailsInconsistentArraySizes($data): v
array_sort_by_multiple_keys($data, $sortColumns);
}

/**
* @return iterable<array{list<array{name: string, position: int, team: array{order: int}}>, array<string, int>, list<string>}>
*/
public static function provideSortByMultipleKeys(): iterable
{
$seed = [
Expand Down Expand Up @@ -387,12 +407,19 @@ public static function provideSortByMultipleKeys(): iterable
];
}

/**
* @param array<array-key, mixed> $input
* @param array<string, mixed> $expected
*/
#[DataProvider('provideArrayFlattening')]
public function testArrayFlattening(array $input, array $expected): void
{
$this->assertSame($expected, array_flatten_with_dots($input));
}

/**
* @return iterable<string, array{array<array-key, mixed>, array<string, mixed>}>
*/
public static function provideArrayFlattening(): iterable
{
yield 'normal' => [
Expand Down Expand Up @@ -485,6 +512,11 @@ public static function provideArrayFlattening(): iterable
];
}

/**
* @param list<string> $indexes
* @param array<array-key, mixed> $data
* @param array<array-key, mixed> $expected
*/
#[DataProvider('provideArrayGroupByIncludeEmpty')]
public function testArrayGroupByIncludeEmpty(array $indexes, array $data, array $expected): void
{
Expand All @@ -493,6 +525,9 @@ public function testArrayGroupByIncludeEmpty(array $indexes, array $data, array
$this->assertSame($expected, $actual, 'array including empty not the same');
}

/**
* @return iterable<string, array{list<string>, array<array-key, mixed>, array<array-key, mixed>}>
*/
public static function provideArrayGroupByIncludeEmpty(): iterable
{
yield 'simple group-by test' => [
Expand Down Expand Up @@ -904,6 +939,11 @@ public static function provideArrayGroupByIncludeEmpty(): iterable
];
}

/**
* @param list<string> $indexes
* @param array<array-key, mixed> $data
* @param array<array-key, mixed> $expected
*/
#[DataProvider('provideArrayGroupByExcludeEmpty')]
public function testArrayGroupByExcludeEmpty(array $indexes, array $data, array $expected): void
{
Expand All @@ -912,6 +952,9 @@ public function testArrayGroupByExcludeEmpty(array $indexes, array $data, array
$this->assertSame($expected, $actual, 'array excluding empty not the same');
}

/**
* @return iterable<string, array{list<string>, array<array-key, mixed>, array<array-key, mixed>}>
*/
public static function provideArrayGroupByExcludeEmpty(): iterable
{
yield 'simple group-by test' => [
Expand Down
8 changes: 5 additions & 3 deletions tests/system/Helpers/CookieHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ protected function setUp(): void
$this->value = 'hello world';
$this->expire = 9999;

Services::injectMock('response', new MockResponse(new App()));
$this->response = service('response');
$request = new IncomingRequest(new App(), new SiteURI(new App()), null, new UserAgent());
$response = new MockResponse(new App());
Services::injectMock('response', $response);
$this->response = $response;

$request = new IncomingRequest(new App(), new SiteURI(new App()), null, new UserAgent());
Services::injectMock('request', $request);

helper('cookie');
Expand Down
8 changes: 6 additions & 2 deletions tests/system/Helpers/FilesystemHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,17 @@ public function testDirectoryMirrorSkipExistingFolder(): void
// skips the existing folder
directory_mirror($root . 'src', $root . 'dest');

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

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

$structure = vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure();
$visitor = vfsStream::inspect(new vfsStreamStructureVisitor());
$this->assertInstanceOf(vfsStreamStructureVisitor::class, $visitor);
$structure = $visitor->getStructure();
$this->assertSame([], $structure['root']['dest']['AnEmptyFolder']);
}

Expand Down
3 changes: 3 additions & 0 deletions tests/system/Helpers/HTMLHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#[Group('Others')]
final class HTMLHelperTest extends CIUnitTestCase
{
/**
* @var list<string>
*/
private array $tracks;

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/system/Helpers/InflectorHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ public function testOrdinal(string $suffix, int $number): void
$this->assertSame($suffix, ordinal($number));
}

/**
* @return iterable<array{string, int}>
*/
public static function provideOrdinal(): iterable
{
return [
Expand Down
5 changes: 4 additions & 1 deletion tests/system/Helpers/URLHelper/CurrentUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function testCurrentURLReturnsAllowedHostname(): void
$this->assertSame('http://www.example.jp/public/index.php/', current_url());
}

private function createRequest(?App $config = null, $body = null, ?string $path = null): void
private function createRequest(?App $config = null, ?string $body = null, ?string $path = null): void
{
$config ??= new App();

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

/**
* @return iterable<array{string, string, bool}>
*/
public static function provideUrlIs(): iterable
{
return [
Expand Down
Loading
Loading