News Feed
Sections




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

SitePoint PHP Blog:
Unit Testing with GuzzlePHP
May 16, 2014 @ 11:56:46

The SitePoint PHP site has a new tutorial posted today showing how, if you're using the Guzzle PHP HTTP client, to work with it in your unit testing. He focuses on PHPUnit testing, but the concepts could be applied in other testing tools as well.

In this tutorial, I want to show you how to use Guzzle from a different perspective, specifically how to do unit testing with it. To do this, we're going to look at three specific approaches: hand crafting custom responses, using a ServiceClient with mock response files and enqueueing a Server with mock responses.

Matthew helps you get started by installing Guzzle and PHPUnit via Composer, including the "composer.json" contents you'll need. He shows you how to get PHPUnit all set up and how to create a first simple test that extends the "GuzzleTestCase" class. He then gets into the custom hand-crafted responses, showing how to push the contents of a text file into the client response. Next up he shows how to use the ServiceClient to create the same setup only simpler. Finally, he looks at the queue handling (via a small node.js background server) where the client passes requests and is returned the same mock body content. Code examples of both the requests and the PHPUnit tests are included through out the tutorial.

0 comments voice your opinion now!
unittest guzzlephp http client tutorial phpunit

Link: http://www.sitepoint.com/unit-testing-guzzlephp

blog comments powered by Disqus

Similar Posts

Zend Developer Zone: 2 Beginners Guides I Wish I had when I Started with PHP

Rob Morgan's Blog: Howto Log Directly to Your OS X Terminal using Zend Framework and NodeJS

Matt Williams' Blog: Implementing oAuth Twitter with CodeIgniter

Federico Cargnelutti's Blog: Building a RESTful Web API with PHP and Apify

NetTuts.com: Accepting Payments with GoCardless


Community Events





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


tips zendserver list development framework community api release laravel interview code language series conference podcast introduction threedevsandamaybe deployment bugfix symfony

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