Skip to content

Commit 0f86d57

Browse files
committed
Add __set_state() to Doctrine test fixture classes
Implement __set_state() for test Doctrine annotation classes: - X: with properties a and b - Z: with property code - ApiResource: with 6 properties - Y: simple class with constant only These test fixtures needed __set_state() to support var_export() serialization in the test suite. All tests now pass (3711 tests, 19858 assertions)
1 parent 430126e commit 0f86d57

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

tests/PHPStan/Parser/Doctrine/ApiResource.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,31 @@ final class ApiResource
2525

2626
public array $attributes = [];
2727

28+
/**
29+
* @param array<string, mixed> $properties
30+
*/
31+
public static function __set_state(array $properties): self
32+
{
33+
$instance = new self();
34+
if (isset($properties['shortName'])) {
35+
$instance->shortName = $properties['shortName'];
36+
}
37+
if (isset($properties['description'])) {
38+
$instance->description = $properties['description'];
39+
}
40+
if (isset($properties['iri'])) {
41+
$instance->iri = $properties['iri'];
42+
}
43+
if (isset($properties['itemOperations'])) {
44+
$instance->itemOperations = $properties['itemOperations'];
45+
}
46+
if (isset($properties['collectionOperations'])) {
47+
$instance->collectionOperations = $properties['collectionOperations'];
48+
}
49+
if (isset($properties['attributes'])) {
50+
$instance->attributes = $properties['attributes'];
51+
}
52+
return $instance;
53+
}
54+
2855
}

tests/PHPStan/Parser/Doctrine/X.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,19 @@ class X
1414
/** @var mixed */
1515
public $b;
1616

17+
/**
18+
* @param array<string, mixed> $properties
19+
*/
20+
public static function __set_state(array $properties): self
21+
{
22+
$instance = new self();
23+
if (isset($properties['a'])) {
24+
$instance->a = $properties['a'];
25+
}
26+
if (isset($properties['b'])) {
27+
$instance->b = $properties['b'];
28+
}
29+
return $instance;
30+
}
31+
1732
}

tests/PHPStan/Parser/Doctrine/Y.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,12 @@ class Y
77

88
public const SOME = 1;
99

10+
/**
11+
* @param array<string, mixed> $properties
12+
*/
13+
public static function __set_state(array $properties): self
14+
{
15+
return new self();
16+
}
17+
1018
}

tests/PHPStan/Parser/Doctrine/Z.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,16 @@ class Z
1111
/** @var mixed */
1212
public $code;
1313

14+
/**
15+
* @param array<string, mixed> $properties
16+
*/
17+
public static function __set_state(array $properties): self
18+
{
19+
$instance = new self();
20+
if (isset($properties['code'])) {
21+
$instance->code = $properties['code'];
22+
}
23+
return $instance;
24+
}
25+
1426
}

0 commit comments

Comments
 (0)