diff --git a/src/Internal/functions.php b/src/Internal/functions.php index d3ac97e..7ba2011 100644 --- a/src/Internal/functions.php +++ b/src/Internal/functions.php @@ -107,12 +107,12 @@ function cast(mixed $value): string|int|float|null "object" => match (true) { $value instanceof \BackedEnum => $value->value, $value instanceof \Stringable => (string) $value, - default => throw new \ValueError( + default => throw new \TypeError( "An object in parameter values must be a BackedEnum or implement Stringable; got instance of " . \get_debug_type($value) ), }, - default => throw new \ValueError(\sprintf( + default => throw new \TypeError(\sprintf( "Invalid value type '%s' in parameter values", \get_debug_type($value), )), @@ -132,7 +132,7 @@ function encodeArrayItem(mixed $value): mixed "object" => match (true) { $value instanceof \BackedEnum => encodeArrayItem($value->value), $value instanceof \Stringable => encodeArrayItem((string) $value), - default => throw new \ValueError( + default => throw new \TypeError( "An object in parameter arrays must be a BackedEnum or implement Stringable; " . "got instance of " . \get_debug_type($value) ), diff --git a/test/CastTest.php b/test/CastTest.php index dca1d0a..3a77ba2 100644 --- a/test/CastTest.php +++ b/test/CastTest.php @@ -117,7 +117,7 @@ public function testBackedEnumInArray(): void public function testUnitEnum(): void { - $this->expectException(\ValueError::class); + $this->expectException(\TypeError::class); $this->expectExceptionMessage('An object in parameter values must be'); cast(UnitEnum::Case); @@ -125,7 +125,7 @@ public function testUnitEnum(): void public function testUnitEnumInArray(): void { - $this->expectException(\ValueError::class); + $this->expectException(\TypeError::class); $this->expectExceptionMessage('An object in parameter arrays must be'); cast([UnitEnum::Case]); @@ -133,7 +133,7 @@ public function testUnitEnumInArray(): void public function testObjectWithoutToStringMethod(): void { - $this->expectException(\ValueError::class); + $this->expectException(\TypeError::class); $this->expectExceptionMessage('An object in parameter values must be'); cast(new \stdClass); @@ -141,7 +141,7 @@ public function testObjectWithoutToStringMethod(): void public function testObjectWithoutToStringMethodInArray(): void { - $this->expectException(\ValueError::class); + $this->expectException(\TypeError::class); $this->expectExceptionMessage('An object in parameter arrays must be'); cast([new \stdClass]);