44
55namespace Encoding ;
66
7+ use Countable ;
78use DateTimeImmutable ;
89use Generator ;
910use MinVWS \Codable \Encoding \Encoder ;
1718use PHPUnit \Framework \Attributes \DataProvider ;
1819use PHPUnit \Framework \TestCase ;
1920
21+ /**
22+ * @phpstan-type PersonShape array{
23+ * firstName: string,
24+ * infix: string,
25+ * surname: string,
26+ * birthDate: string,
27+ * favoriteFruit: string,
28+ * address: array{
29+ * country: string,
30+ * },
31+ * dislikedFruits: array<Fruit>,
32+ * notes: array<string>,
33+ * }
34+ * @phpstan-type FruitSaladShape array{
35+ * title: string,
36+ * description: string,
37+ * author: string,
38+ * fruits: Countable,
39+ * }
40+ */
2041class EncoderTest extends TestCase
2142{
2243 use WithFaker;
@@ -98,6 +119,8 @@ public function testEncodeComplexType(Person $person): void
98119 {
99120 $ encoder = new Encoder ();
100121 $ encoder ->getContext ()->setUseAssociativeArraysForObjects (true );
122+
123+ /** @var PersonShape $data */
101124 $ data = $ encoder ->encode ($ person );
102125 $ this ->assertIsArray ($ data );
103126 $ this ->assertEquals ($ person ->firstName , $ data ['firstName ' ]);
@@ -119,6 +142,7 @@ public static function encodingModeProvider(): Generator
119142 yield [EncodingContext::MODE_DISPLAY , false ];
120143 }
121144
145+
122146 #[DataProvider('encodingModeProvider ' )]
123147 public function testEncodingMode (?string $ mode , bool $ expectsAuthor ): void
124148 {
@@ -132,6 +156,8 @@ public function testEncodingMode(?string $mode, bool $expectsAuthor): void
132156 $ encoder = new Encoder ();
133157 $ encoder ->getContext ()->setMode ($ mode );
134158 $ encoder ->getContext ()->setUseAssociativeArraysForObjects (true );
159+
160+ /** @var FruitSaladShape $data */
135161 $ data = $ encoder ->encode ($ salad );
136162 $ this ->assertIsArray ($ data );
137163 $ this ->assertEquals ($ salad ->title , $ data ['title ' ]);
0 commit comments