G
G
gitdev2019-05-09 16:39:53
symfony
gitdev, 2019-05-09 16:39:53

What is the correct way to write unit tests in Symfony 3 considering dependencies in the constructor?

In the service constructor to be tested, there are dependencies that are passed through DI, how to get the service along with all the dependencies?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
OnYourLips, 2019-05-09
@OnYourLips

If you are writing a unit test, then you are mocking these dependencies instead.
It is fundamentally.

E
Evgeny Samsonov, 2019-05-09
@bitniks

In a unit test, only the module itself is tested, dependencies are not tested. Therefore, instead of dependencies, you need to pass Mock objects. An instance of the class is created directly How to create Mock objects when testing phpunit can be found here https://phpunit.readthedocs.io/ru/latest/test-doub...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question