Skip to content

Commit fec6d2e

Browse files
committed
chore: add phpstan shapes as phpstan has become a bit stricter
1 parent 217e59e commit fec6d2e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/Encoding/EncoderTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Encoding;
66

7+
use Countable;
78
use DateTimeImmutable;
89
use Generator;
910
use MinVWS\Codable\Encoding\Encoder;
@@ -17,6 +18,26 @@
1718
use PHPUnit\Framework\Attributes\DataProvider;
1819
use 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+
*/
2041
class 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

Comments
 (0)