Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctrine listeners not referencing the right services #1166

Closed
aless673 opened this issue May 11, 2020 · 5 comments
Closed

Doctrine listeners not referencing the right services #1166

aless673 opened this issue May 11, 2020 · 5 comments

Comments

@aless673
Copy link

aless673 commented May 11, 2020

Hi,

Environement test
Symfony 4.4.8
Doctrine 2.0.8

Description
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.
It implies that all injected services are also not the right ones (are they duplicated ?). Messenger transports are also impacted : transport is duplicated when coming from doctrine event

Maybe the test container is guilty ?

Symfony issue : symfony/symfony#36783

@ostrolucky
Copy link
Member

I wasn't able to reproduce this with

<?php
namespace App\EventSubscriber;

use Doctrine\Common\EventArgs;
use Doctrine\Common\EventManager;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Events;
use Psr\Container\ContainerInterface;

class Issue36783Subscriber implements EventSubscriber
{
    /**
     * @var ContainerInterface
     */
    private $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function postLoad(EventArgs $eventArgs)
    {
        var_dump($this->container->get(self::class) === $this);
    }

    public function getSubscribedEvents()
    {
        return [Events::postLoad];
    }
}

Please post failing test case, or reproducer according instructions I posted in linked issue.

@aless673
Copy link
Author

@ostrolucky Here the demo : symfony/symfony#36783 (comment)

@ostrolucky
Copy link
Member

ostrolucky commented May 28, 2020

Codeception symfony module reboots kernel by default in https://github.com/Codeception/module-symfony/blob/e60d4266644099ba2cccad9ae22cef3ceb6c0039/src/Codeception/Module/Symfony.php#L214 so you probably want to use rebootable_client option. Nothing to do with Doctrine, please raise your concerns at https://github.com/Codeception/module-symfony if you still have any

@ostrolucky
Copy link
Member

Actually using that option does not help, however this is still an issue of Symfony module, as commenting out rebootKernel call from \Codeception\Lib\Connector\Symfony::__construct causes your expected behaviour

@aless673
Copy link
Author

Not using Doctrine2 module make it works (see Codeception/Codeception#3497)

It is a solution for us as we only use Db module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants