How to mock test a web service in PHPUnit across multiple tests?

Posted by scraton on Stack Overflow See other posts from Stack Overflow or by scraton
Published on 2010-03-16T21:47:49Z Indexed on 2010/03/16 21:51 UTC
Read the original article Hit count: 299

Filed under:
|
|
|

I am attempting to test a web service interface class using PHPUnit. Basically, this class makes calls to a SoapClient object. I am attempting to test this class in PHPUnit using the "getMockFromWsdl" method described here:

http://www.phpunit.de/manual/current/en/test-doubles.html#test-doubles.stubbing-and-mocking-web-services

However, since I want to test multiple methods from this same class, every time I setup the object, I also have to setup the mock WSDL SoapClient object. This is causing a fatal error to be thrown:

Fatal error: Cannot redeclare class xxxx in C:\web\php5\PEAR\PHPUnit\Framework\TestCase.php(1227) : eval()'d code on line 15

How can I use the same mock object across multiple tests without having to regenerate it off the WSDL each time? That seems to be the problem.

© Stack Overflow or respective owner

Related posts about phpunit

Related posts about php