Skip to content

Commit

Permalink
add Unit-Testcase for the changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasKuehneEllerhold committed Nov 13, 2023
1 parent 5294806 commit ff217a0
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions test/View/Helper/NumberFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function setUp(): void
}

/** @return array<array-key, array{0: string, 1: int, 2: int, 3: int|null, 4: array<int, string>, 5: float, 6: string}> */

Check failure on line 25 in test/View/Helper/NumberFormatTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

InvalidReturnType

test/View/Helper/NumberFormatTest.php:25:17: InvalidReturnType: The declared return type 'array<array-key, array{0: string, 1: int, 2: int, 3: int|null, 4: array<int, string>, 5: float, 6: string}>' for LaminasTest\I18n\View\Helper\NumberFormatTest::numberTestsDataProvider is incorrect, got 'list{list{'de_DE', 1, 3, null, array<never, never>, null, float(1234567.8912346), '1.234.567,891'}, list{'de_DE', 1, 3, 6, array<never, never>, null, float(1234567.8912346), '1.234.567,891235'}, list{'de_DE', 3, 3, null, array<never, never>, null, float(1234567.8912346), '123.456.789 %'}, list{'de_DE', 3, 3, 1, array<never, never>, null, float(1234567.8912346), '123.456.789,1 %'}, list{'de_DE', 4, 3, null, array<never, never>, null, float(1234567.8912346), '1,23456789123456E6'}, list{'ru_RU', 1, 3, null, array<never, never>, null, float(1234567.8912346), '1 234 567,891'}, list{'ru_RU', 3, 3, null, array<never, never>, null, float(1234567.8912346), '123 456 789 %'}, list{'ru_RU', 4, 3, null, array<never, never>, null, float(1234567.8912346), '1,23456789123456E6'}, list{'en_US', 1, 3, null, array<never, never>, null, float(1234567.8912346), '1,234,567.891'}, list{'en_US', 3, 3, null, array<never, never>, null, float(1234567.8912346), '123,456,789%'}, list{'en_US', 4, 3, null, array<never, never>, null, float(1234567.8912346), '1.23456789123456E6'}, list{'en_US', 3, 3, null, array{2: 'MINUS'}, null, float(-1234567.8912346), 'MINUS123,456,789%'}, list{'de_DE', 1, 3, 5, array<never, never>, 0, float(1234567.8912346), '1.234.567,89123'}, list{'de_DE', 1, 3, 5, array<never, never>, 0, 1234567, '1.234.567'}}' (see https://psalm.dev/011)
public static function currencyTestsDataProvider(): array
public static function numberTestsDataProvider(): array

Check failure on line 26 in test/View/Helper/NumberFormatTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

PossiblyUnusedMethod

test/View/Helper/NumberFormatTest.php:26:28: PossiblyUnusedMethod: Cannot find any calls to method LaminasTest\I18n\View\Helper\NumberFormatTest::numberTestsDataProvider (see https://psalm.dev/087)
{
return [

Check failure on line 28 in test/View/Helper/NumberFormatTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

InvalidReturnStatement

test/View/Helper/NumberFormatTest.php:28:16: InvalidReturnStatement: The inferred type 'list{list{'de_DE', 1, 3, null, array<never, never>, null, float(1234567.8912346), '1.234.567,891'}, list{'de_DE', 1, 3, 6, array<never, never>, null, float(1234567.8912346), '1.234.567,891235'}, list{'de_DE', 3, 3, null, array<never, never>, null, float(1234567.8912346), '123.456.789 %'}, list{'de_DE', 3, 3, 1, array<never, never>, null, float(1234567.8912346), '123.456.789,1 %'}, list{'de_DE', 4, 3, null, array<never, never>, null, float(1234567.8912346), '1,23456789123456E6'}, list{'ru_RU', 1, 3, null, array<never, never>, null, float(1234567.8912346), '1 234 567,891'}, list{'ru_RU', 3, 3, null, array<never, never>, null, float(1234567.8912346), '123 456 789 %'}, list{'ru_RU', 4, 3, null, array<never, never>, null, float(1234567.8912346), '1,23456789123456E6'}, list{'en_US', 1, 3, null, array<never, never>, null, float(1234567.8912346), '1,234,567.891'}, list{'en_US', 3, 3, null, array<never, never>, null, float(1234567.8912346), '123,456,789%'}, list{'en_US', 4, 3, null, array<never, never>, null, float(1234567.8912346), '1.23456789123456E6'}, list{'en_US', 3, 3, null, array{2: 'MINUS'}, null, float(-1234567.8912346), 'MINUS123,456,789%'}, list{'de_DE', 1, 3, 5, array<never, never>, 0, float(1234567.8912346), '1.234.567,89123'}, list{'de_DE', 1, 3, 5, array<never, never>, 0, 1234567, '1.234.567'}}' does not match the declared return type 'array<array-key, array{0: string, 1: int, 2: int, 3: int|null, 4: array<int, string>, 5: float, 6: string}>' for LaminasTest\I18n\View\Helper\NumberFormatTest::numberTestsDataProvider (see https://psalm.dev/128)
[
Expand All @@ -32,6 +32,7 @@ public static function currencyTestsDataProvider(): array
NumberFormatter::TYPE_DOUBLE,
null,
[],
null,
1234567.891234567890000,
'1.234.567,891',
],
Expand All @@ -41,6 +42,7 @@ public static function currencyTestsDataProvider(): array
NumberFormatter::TYPE_DOUBLE,
6,
[],
null,
1234567.891234567890000,
'1.234.567,891235',
],
Expand All @@ -50,6 +52,7 @@ public static function currencyTestsDataProvider(): array
NumberFormatter::TYPE_DOUBLE,
null,
[],
null,
1234567.891234567890000,
'123.456.789 %',
],
Expand All @@ -59,6 +62,7 @@ public static function currencyTestsDataProvider(): array
NumberFormatter::TYPE_DOUBLE,
1,
[],
null,
1234567.891234567890000,
'123.456.789,1 %',
],
Expand All @@ -68,6 +72,7 @@ public static function currencyTestsDataProvider(): array
NumberFormatter::TYPE_DOUBLE,
null,
[],
null,
1234567.891234560000,
'1,23456789123456E6',
],
Expand All @@ -77,6 +82,7 @@ public static function currencyTestsDataProvider(): array
NumberFormatter::TYPE_DOUBLE,
null,
[],
null,
1234567.891234567890000,
'1 234 567,891',
],
Expand All @@ -86,6 +92,7 @@ public static function currencyTestsDataProvider(): array
NumberFormatter::TYPE_DOUBLE,
null,
[],
null,
1234567.891234567890000,
'123 456 789 %',
],
Expand All @@ -95,6 +102,7 @@ public static function currencyTestsDataProvider(): array
NumberFormatter::TYPE_DOUBLE,
null,
[],
null,
1234567.891234560000,
'1,23456789123456E6',
],
Expand All @@ -104,6 +112,7 @@ public static function currencyTestsDataProvider(): array
NumberFormatter::TYPE_DOUBLE,
null,
[],
null,
1234567.891234567890000,
'1,234,567.891',
],
Expand All @@ -113,6 +122,7 @@ public static function currencyTestsDataProvider(): array
NumberFormatter::TYPE_DOUBLE,
null,
[],
null,
1234567.891234567890000,
'123,456,789%',
],
Expand All @@ -122,6 +132,7 @@ public static function currencyTestsDataProvider(): array
NumberFormatter::TYPE_DOUBLE,
null,
[],
null,
1234567.891234560000,
'1.23456789123456E6',
],
Expand All @@ -133,22 +144,44 @@ public static function currencyTestsDataProvider(): array
[
NumberFormatter::NEGATIVE_PREFIX => 'MINUS',
],
null,
-1234567.891234567890000,
'MINUS123,456,789%',
],
[
'de_DE',
NumberFormatter::DECIMAL,
NumberFormatter::TYPE_DOUBLE,
5,
[],
0,
1234567.891234567890000,
'1.234.567,89123',
],
[
'de_DE',
NumberFormatter::DECIMAL,
NumberFormatter::TYPE_DOUBLE,
5,
[],
0,
1234567,
'1.234.567',
],
];
}

