8000 Difference between parameter injection and access to `getContainer` · Issue #148 · Behat/Symfony2Extension · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.
This repository was archived by the owner on Apr 29, 2025. It is now read-only.
Difference between parameter injection and access to getContainer #148
@jdeniau

Description

@jdeniau

Hi,

I just discover a small difference between access getContainer from the KernelDictionary::getContainer().

If I understand correctly, the kernel is rebooted after each scenario or if we call an http request from symfony framework client.

This mean that all services are reinitialized, and particularly doctrine entity managers.

But's that is not really the recommended way of doing this in Symfony 3+ (private services, autowiring, etc.).

On the other hand, if we do inject doctrine as a parameter in behat.yml like this :

default:
  suites:
    default:
      contexts:
        - Mapado\TicketingBundle\Tests\Context\TransactionContext:             
          - '@doctrine.orm.default_entity_manager'

Then the instance of entity manager is not reinitialized when the kernel is rebooted (and thus the unit of work is not "cleared").

I made a "patch" with a context that clear every unit of work after each step, but it's a bit weird, and other users may have similar bugs.

  1. What is the way you recommend about that ?
  2. Is there something we can do in this bundle to prevent that kind of bug ? (maybe re-initialize every contexts after each scenario / steps 5BD6 ?)
  3. May I help with an implementation or does it have to wait after Enable Symfony DI autowiring #128 is resolved ?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0