简体   繁体   中英

Doctrine2 orderBy in Symfony4 UnitTest

I'm having an issue in Symfony when it comes to test my API. I want to get a field and its values that I insert with an orderBy in my DQL. I'm using a getSingleResult to get the result.

When I get it in Postman, the orderBy is functionnal. When I try to get it in my console running php bin/phpUnit, the orderBy is inefficient. If I replace getSingleResult by getArrayResult, it works but I don't have an object and that's not what I want.

Is there someone who know's about a problem like this one ?

I found the answer : when I'm testing my API I'm adding the entity, then I try to get it, but the collection in the parent entity is kept in cache. The fact is Doctrine needs to know that in this particular case the entity must be refreshed so I told my entity manager to use the HINT_REFRESH. Now it's working just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM