Strange behavior of symfony doctrine during phpunit test – field becomes null in database

I am using

  • Symfony v6.4.8
  • doctrine/orm 2.19.5
  • phpunit/phpunit 9.6.19

I have build an REST API GET endpoint /api/contract/{$id} in Symfony.

It performs an API request at another system, receiving that data and combining it with local database data and creates a new record in my database.

The problem I have is at / after the persist()/flush() in the Database, that sometimes the field $contract->eup is NULL in the database.

eup is defined as nvarchar(10) in a MSSQL database.

private function saveContract(EntityManager $em, array $data): ContractData
{        
    $contract = new ContractData();
    // [... some more variables]
    $contract->setEup($data['eup']);  // example: "2024-06-29"
    
    $em->persist($contract);
    $em->flush();

    return $contract;
}

When I call my API with Postman, the record is created correctly and the eup field in the database is filled with a string.

But when I run the phpunit test php bin/phpunit --filter myTest, it calls the api, the record is created in the database, but the eup field is NULL.

  • Other fields of this record are stored correctly at the test.

  • It is also possible to write the value of this field to other fields.

  • Also tried to a shorter string, but this is also not saved.

  • I have run the test with xdebug too and can confirm (together with my colleague) that $contract->eup is set and filled with a string at $em->persist($contract); but when we look after flush at the database SELECT * FROM ... the field eup is NULL.

Do you have an idea what could be wrong?