Skip to content

Struggling with Service Mocking: Functional Testing in Symfony #54915

Answered by pkly
berkut1 asked this question in Q&A
Discussion options

You must be logged in to vote

I personally find that including any arguments in an entity constructor needlessly complicates everything. You also seem to use a service inside of your entity, which is not great. I would simply suggest creating your entity through a factory instead, which would give you yet another service.

As for mocking, I do something similar in a lot of our tests and I generally find that booting the container, and only booting it, should allow you to replace services. If a service cannot be replaced it means it was already used in something when the container started, which could've happened if you say, made a request in the test case.

Example from one of our WebTestCase tests below.

        parent::

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@berkut1
Comment options

@berkut1
Comment options

@pkly
Comment options

Answer selected by berkut1
@berkut1
Comment options

@berkut1
Comment options

@pkly
Comment options

@berkut1
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants