core icon indicating copy to clipboard operation
core copied to clipboard

assertMatchesResourceItemJsonSchema throws "InvalidArgumentException: 0 is an invalid type for int" for int backed enum

Open ErnestoNCarrea opened this issue 2 years ago • 1 comments

API Platform version(s) affected: 3.2.1

Description
assertMatchesResourceItemJsonSchema throws JsonSchema\Exception\InvalidArgumentException: 0 is an invalid type for int when comparing against an int backed enum property.

How to reproduce Simplified example:

public Status: int { case Active = 1; case Inactive = 0; }

class Entity { #[ORM\Column()] private Status $status = Status::Active; }

Use assertMatchesResourceItemJsonSchema against a request to /api/entities/1

Possible Solution
TypeConstraint.php@278 compares $type to 'integer'. Looks like int backed enums are detected as 'int' and not 'integer'.

Additional Context
Symfony 6.3.6 PHP 8.2

ErnestoNCarrea avatar Oct 24 '23 18:10 ErnestoNCarrea

This looks to have been fixed circa 3.2.8 as my test case passed from there on.

GwendolenLynch avatar Apr 08 '24 14:04 GwendolenLynch