I created fixtures with fakerphp to generate fake birth date but can't load fixtures files and getting this error message : Could not convert PHP value '1970-01-01' to type date. Expected one of the following types: null, DateTime. Do you have an idea what I should modify please ?
Here is part of my php entity file code :
/**
* @ORM\Column(type="date")
*/
private $birthDate;
public function getId(): ?int
{
return $this->id;
}
public function getEmailAddress(): ?string
{
return $this->emailAddress;
}
public function setEmailAddress(string $emailAddress): self
{
$this->emailAddress = $emailAddress;
return $this;
}
public function getBirthDate(): ?string
{
return $this->birthDate;
}
public function setBirthDate(string $birthDate): self
{
$this->birthDate = $birthDate;
return $this;
}
And my fixture :
public function load(ObjectManager $manager):void
{
$faker = Factory::create(('fr_FR'));
$faker->seed(1234);
for ($i = 0; $i <= 20; $i ) {
$member = new Member();
$member->setEmailAddress('[email protected]');
$member->setFirstName($faker->firstName());
$member->setLastName($faker->lastName());
$member->setbirthDate($faker->date($format ='Y-m-d', $max = '2004-31-12'));
$member->setPostalAddress($faker->address());
$password = $this->encoder->encodePassword($member, 'password');
$member->setPassword($password);
}
$manager->persist($member);
$manager->flush();
}
}
CodePudding user response:
birthDate type is 'date' and in your setter you give a String
you have to change your setter to this -> setBirthDate(\DateTimeInterface $birthDate){}