R
R
rumasterov2015-10-14 22:03:51
Yii
rumasterov, 2015-10-14 22:03:51

How to write a functional test for a function that uses an external web service?

I use yii2, I want to write functional tests. It is necessary to test the "Confirm sale" button, when clicked, a request is sent to an external web service that belongs to the provider, if the request is successful, the order status in my local database changes and the user is informed that the order was successfully confirmed.
There is a test environment for this external web service, but it can be disabled, etc. or to confirm the sale, the order must already be created in this test external web service, but at the time of running my tests with the test database, it may not be there either. It turns out I need to somehow replace this class that works with an external service? And is it ok for functional tests?
Maybe someone faced such a situation?
In my classes, I work with this external web service through the client, which is specified in the components in the config and is called like this: Yii::$app->provider->approveOrder($order);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-10-14
Protko @Fesor

1) use a test environment, reliably and simply
2) encapsulate work with the service in a separate service and replace it with a mock / stub in tests.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question