Skip to content

Commit d140471

Browse files
committed
IBX-9727: [Tests] Aligned Forms transformers tests with generics fixes
1 parent 5be509e commit d140471

File tree

4 files changed

+51
-14
lines changed

4 files changed

+51
-14
lines changed

tests/lib/FieldType/DataTransformer/MultiSelectionValueTransformerTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,22 @@
1414

1515
class MultiSelectionValueTransformerTest extends TestCase
1616
{
17+
/**
18+
* @phpstan-return list<array{array<int>}>
19+
*/
1720
public function transformProvider(): array
1821
{
1922
return [
2023
[[0]],
21-
[['null']],
2224
[[1, 2]],
23-
[['forty', 'two']],
2425
[[1, 4, 1, 5, 9, 2, 6]],
2526
];
2627
}
2728

2829
/**
2930
* @dataProvider transformProvider
31+
*
32+
* @param array<int> $valueAsArray
3033
*/
3134
public function testTransform(array $valueAsArray): void
3235
{
@@ -37,6 +40,8 @@ public function testTransform(array $valueAsArray): void
3740

3841
/**
3942
* @dataProvider transformProvider
43+
*
44+
* @param array<int> $valueAsArray
4045
*/
4146
public function testReverseTransform(array $valueAsArray): void
4247
{
@@ -45,6 +50,9 @@ public function testReverseTransform(array $valueAsArray): void
4550
self::assertEquals($expectedValue, $transformer->reverseTransform($valueAsArray));
4651
}
4752

53+
/**
54+
* @phpstan-return list<array{mixed}>
55+
*/
4856
public function transformNullProvider(): array
4957
{
5058
return [

tests/lib/FieldType/DataTransformer/MultipleCountryValueTransformerTest.php

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212
use Ibexa\Core\FieldType\Country\Value;
1313
use PHPUnit\Framework\TestCase;
1414

15-
class MultipleCountryValueTransformerTest extends TestCase
15+
/**
16+
* @phpstan-import-type TCountryValueData from \Ibexa\ContentForms\FieldType\DataTransformer\MultipleCountryValueTransformer
17+
*/
18+
final class MultipleCountryValueTransformerTest extends TestCase
1619
{
1720
/**
18-
* @var array Array of countries from "ibexa.field_type.country.data"
21+
* Array of countries from "ibexa.field_type.country.data".
22+
*
23+
* @phpstan-var array<string, TCountryValueData>
1924
*/
20-
protected $countriesInfo = [
25+
protected array $countriesInfo = [
2126
'AF' => ['Name' => 'Afghanistan', 'Alpha2' => 'AF', 'Alpha3' => 'AFG', 'IDC' => '93'],
2227
'AX' => ['Name' => 'Åland', 'Alpha2' => 'AX', 'Alpha3' => 'ALA', 'IDC' => '358'],
2328
'AQ' => ['Name' => 'Antarctica', 'Alpha2' => 'AQ', 'Alpha3' => 'ATA', 'IDC' => '672'],
@@ -44,22 +49,31 @@ class MultipleCountryValueTransformerTest extends TestCase
4449
'ZW' => ['Name' => 'Zimbabwe', 'Alpha2' => 'ZW', 'Alpha3' => 'ZWE', 'IDC' => '263'],
4550
];
4651

52+
/**
53+
* @phpstan-return list<array{array<string, TCountryValueData>}>
54+
*/
4755
public function transformProvider(): array
4856
{
4957
return [
50-
[[
51-
'BN' => ['Name' => 'Brunei Darussalam', 'Alpha2' => 'BN', 'Alpha3' => 'BRN', 'IDC' => '673'],
52-
]],
53-
[[
54-
'AX' => ['Name' => 'Åland', 'Alpha2' => 'AX', 'Alpha3' => 'ALA', 'IDC' => '358'],
55-
'BL' => ['Name' => 'Saint Barthélemy', 'Alpha2' => 'BL', 'Alpha3' => 'BLM', 'IDC' => '590'],
56-
'GS' => ['Name' => 'South Georgia and The South Sandwich Islands', 'Alpha2' => 'GS', 'Alpha3' => 'SGS', 'IDC' => '500'],
57-
]],
58+
[
59+
[
60+
'BN' => ['Name' => 'Brunei Darussalam', 'Alpha2' => 'BN', 'Alpha3' => 'BRN', 'IDC' => '673'],
61+
],
62+
],
63+
[
64+
[
65+
'AX' => ['Name' => 'Åland', 'Alpha2' => 'AX', 'Alpha3' => 'ALA', 'IDC' => '358'],
66+
'BL' => ['Name' => 'Saint Barthélemy', 'Alpha2' => 'BL', 'Alpha3' => 'BLM', 'IDC' => '590'],
67+
'GS' => ['Name' => 'South Georgia and The South Sandwich Islands', 'Alpha2' => 'GS', 'Alpha3' => 'SGS', 'IDC' => '500'],
68+
],
69+
],
5870
];
5971
}
6072

6173
/**
6274
* @dataProvider transformProvider
75+
*
76+
* @phpstan-param array<string, TCountryValueData> $valueAsArray
6377
*/
6478
public function testTransform(array $valueAsArray): void
6579
{
@@ -70,6 +84,8 @@ public function testTransform(array $valueAsArray): void
7084

7185
/**
7286
* @dataProvider transformProvider
87+
*
88+
* @phpstan-param array<string, TCountryValueData> $valueAsArray
7389
*/
7490
public function testReverseTransform(array $valueAsArray): void
7591
{
@@ -78,6 +94,9 @@ public function testReverseTransform(array $valueAsArray): void
7894
self::assertEquals($expectedValue, $transformer->reverseTransform(array_keys($valueAsArray)));
7995
}
8096

97+
/**
98+
* @phpstan-return list<array{int|string|array<mixed>|null}>
99+
*/
81100
public function transformNullProvider(): array
82101
{
83102
return [
@@ -91,12 +110,15 @@ public function transformNullProvider(): array
91110
/**
92111
* @dataProvider transformNullProvider
93112
*/
94-
public function testTransformNull(int|string|array|null $value): void
113+
public function testTransformNull(mixed $value): void
95114
{
96115
$transformer = new MultipleCountryValueTransformer($this->countriesInfo);
97116
self::assertNull($transformer->transform($value));
98117
}
99118

119+
/**
120+
* @phpstan-return list<array{mixed}>
121+
*/
100122
public function reverseTransformNullProvider(): array
101123
{
102124
return [

tests/lib/FieldType/DataTransformer/SingleSelectionValueTransformerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
class SingleSelectionValueTransformerTest extends TestCase
1616
{
17+
/**
18+
* @phpstan-return list<array{int}>
19+
*/
1720
public function transformProvider(): array
1821
{
1922
return [
@@ -42,6 +45,9 @@ public function testReverseTransform(int $value): void
4245
self::assertEquals($expectedValue, $transformer->reverseTransform($value));
4346
}
4447

48+
/**
49+
* @phpstan-return list<array{mixed}>
50+
*/
4551
public function transformNullProvider(): array
4652
{
4753
return [

tests/lib/FieldType/DataTransformer/TimeValueTransformerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function testTransformInvalidValue(): void
4747
$transformer = new TimeValueTransformer();
4848

4949
$this->expectException(TransformationFailedException::class);
50+
/** @phpstan-ignore argument.type */
5051
$transformer->transform((object) ['time' => 1]);
5152
}
5253
}

0 commit comments

Comments
 (0)