News Feed
Sections




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

Jakub Zalas' Blog:
Mocking Symfony Container services in Behat scenarios with Mockery
January 20, 2012 @ 13:54:52

Jakub Zalas has a recent post to his blog with a hint about how to test Symfony container services by mocking them (when testing with Behat) with the help of Mockery (and the PSSMockeryBundle).

Mocking objects in unit tests is pretty straightforward as every object used in a test case is usually created in a scope of one test class. In functional tests it's a bit harder since we either don't have full control over objects being created or it's simply too laborious to mock half the framework. [...] We're getting the service from a container [in the example] and calling a method which should send a lead. The problem is we don't want to actually call an API while executing Behat scenarios.

Rather than hitting up the API for each test, he opts to create mock objects and results with the tools Mockery has to offer. He gives code for a "is API available" method that either returns a valid container or a mocked object, depending on how it was called.

0 comments voice your opinion now!
mock mockery object behat symfony api tutorial


blog comments powered by Disqus

Similar Posts

DevShed: Working with Attributes and CDATA Sections with the DOM XML Extension

FuzzyOpinions Blog: Tutorial: improving security with a PHP Captcha

phpDevelopment Blog: Zend Framework Tutorial Series: Part 3 – Login and Signup with (RE)Captcha

Brandon Savage's Blog: Five Tips To Make Good Object-Oriented Code Better

Francois Zaninotto's Blog: Validating a YAML file against a schema in PHP


Community Events

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


laravel community introduction interview opinion release unittest voicesoftheelephpant library laravel5 framework video series version api extension podcast language php7 development

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