docs
docs copied to clipboard
DateTimeImmutable $publicationDate should be DateTime
After finishing Getting Started With API Platform: Create Your API and Your Jamstack Site and moving onto Testing the API when you run
docker-compose exec php \
bin/console hautelook:fixtures:load
You get an error
In SimpleObjectGenerator.php line 111:
An error occurred while generating the fixture "review_1" (App\Entity\Review):
Invalid value given for the property "publicationDate" of the object "review_
1" (class: App\Entity\Review).
In HydrationExceptionFactory.php line 67:
Invalid value given for the property "publicationDate" of the object "review_1
" (class: App\Entity\Review).
In PropertyAccessor.php line 522:
Cannot assign DateTime to property App\Entity\Review::$publicationDate of type
?DateTimeImmutable
This is because in Getting Started With API Platform: Create Your API and Your Jamstack Site you set the publicationDate to be DateTimeImmutable which should be DateTime
/** The publication date of this book. */
public ?\DateTimeImmutable $publicationDate = null;
and
/** The date of publication of this review.*/
public ?\DateTimeImmutable $publicationDate = null;
Should be
/** The publication date of this book. */
public ?\DateTime $publicationDate = null;
and
/** The date of publication of this review.*/
public ?\DateTime $publicationDate = null;
Couldn't we fix the fixtures instead? Using immutable datetime objects is a best practice.
Could you please suggest how the fixtures could be fixed?