Skip to content

Commit 420ef32

Browse files
committed
Improve Serialize coverage
1 parent 5798233 commit 420ef32

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/ArrayDeserializer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ protected function deserializeProperty(
141141
);
142142
}
143143

144-
if (is_array($value) && $attribute->itemType() !== null) {
145-
$deserializer = new static($attribute->itemType());
144+
if (is_array($value) && $attribute->getItemType() !== null) {
145+
$deserializer = new static($attribute->getItemType());
146146
$value = array_map(fn($item) => $deserializer->deserialize($item, $path . "." . $name), $value);
147147
}
148148

src/Serialize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function allowsNull(): ?bool
5454
/**
5555
* @return class-string|null
5656
*/
57-
public function itemType(): ?string
57+
public function getItemType(): ?string
5858
{
5959
return $this->itemType;
6060
}

tests/tests/SerializeTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Aternos\Serializer\Test\Tests;
44

55
use Aternos\Serializer\Serialize;
6+
use Aternos\Serializer\Test\Src\TestClass;
67
use PHPUnit\Framework\Attributes\CoversClass;
78
use PHPUnit\Framework\TestCase;
89
use ReflectionProperty;
@@ -66,4 +67,10 @@ public function testGetAttributeNone(): void
6667
$attribute = Serialize::getAttribute($property);
6768
$this->assertNull($attribute);
6869
}
70+
71+
public function testGetItemType(): void
72+
{
73+
$property = new Serialize(itemType: TestClass::class);
74+
$this->assertSame(TestClass::class, $property->getItemType());
75+
}
6976
}

0 commit comments

Comments
 (0)