A
A
Artem2021-05-03 15:21:55
Yii
Artem, 2021-05-03 15:21:55

How to write test case-specific definitions to a container in API tests?

Hello.

I have a set of api tests for which I want to write specific definitions for a number of classes in a dependency injection container.

The problem is that I can only do this in the context of Unit tests, but I can’t do this in API tests, because. the changes will only apply to the current process running the test, while the test sends requests to the real application with the test config. Pushing test data for some specific test case will not work, only for all at once.

Who faced this problem? If yes, how did you decide?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daria Motorina, 2021-05-03
@glaphire

Unfortunately, I did not solve such a problem, but perhaps the answer from the issue on github will do. If not, then you need to try dirty setting the environment settings for tests up to reflection in some setup/before method (if you figure out which parameters you need to change)

K
Konstantin, 2021-05-06
@kot999

If I understand the question correctly (which I'm not sure about), then this is a deployment question.
Make a separate server on which you will deploy the project with an api-test environment, which at the time of initialization will slip yii init --env api-testsanother container config needed for these tests.
well, or do a dirty hack that I personally don't like, something like

if (isset($_GET['apitests']) && $_GET['apitests'] ==true && $_SERVER['HTTP_CLIENT_IP'] == '{IP ADDR}'){
return  $devContainerConfig; 
}
return $prodContainerConfig;

which will change the configs at runtime. But this is crutchism.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question