/**
* @param array<int, string> $textAttributes
*/
#[DataProvider('currencyTestsDataProvider')]
#[DataProvider('numberTestsDataProvider')]
public function testBasic(
string $locale,
int $formatStyle,
int $formatType,
?int $decimals,
array $textAttributes,
?int $minDecimals,
float $number,
string $expected
): void {
Expand All @@ -158,29 +191,32 @@ public function testBasic(
$formatType,
$locale,
$decimals,
$textAttributes
$textAttributes,
$minDecimals
));
}

/**
* @param array<int, string> $textAttributes
*/
#[DataProvider('currencyTestsDataProvider')]
#[DataProvider('numberTestsDataProvider')]
public function testSettersProvideDefaults(
string $locale,
int $formatStyle,
int $formatType,
?int $decimals,
array $textAttributes,
?int $minDecimals,
float $number,
string $expected
): void {
$this->helper
->setLocale($locale)
->setFormatStyle($formatStyle)
->setDecimals($decimals)
->setMaxDecimals($decimals)
->setFormatType($formatType)
->setTextAttributes($textAttributes);
->setTextAttributes($textAttributes)
->setMinDecimals($minDecimals);

self::assertMbStringEquals($expected, $this->helper->__invoke($number));
}
Expand Down

0 comments on commit ff217a0

Please sign in to comment.