Answer the question
In order to leave comments, you need to log in
How to implement a unit test of a method containing the creation of an instance of SoapClient?
Inside my own class, I use SoapClient to exchange data with an external source. To make it more convenient to test, I isolated the creation of an instance of SoapClient in the form of a separate getSoapClient method. Inside it, I create an object of the SoapClient class, passing a certain set of parameters to the constructor, including the url of the external service.
Next, in the code for writing unit tests, I mock the result of the getSoapClient method and everything turns out as it should ... The
question is how to write a unit test for the getSoapClient method itself, which actually consists of one line
. I need to check what is fed to the constructor as input exactly the url you want and the correct parameters are used for initialization...
return new SoapClient($url, $params);
On the Internet, everyone says to dig in the direction of dependency injection, but in this case it is inconvenient for me to receive a ready-made object "from outside", plus, anyway, somewhere else in the code, I will need to check its initialization parameters ...
Answer the question
In order to leave comments, you need to log in
It's a little unclear what exactly you want to test in this method.
This is a typical humble object that does not need to be covered by unit tests. The point is to make such difficult-to-test places as simple as possible and to reduce the probability of error in them to a minimum.
This code can (and preferably should) be verified by an integration or acceptance test, it is outside the scope of unit testing.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question