I want to functional test my Symfony 4 app on a specific part using Doctrine subscribers. So i mock up my service as i mentionned it in this post : How to mock service with symfony 4 in functional tests?
But then i encoutered this problem : Doctrine subscribers (or listeners) services are not the same if fetched from container or fetched by doctrine events. If i dump the spl_object_id of a doctrine subscriber fetched from the container and the spl_object_id of the same doctrine subscriber but fired by a doctrine event (like onFlush), this is not the same id.
That implies that in my tests i cannot update my mock with some asserts, because the doctrine subscriber that i fetched is not the one used by doctrine events...
Maybe this is a specific and normal behavior of Doctrine subscribers, but if someone can explains it and suggest how to retrieve the right doctrine service instance to update it (the mock in my case)
EDIT
This is also the case for Symfony messenger transport. Transport is duplicated in doctrine subscribers
Symfony issue : https://github.com/symfony/symfony/issues/36783