diff --git a/composer.json b/composer.json index 3d6874e..3c12ac8 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "yzen.dev/plain-to-class", - "version": "3.0.2", + "version": "3.0.3", "description": "Class-transformer to transform your dataset into a structured object", "minimum-stability": "dev", "prefer-stable": true, diff --git a/composer.lock b/composer.lock index 43ff397..bc4682e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5a0b6ab9a620c712b6b5c2c8cc3bc364", + "content-hash": "38393cf49708cbd2c627803180a174c8", "packages": [], "packages-dev": [ { diff --git a/src/ValueCasting.php b/src/ValueCasting.php index add0973..bebe006 100644 --- a/src/ValueCasting.php +++ b/src/ValueCasting.php @@ -47,7 +47,7 @@ public function __construct(ReflectionProperty $property, HydratorConfig $config */ public function castAttribute(mixed $value): mixed { - if ($this->property->type->isNullable && empty($value)) { + if ($this->property->type->isNullable && $value === null) { return null; } diff --git a/tests/Units/ValueCastingTest.php b/tests/Units/ValueCastingTest.php index ba563ac..320edd0 100644 --- a/tests/Units/ValueCastingTest.php +++ b/tests/Units/ValueCastingTest.php @@ -50,19 +50,19 @@ public function testCreateProperty(): void $caster = new ValueCasting(new RuntimeReflectionProperty(new \ReflectionProperty(TypesDto::class, 'nullableInt'))); - $value = $caster->castAttribute(''); + $value = $caster->castAttribute(null); $this->assertNull($value); $caster = new ValueCasting(new RuntimeReflectionProperty(new \ReflectionProperty(TypesDto::class, 'nullableString'))); - $value = $caster->castAttribute(''); + $value = $caster->castAttribute(null); $this->assertNull($value); $caster = new ValueCasting(new RuntimeReflectionProperty(new \ReflectionProperty(TypesDto::class, 'nullableFloat'))); - $value = $caster->castAttribute(''); + $value = $caster->castAttribute(null); $this->assertNull($value); $caster = new ValueCasting(new RuntimeReflectionProperty(new \ReflectionProperty(TypesDto::class, 'nullableBool'))); - $value = $caster->castAttribute(''); + $value = $caster->castAttribute(null); $this->assertNull($value); }