We have a very strane behaviour here, we have this class:
class NotificationDispatcherSpy implements NotificationDispatcherInterface
{
/** @var Message[] */
private $calls = [];
public function dispatch(Message $message)
{
$this->calls[] = $message;
}
/**
* @return Message[]
*/
public function getCalls(): array
{
return $this->calls;
}
}
And it's injected both in Symfony and in a Behat context. Symfony makes the dispatch calls and then the context check for them with getCalls.
If the test that checks for the calls runs the first in the feature file, the calls are recorded as the spy is the same instance both for Symfony and Behat context.
If the test that uses the spy is not the first to run, the instance of the spy class that Symfony gets and the instance the Behat context gets are different and obviously the test fails because there are no recorded calls.
I've tried to debug the issue with no success, can anyone think of the reason?
Thanks
We have a very strane behaviour here, we have this class:
And it's injected both in Symfony and in a Behat context. Symfony makes the
dispatch
calls and then the context check for them withgetCalls
.If the test that checks for the calls runs the first in the feature file, the calls are recorded as the spy is the same instance both for Symfony and Behat context.
If the test that uses the spy is not the first to run, the instance of the spy class that Symfony gets and the instance the Behat context gets are different and obviously the test fails because there are no recorded calls.
I've tried to debug the issue with no success, can anyone think of the reason? Thanks