diff --git a/clover.xml b/clover.xml index af634e2..51124f8 100644 --- a/clover.xml +++ b/clover.xml @@ -1,8 +1,8 @@ - - + + - + @@ -10,7 +10,7 @@ - + @@ -18,13 +18,13 @@ - + - + @@ -36,7 +36,7 @@ - + @@ -48,7 +48,7 @@ - + @@ -72,7 +72,7 @@ - + @@ -100,7 +100,7 @@ - + @@ -128,7 +128,7 @@ - + @@ -146,9 +146,9 @@ - + - + @@ -169,54 +169,50 @@ - - + + - - - - - - - + + + + + + - + - - - + + + - + - - - - - - - + + + + + + + - - + - - - - - - - - - - - + + + + + + + + + - + @@ -253,7 +249,7 @@ - + @@ -264,32 +260,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - + @@ -323,7 +296,7 @@ - + @@ -379,13 +352,14 @@ - + - + + @@ -393,42 +367,41 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + - + @@ -516,7 +489,7 @@ - + @@ -580,20 +553,17 @@ - + - + - + - - - - + @@ -601,7 +571,7 @@ - + @@ -609,7 +579,7 @@ - + @@ -662,14 +632,14 @@ - + - + - + @@ -700,11 +670,11 @@ - + - + @@ -735,7 +705,7 @@ - + @@ -770,15 +740,59 @@ - + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -789,29 +803,55 @@ - + - + - + - - - - + - + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -830,7 +870,7 @@ - + @@ -854,7 +894,7 @@ - + @@ -863,11 +903,11 @@ - + - + @@ -895,7 +935,7 @@ - + @@ -912,7 +952,7 @@ - + @@ -931,7 +971,7 @@ - + @@ -939,7 +979,7 @@ - + @@ -957,7 +997,7 @@ - + @@ -974,7 +1014,7 @@ - + @@ -986,7 +1026,7 @@ - + @@ -1006,7 +1046,7 @@ - + @@ -1025,7 +1065,7 @@ - + @@ -1051,7 +1091,7 @@ - + @@ -1071,7 +1111,7 @@ - + @@ -1079,33 +1119,33 @@ - - - - - + + + + - + - - - - - - - - + + + + + + + - - - - - - + + + + + + + + - + @@ -1144,7 +1184,7 @@ - + @@ -1183,7 +1223,7 @@ - + @@ -1221,7 +1261,7 @@ - + @@ -1260,7 +1300,7 @@ - + @@ -1277,21 +1317,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + @@ -1308,7 +1376,7 @@ - + @@ -1330,7 +1398,7 @@ - + @@ -1364,7 +1432,7 @@ - + @@ -1374,6 +1442,6 @@ - + diff --git a/src/Concerns/BaseData.php b/src/Concerns/BaseData.php index d5cc8c7..0b2ec52 100644 --- a/src/Concerns/BaseData.php +++ b/src/Concerns/BaseData.php @@ -54,9 +54,7 @@ final public static function from(mixed $value): static $value = static::normalizeValue($value, static::class); if ($value === false) { - throw new DeserializeException( - code: DeserializeException::INVALID_VALUE_ERROR_CODE - ); + throw DeserializeException::invalidValue(); } /** @var ClassContext $context */ @@ -73,7 +71,7 @@ classContext: $context, ? static::instanceWithConstructorCallFrom($context, $data) : static::instanceWithoutConstructorFrom($context, $data); } catch (Throwable $e) { - throw new DeserializeException($e->getMessage(), $e->getCode(), $e); + throw DeserializeException::generic($e); } } @@ -111,9 +109,7 @@ protected static function instanceWithConstructorCallFrom(ClassContext $context, $propertyContext = $context->properties[$paramName] ?? null; if (!$propertyContext) { - throw new DeserializeException( - "Could not find property context for constructor param: $paramName" - ); + throw DeserializeException::invalidParamsPassed(); } $args[$paramName] = $propertyContext->deserializeFrom($value); @@ -145,7 +141,7 @@ final public function jsonSerialize(): array return $serializedData; } catch (Throwable $e) { - throw new SerializeException($e->getMessage(), $e->getCode(), $e); + throw SerializeException::generic($e); } } diff --git a/src/Contexts/PropertyContext.php b/src/Contexts/PropertyContext.php index 3619ae0..7886500 100644 --- a/src/Contexts/PropertyContext.php +++ b/src/Contexts/PropertyContext.php @@ -194,29 +194,28 @@ public function deserializeFrom(array $value): mixed } } - throw new DeserializeException('Could not deserialize value for property: ' . $this->propertyName); + throw DeserializeException::generic(); } /** * @return array * * @throws SerializeException - * @throws UnknownTypeException */ public function serializeFrom(object $object): array { - foreach ($this->serializers() as $serializer) { - try { - $serializedData = $serializer->serialize($this, $object); - } catch (SerializeException) { + try { + foreach ($this->serializers() as $serializer) { + try { + $serializedData = $serializer->serialize($this, $object); + } catch (SerializeException) { + } } - } - if (empty($serializedData)) { - throw new SerializeException('Could not serialize value for property: ' . $this->propertyName); - } + if (empty($serializedData)) { + throw new Exception(); + } - try { if ($this->cipherConfig) { return array_map( fn (mixed $value) => $this->cipherConfig->dataCipherClass::cipher( @@ -229,8 +228,8 @@ public function serializeFrom(object $object): array } return $serializedData; - } catch (Exception) { - throw new SerializeException('Could not serialize value for property: ' . $this->propertyName); + } catch (Exception $e) { + throw SerializeException::generic($e); } } diff --git a/src/DataRefiners/DateTimeRefiner.php b/src/DataRefiners/DateTimeRefiner.php index 9b1c170..517de6f 100644 --- a/src/DataRefiners/DateTimeRefiner.php +++ b/src/DataRefiners/DateTimeRefiner.php @@ -45,7 +45,7 @@ public function refine(mixed $value, PropertyContext $property): mixed $typeContexts = $property->getFilteredTypeContexts(Type::DATETIME); if (empty($typeContexts)) { - throw InvalidRefiner::from($this, $property); + throw InvalidRefiner::emptyTypeContexts(); } $refinedValue = false; diff --git a/src/Exceptions/DeserializeException.php b/src/Exceptions/DeserializeException.php index 85b4632..9670e61 100644 --- a/src/Exceptions/DeserializeException.php +++ b/src/Exceptions/DeserializeException.php @@ -7,15 +7,86 @@ class DeserializeException extends Exception { - public const int GENERIC_ERROR_CODE = 0; - public const int INVALID_VALUE_ERROR_CODE = 1; - public const int NO_SERIALIZERS_ERROR_CODE = 2; - - public function __construct( - string $message = 'Failed to deserialize data', - int $code = self::GENERIC_ERROR_CODE, - ?Throwable $previous = null - ) { - parent::__construct($message, $code, $previous); + protected const int GENERIC_ERROR_CODE = 0; + protected const int INVALID_VALUE_ERROR_CODE = 1; + protected const int PROPERTY_IS_NOT_NULLABLE_ERROR_CODE = 2; + protected const int UNABLE_TO_DESERIALIZE_SCALAR_TYPE_ITEM_ERROR_CODE = 3; + protected const int UNABLE_TO_DESERIALIZE_BACKED_ENUM_ITEM_ERROR_CODE = 4; + protected const int UNABLE_TO_DESERIALIZE_DATE_TIME_ITEM_ERROR_CODE = 5; + protected const int UNABLE_TO_DESERIALIZE_DATA_ITEM_ERROR_CODE = 6; + protected const int UNABLE_TO_DESERIALIZE_ARRAY_ITEM_ERROR_CODE = 7; + protected const int INVALID_PARAMS_PASSED_ERROR_CODE = 8; + + public static function generic(?Throwable $throwable = null): self + { + return new self( + message: 'An error occurred while deserializing data', + code: self::GENERIC_ERROR_CODE, + previous: $throwable + ); + } + + public static function invalidValue(): self + { + return new self( + message: 'Invalid value passed to from method', + code: self::INVALID_VALUE_ERROR_CODE + ); + } + + public static function propertyIsNotNullable(): self + { + return new self( + message: 'Property is not nullable', + code: self::PROPERTY_IS_NOT_NULLABLE_ERROR_CODE + ); + } + + public static function unableToDeserializeScalarTypeItem(): self + { + return new self( + message: 'Could not deserialize scalar type item', + code: self::UNABLE_TO_DESERIALIZE_SCALAR_TYPE_ITEM_ERROR_CODE + ); + } + + public static function unableToDeserializeBackedEnumItem(): self + { + return new self( + message: 'Could not deserialize BackedEnum item', + code: self::UNABLE_TO_DESERIALIZE_BACKED_ENUM_ITEM_ERROR_CODE + ); + } + + public static function unableToDeserializeDateTimeItem(): self + { + return new self( + message: 'Could not deserialize DateTime item', + code: self::UNABLE_TO_DESERIALIZE_DATE_TIME_ITEM_ERROR_CODE + ); + } + + public static function unableToDeserializeDataItem(): self + { + return new self( + message: 'Could not deserialize Data item', + code: self::UNABLE_TO_DESERIALIZE_DATA_ITEM_ERROR_CODE + ); + } + + public static function unableToDeserializeArrayItem(): self + { + return new self( + message: 'Could not deserialize array item', + code: self::UNABLE_TO_DESERIALIZE_ARRAY_ITEM_ERROR_CODE + ); + } + + public static function invalidParamsPassed(): self + { + return new self( + message: 'Invalid params passed', + code: self::INVALID_PARAMS_PASSED_ERROR_CODE + ); } } diff --git a/src/Exceptions/InvalidRefiner.php b/src/Exceptions/InvalidRefiner.php index e947b8d..1b33420 100644 --- a/src/Exceptions/InvalidRefiner.php +++ b/src/Exceptions/InvalidRefiner.php @@ -8,16 +8,13 @@ class InvalidRefiner extends Exception { - public static function from( - DataRefiner $refiner, - PropertyContext $property - ): self { + protected const int EMPTY_TYPE_CONTEXTS_CODE = 1; + + public static function emptyTypeContexts(): self + { return new self( - sprintf( - 'Refiner %s is not applicable to property %s', - get_class($refiner), - $property->propertyName - ) + 'Property does not have any type contexts', + self::EMPTY_TYPE_CONTEXTS_CODE ); } } diff --git a/src/Exceptions/SerializeException.php b/src/Exceptions/SerializeException.php index b2ca7ee..16ed5d0 100644 --- a/src/Exceptions/SerializeException.php +++ b/src/Exceptions/SerializeException.php @@ -7,14 +7,60 @@ class SerializeException extends Exception { - public const int GENERIC_ERROR_CODE = 0; - public const int NO_SERIALIZERS_ERROR_CODE = 1; - - public function __construct( - string $message = "", - int $code = 0, - ?Throwable $previous = null - ) { - parent::__construct($message, $code, $previous); + protected const int GENERIC_ERROR_CODE = 0; + protected const int NO_SERIALIZERS_ERROR_CODE = 1; + protected const int UNABLE_TO_SERIALIZE_SCALAR_TYPE_ITEM_ERROR_CODE = 2; + protected const int UNABLE_TO_SERIALIZE_BACKED_ENUM_ERROR_CODE = 3; + protected const int UNABLE_TO_SERIALIZE_DATE_TIME_ITEM_ERROR_CODE = 4; + protected const int UNABLE_TO_SERIALIZE_DATA_ITEM_ERROR_CODE = 5; + protected const int UNABLE_TO_SERIALIZE_ARRAY_ITEM_ERROR_CODE = 6; + + public static function generic(?Throwable $throwable = null): self + { + return new self( + message: 'An error occurred while serializing data', + code: self::GENERIC_ERROR_CODE, + previous: $throwable + ); + } + + public static function unableToSerializeScalarTypeItem(): self + { + return new self( + message: 'Could not serialize scalar type item', + code: self::UNABLE_TO_SERIALIZE_SCALAR_TYPE_ITEM_ERROR_CODE + ); + } + + public static function unableToSerializeBackedEnumItem(): self + { + return new self( + message: 'Could not serialize array of BackedEnum items', + code: self::UNABLE_TO_SERIALIZE_BACKED_ENUM_ERROR_CODE + ); + } + + public static function unableToSerializeDateTimeItem(): self + { + return new self( + message: 'Could not serialize array of DateTime items', + code: self::UNABLE_TO_SERIALIZE_DATE_TIME_ITEM_ERROR_CODE + ); + } + + public static function unableToSerializeDataItem(): self + { + return new self( + message: 'Could not serialize array of data items', + code: self::UNABLE_TO_SERIALIZE_DATA_ITEM_ERROR_CODE + ); + } + + public static function unableToSerializeArrayItem(): self + { + return new self( + message: 'Could not serialize array of items', + code: self::UNABLE_TO_SERIALIZE_ARRAY_ITEM_ERROR_CODE + ); } } diff --git a/src/Serializers/ArraySerializer.php b/src/Serializers/ArraySerializer.php index 263d799..0c9c148 100644 --- a/src/Serializers/ArraySerializer.php +++ b/src/Serializers/ArraySerializer.php @@ -2,12 +2,12 @@ namespace Nuxtifyts\PhpDto\Serializers; +use Exception; use Nuxtifyts\PhpDto\Contexts\PropertyContext; use Nuxtifyts\PhpDto\Enums\Property\Type; -use Nuxtifyts\PhpDto\Contracts\SerializesArrayOfItems as SerializesArrayOfItemsContract; use Nuxtifyts\PhpDto\Exceptions\DeserializeException; use Nuxtifyts\PhpDto\Exceptions\SerializeException; -use Exception; +use Nuxtifyts\PhpDto\Serializers\Contracts\SerializesArrayOfItems; class ArraySerializer extends Serializer { @@ -20,6 +20,8 @@ public static function supportedTypes(): array /** * @return ?array + * + * @throws SerializeException */ protected function serializeItem(mixed $item, PropertyContext $property, object $object): ?array { @@ -32,7 +34,7 @@ protected function serializeItem(mixed $item, PropertyContext $property, object try { foreach ($typeContext->subTypeSerializers() as $serializer) { try { - if ($serializer instanceof SerializesArrayOfItemsContract) { + if ($serializer instanceof SerializesArrayOfItems) { $serializedValue = $serializer->serializeArrayOfItems($property, $object); if (array_key_exists($property->propertyName, $serializedValue)) { @@ -47,11 +49,13 @@ protected function serializeItem(mixed $item, PropertyContext $property, object } } - throw new SerializeException('Could not serialize array of items'); + throw SerializeException::unableToSerializeArrayItem(); } /** * @return ?array + * + * @throws DeserializeException */ protected function deserializeItem(mixed $item, PropertyContext $property): ?array { @@ -60,7 +64,7 @@ protected function deserializeItem(mixed $item, PropertyContext $property): ?arr try { foreach ($typeContext->subTypeSerializers() as $serializer) { try { - if ($serializer instanceof SerializesArrayOfItemsContract) { + if ($serializer instanceof SerializesArrayOfItems) { // @phpstan-ignore-next-line return $serializer->deserializeArrayOfItems($property, $item); } @@ -74,6 +78,6 @@ protected function deserializeItem(mixed $item, PropertyContext $property): ?arr return is_null($item) && $property->isNullable ? null - : throw new DeserializeException('Property is not nullable'); + : throw DeserializeException::unableToDeserializeArrayItem(); } } diff --git a/src/Serializers/BackedEnumSerializer.php b/src/Serializers/BackedEnumSerializer.php index 99fd631..e653cb3 100644 --- a/src/Serializers/BackedEnumSerializer.php +++ b/src/Serializers/BackedEnumSerializer.php @@ -5,11 +5,11 @@ use BackedEnum; use Exception; use Nuxtifyts\PhpDto\Contexts\PropertyContext; -use Nuxtifyts\PhpDto\Contracts\SerializesArrayOfItems as SerializesArrayOfItemsContract; -use Nuxtifyts\PhpDto\Concerns\SerializesArrayOfItems; use Nuxtifyts\PhpDto\Enums\Property\Type; use Nuxtifyts\PhpDto\Exceptions\DeserializeException; use Nuxtifyts\PhpDto\Exceptions\SerializeException; +use Nuxtifyts\PhpDto\Serializers\Concerns\SerializesArrayOfItems; +use Nuxtifyts\PhpDto\Serializers\Contracts\SerializesArrayOfItems as SerializesArrayOfItemsContract; class BackedEnumSerializer extends Serializer implements SerializesArrayOfItemsContract { @@ -30,7 +30,7 @@ protected function serializeItem(mixed $item, PropertyContext $property, object return match(true) { is_null($item) && $property->isNullable => null, $item instanceof BackedEnum => $item->value, - default => throw new SerializeException('Could not serialize array of BackedEnum items') + default => throw SerializeException::unableToSerializeScalarTypeItem() }; } @@ -42,7 +42,7 @@ protected function deserializeItem(mixed $item, PropertyContext $property): ?Bac if (is_null($item)) { return $property->isNullable ? null - : throw new DeserializeException('Property is not nullable'); + : throw DeserializeException::propertyIsNotNullable(); } if ( @@ -50,7 +50,7 @@ protected function deserializeItem(mixed $item, PropertyContext $property): ?Bac && !is_integer($item) && !$item instanceof BackedEnum ) { - throw new DeserializeException('Value is not a string or integer'); + throw DeserializeException::invalidValue(); } $typeContexts = $property->getFilteredTypeContexts(...self::supportedTypes()) @@ -86,6 +86,6 @@ protected function deserializeItem(mixed $item, PropertyContext $property): ?Bac // @codeCoverageIgnoreEnd } - throw new DeserializeException('Could not deserialize BackedEnum'); + throw DeserializeException::unableToDeserializeBackedEnumItem(); } } diff --git a/src/Concerns/SerializesArrayOfItems.php b/src/Serializers/Concerns/SerializesArrayOfItems.php similarity index 90% rename from src/Concerns/SerializesArrayOfItems.php rename to src/Serializers/Concerns/SerializesArrayOfItems.php index fdf765e..fc936f0 100644 --- a/src/Concerns/SerializesArrayOfItems.php +++ b/src/Serializers/Concerns/SerializesArrayOfItems.php @@ -1,6 +1,6 @@ throw new SerializeException('Could not serialize array of items') + default => throw SerializeException::unableToSerializeArrayItem() } ]; } diff --git a/src/Contracts/SerializesArrayOfItems.php b/src/Serializers/Contracts/SerializesArrayOfItems.php similarity index 93% rename from src/Contracts/SerializesArrayOfItems.php rename to src/Serializers/Contracts/SerializesArrayOfItems.php index 4e71794..adedfe5 100644 --- a/src/Contracts/SerializesArrayOfItems.php +++ b/src/Serializers/Contracts/SerializesArrayOfItems.php @@ -1,6 +1,6 @@ $item->jsonSerialize(), - default => throw new SerializeException('Could not serialize array of BaseDataContract items') + default => throw SerializeException::unableToSerializeDataItem() }; } @@ -85,6 +85,6 @@ protected function deserializeItem(mixed $item, PropertyContext $property): ?Bas return is_null($item) && $property->isNullable ? null - : throw new DeserializeException('Could not deserialize BaseDataContract'); + : throw DeserializeException::unableToDeserializeDataItem(); } } diff --git a/src/Serializers/DateTimeSerializer.php b/src/Serializers/DateTimeSerializer.php index 6b67e42..c2c75f2 100644 --- a/src/Serializers/DateTimeSerializer.php +++ b/src/Serializers/DateTimeSerializer.php @@ -7,11 +7,11 @@ use Exception; use Nuxtifyts\PhpDto\Contexts\PropertyContext; use Nuxtifyts\PhpDto\Contexts\TypeContext; -use Nuxtifyts\PhpDto\Contracts\SerializesArrayOfItems as SerializesArrayOfItemsContract; -use Nuxtifyts\PhpDto\Concerns\SerializesArrayOfItems; use Nuxtifyts\PhpDto\Enums\Property\Type; use Nuxtifyts\PhpDto\Exceptions\DeserializeException; use Nuxtifyts\PhpDto\Exceptions\SerializeException; +use Nuxtifyts\PhpDto\Serializers\Contracts\SerializesArrayOfItems as SerializesArrayOfItemsContract; +use Nuxtifyts\PhpDto\Serializers\Concerns\SerializesArrayOfItems; class DateTimeSerializer extends Serializer implements SerializesArrayOfItemsContract { @@ -34,7 +34,7 @@ protected function serializeItem(mixed $item, PropertyContext $property, object $item instanceof DateTimeInterface => $item->format(DateTimeInterface::ATOM), - default => throw new SerializeException('Value is not an instance of DateTimeInterface') + default => throw SerializeException::unableToSerializeDateTimeItem() }; } @@ -81,6 +81,6 @@ protected function deserializeItem(mixed $item, PropertyContext $property): ?Dat return is_null($item) && $property->isNullable ? null - : throw new DeserializeException('Could not deserialize DateTimeInterface'); + : throw DeserializeException::unableToDeserializeDateTimeItem(); } } diff --git a/src/Serializers/ScalarTypeSerializer.php b/src/Serializers/ScalarTypeSerializer.php index 1376193..2bed1ea 100644 --- a/src/Serializers/ScalarTypeSerializer.php +++ b/src/Serializers/ScalarTypeSerializer.php @@ -4,11 +4,11 @@ use Nuxtifyts\PhpDto\Contexts\PropertyContext; use Nuxtifyts\PhpDto\Contexts\TypeContext; -use Nuxtifyts\PhpDto\Contracts\SerializesArrayOfItems as SerializesArrayOfItemsContract; -use Nuxtifyts\PhpDto\Concerns\SerializesArrayOfItems; use Nuxtifyts\PhpDto\Enums\Property\Type; use Nuxtifyts\PhpDto\Exceptions\DeserializeException; use Nuxtifyts\PhpDto\Exceptions\SerializeException; +use Nuxtifyts\PhpDto\Serializers\Contracts\SerializesArrayOfItems as SerializesArrayOfItemsContract; +use Nuxtifyts\PhpDto\Serializers\Concerns\SerializesArrayOfItems; class ScalarTypeSerializer extends Serializer implements SerializesArrayOfItemsContract { @@ -50,7 +50,7 @@ protected function serializeItem(mixed $item, PropertyContext $property, object is_int($item), is_string($item) => $item, - default => throw new SerializeException('Could not serialize scalar type item') + default => throw SerializeException::unableToSerializeBackedEnumItem() }; } @@ -62,14 +62,14 @@ protected function deserializeItem(mixed $item, PropertyContext $property): mixe return match(true) { is_null($item) => $property->isNullable ? null - : throw new DeserializeException('Could not deserialize scalar type item'), + : throw DeserializeException::propertyIsNotNullable(), array_any( array_column(self::getScalarTypeFromProperty($property), 'value'), static fn (string $type) => settype($item, $type) ) => $item, - default => throw new DeserializeException('Could not deserialize scalar type item') + default => throw DeserializeException::unableToDeserializeScalarTypeItem() }; } } diff --git a/src/Support/Traits/HasSerializers.php b/src/Support/Traits/HasSerializers.php index 0d94c68..424534d 100644 --- a/src/Support/Traits/HasSerializers.php +++ b/src/Support/Traits/HasSerializers.php @@ -6,11 +6,11 @@ use Nuxtifyts\PhpDto\Contexts\TypeContext; use Nuxtifyts\PhpDto\Enums\Property\Type; use Nuxtifyts\PhpDto\Exceptions\UnknownTypeException; -use Nuxtifyts\PhpDto\Serializers\ArraySerializer; use Nuxtifyts\PhpDto\Serializers\BackedEnumSerializer; use Nuxtifyts\PhpDto\Serializers\DataSerializer; use Nuxtifyts\PhpDto\Serializers\DateTimeSerializer; use Nuxtifyts\PhpDto\Serializers\ScalarTypeSerializer; +use Nuxtifyts\PhpDto\Serializers\ArraySerializer; use Nuxtifyts\PhpDto\Serializers\Serializer; trait HasSerializers diff --git a/tests/Unit/Concerns/BaseDataTest.php b/tests/Unit/Concerns/BaseDataTest.php index 38f9c07..90f00ec 100644 --- a/tests/Unit/Concerns/BaseDataTest.php +++ b/tests/Unit/Concerns/BaseDataTest.php @@ -113,7 +113,7 @@ public function base_data_supports_scalar_types(): void public function will_throw_an_exception_if_an_invalid_value_is_passed_to_from_function(): void { self::expectException(DeserializeException::class); - self::expectExceptionCode(DeserializeException::INVALID_VALUE_ERROR_CODE); + self::expectExceptionCode(0); PersonData::from(false); }