skip to Main Content

ideally for my project I need to store time only in the database (doctrine type="time_immutable"). However it causes issues with phpunit and I cant find any working solution.

When I try to mock time only got this error:

PDOException: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '09:00:00' for column 'start_time' at row 1

When mock datetime got this error:

Could not convert database value "1970-01-01 09:00:00" to Doctrine Type time_immutable. Expected format: H:i:s

It works fine when I do actual API call, so seems like issue with phpunit only. When I change doctrine column type to datetimetz_immutable and mock datetime it works fine for tests but obviously I have to store entire datetime when I need time only.

2

Answers


  1. Chosen as BEST ANSWER

    Eventually, I had to manually delete testing schema. I believe there was some cached issue with that schema.

    Thanks for help anyway.


  2. What you are giving to the database is a DateTime string.
    The database expects a Time string.
    Fastest way to convert is:

    date('H:i:s', strtotime($yourDateTimeString));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search