News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Matt Frost:
Mocking SoapClient
December 21, 2012 @ 10:23:02

Matt Frost has shared some of his work he's done with the SoapClient in PHP and how he mocked it out for his unit tests (since it's an external resource).

The concept of mocking web services for testability took a little while to sink in for me. A big part of it was that my job doesn't see me consuming web services all that often, but I had an opportunity to give it a shot with SOAP. I found that I learned a lot more about testing in general having worked through this. I used SoapClient and wrapped it, so here's a little bit about some of things I learned. Hopefully you don't have to work with SOAP, but if you do you can test it pretty easily.

He walks through the mocking of the client itself and how he handled it's ability to translate function calls into SOAP method calls (using "__call") and how he mocked that. He also makes the suggestion that you actually wrap the SoapClient inside of another class rather than trying to mock the actual SoapClient. He also touches on the testing of exceptions that might be thrown by the service and how he tested those using his wrapper class.

0 comments voice your opinion now!
mock unittest soapclient wrapper exception function


blog comments powered by Disqus

Similar Posts

Zend Developer Zone: Accessing DB2 Data Inside of i5/OS

PHPMaster.com: Living Apart Together: Decoupling Code and Framework

php|architect: Vulcan Zend PHP Certification Mock Testing

PHPMaster.com: Bulletproofing Database Interactions with PHPUnit's Database Extension

Zend Developer Zone: Zend Framework Hidden Gems: Zend Plumbing


Community Events





Don't see your event here?
Let us know!


introduction release language community interview voicesoftheelephpant tool security package symfony podcast update framework series version install composer library laravel opinion

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework