Y
Y
yabivipil2015-11-10 16:14:24
symfony
yabivipil, 2015-11-10 16:14:24

How to write kosher unit tests in symfony2 when all logic is in controllers?

There is a small project, the essence of which is to receive and process orders. It contains about 10 classes of controllers, which describe all the business logic. Plus access is allowed only for registered users. Therefore, there are several questions about writing unit tests:
1. Is it correct to write all tests through

$client->request('GET', '/');
$client = static::createClient();

and look for matches in $crawler + correct response code?
2. Is it correct to authorize the user for each test?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-11-10
@yabivipil

unit tests are tests that test units (that is, at least some degree of isolation is implied, from complete (when everything is locked) to not very complete (if everything is not very convenient to mock)).
In the case of controller logic, your infrastructure and business logic are strongly connected, so your path is functional and integration tests. (because at this stage it will not be possible to put everything into services and isolate it in a reasonable time).
According to your points - do as you like. Well, that is, the essence of everything boils down to the fact that it would be convenient to work with your application code. Tests are a way to make it easier to make changes to your code. If it’s not convenient for you because of the tests, you need to figure out how to make it convenient (either you have something wrong with the tests or with the code, since it’s not convenient to test it).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question