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

James Morris:
PHPUnit Mocking and Method Chaining
Jul 17, 2013 @ 17:13:02

James Morris has an interesting new post about mocking and method chaining and a discovery he made about the proper use of the "at" method in what his mock objects were expecting.

I’ve been given the task of unit testing Symfony2’s security layer, which at first seems daunting, but in reality with a clever bit of PHPUnit mocking, it’s actually quite simple. Symfony2 makes heavy use of method chaining.

He illustrates one way to create the mocks for this chain (one mock returning another) but suggests an alternative - returning an instance of "self" to keep the chain alive. He also includes a bit about the "at" matcher and how, despite what the PHPUnit documentation says, it should be correctly used to handle the response of certain methods in the chained call.

tagged: phpunit mock method chain object tutorial matcher

Link: http://blog.jmoz.co.uk/phpunit-mocking-and-method-chaining

Sebastian Bergmann's Blog:
Getting Started with Hamcrest
Jan 09, 2008 @ 16:23:00

Following up on the start of his port of the Hamcrest (a library of "matchers") functionality over to PHP, Sebastian Bergmann has posted the getting started guide to show you how to use it with the popular PHPUnit unit testing software.

There are a number of situations where matchers are invaluble, such as UI validation, or data filtering, but it is in the area of writing flexible tests that matchers are most commonly used.

His example that checks to see if one object is equal to another object. The Hamcrest matcher allows for a "assertThat" method making it easier to create and use pre-existing unit testing assertions.

He also includes a list of some of the most common matchers broken up into groups of core, logical, object, number and text.

tagged: hamcrest matcher library gettingstarted tutorial assert hamcrest matcher library gettingstarted tutorial assert

Link:

Sebastian Bergmann's Blog:
Getting Started with Hamcrest
Jan 09, 2008 @ 16:23:00

Following up on the start of his port of the Hamcrest (a library of "matchers") functionality over to PHP, Sebastian Bergmann has posted the getting started guide to show you how to use it with the popular PHPUnit unit testing software.

There are a number of situations where matchers are invaluble, such as UI validation, or data filtering, but it is in the area of writing flexible tests that matchers are most commonly used.

His example that checks to see if one object is equal to another object. The Hamcrest matcher allows for a "assertThat" method making it easier to create and use pre-existing unit testing assertions.

He also includes a list of some of the most common matchers broken up into groups of core, logical, object, number and text.

tagged: hamcrest matcher library gettingstarted tutorial assert hamcrest matcher library gettingstarted tutorial assert

Link:

Sebastian Bergmann's Blog:
Hamcrest
Jan 01, 2008 @ 20:16:00

In a new post to his blog, Sebastian Bergmann mentions a new effort he's undertaken - the porting of the Hamcrest library of matcher objects to PHP.

I have begun to port Hamcrest, which provides a library of matcher objects (also known as constraints or predicates) allowing "match" rules to be defined declaratively, to be used in other frameworks. Typical scenarios include testing frameworks, mocking libraries and UI validation rules, to PHP.

The hamcrest-php project compliments other current hamcrest-related projects and his ultimate goal is to make it available to the PHPUnit testing community (as well as with the PHPMock effort).

tagged: hamcrest phpunit matcher constraint object phpmock port hamcrest phpunit matcher constraint object phpmock port

Link:

Sebastian Bergmann's Blog:
Hamcrest
Jan 01, 2008 @ 20:16:00

In a new post to his blog, Sebastian Bergmann mentions a new effort he's undertaken - the porting of the Hamcrest library of matcher objects to PHP.

I have begun to port Hamcrest, which provides a library of matcher objects (also known as constraints or predicates) allowing "match" rules to be defined declaratively, to be used in other frameworks. Typical scenarios include testing frameworks, mocking libraries and UI validation rules, to PHP.

The hamcrest-php project compliments other current hamcrest-related projects and his ultimate goal is to make it available to the PHPUnit testing community (as well as with the PHPMock effort).

tagged: hamcrest phpunit matcher constraint object phpmock port hamcrest phpunit matcher constraint object phpmock port

Link:


Trending Topics: