Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test Webservices with PHPUnit?

I neet to test a couple of SOAP webservices. What types of tests can I run?

like image 878
powtac Avatar asked Feb 27 '23 21:02

powtac


1 Answers

It is by far better to test the local consumer classes with mocks of the SoapClient that return pre-recorded result XML, since Unit-Tests are meant to run fast and be independant from remote services.

  • Create a Mock class of your Client class (you should have an object wrapper for the SoapClient to be able to test it thoroughly)
  • Use $this->returnValue() to return pre-recorded XML responses or headers that your system expects

See: http://www.phpunit.de/manual/current/en/test-doubles.html

If your system is dependant on the availability of those remote services, you could implement a watchdog service that checks if the ressource is available, but this is not something that should be done in the Unit-Tests themselves.

Kind regards, Thomas

like image 126
Thomas Ploch Avatar answered Mar 05 '23 17:03

Thomas Ploch