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

Chris Hartjes' Blog:
Testing Form Posts in Zend Framework
Sep 23, 2010 @ 15:36:42

In a new post to his blog today Chris Hartjes talks about the trials and tribulations he had when trying to test POST requests in his Zend Framework application with Zend_Test/PHPUnit.

I had done a refactoring of the way a model was pulling in stats for running backs and receivers for a fantasy game. As a result, in production (you suck Chris) you could not see results for those players. The data was there, I had not properly tested things. A familiar situation. So, I fixed the code and wrote my more-specific-than-before unit tests, but I decided I also wanted to make sure that the output on the page itself worked correctly. This began the descent into madness.

He found several examples of ways to test POST requests but none of them worked in his situation. They used an object chaining method that just didn't cooperate for him, so he figured out another way. The code for it's included in the post - it uses the getRequest method to set up and send the POST request.

tagged: zendframework post request getrequest unittest zendtest phpunit

Link:

Till Klampaeckel's Blog:
Debugging Zend_Test
Sep 22, 2010 @ 13:10:04

In a new post to his blog Till Klampaeckel looks at unit testing in a real life example he had when working with the Zend Framework's Zend_Test component.

If I have to spend too much time debugging a test it's usually a bad test. Which usually means that it's too complex. However, with Zend_Test_PHPUnit_ControllerTestCase, it's often not the actual test, but the framework. This is not just tedious for myself, it's also not the most supportive fact when I ask my developers to write tests. [...] The [details about the error] are especially tricky and drive me nuts on a regular basis because a unit test should never withhold these things from you. After all, we use these tests to catch bugs to begin with. Why make it harder for the developer fix them?

In his example he has a controller that validates API requests before the routing gets too far (preDispatch) and responds with a 401 HTTP code if they can't use it. His test, however, just fails and doesn't give any feedback on what happened over than "it's broken". To remedy the situation he uses something he's created, a Listener, that can be used as a part of the PHPUnit configuration and gives the output of the test including headers, HTTP response code and the body of the response - a much handier result.

tagged: zendtest zendframework

Link:

Web Builder Zone:
Zend_Test for Acceptance TDD
May 25, 2010 @ 14:29:51

On the Web Builder Zone (of DZone) Giorgio Sironi has posted an article looking at the Zend_Test component of the Zend Framework and how to use it for acceptance test-driven development.

Acceptance Test-Driven Development is an Agile technique that extends the test-first approach to the development of the front end of an application. The mechanics of Acceptance TDD are clear: first you write a test which defines the goal of your development, which is basically the feature you're adding to your application. As with all TDD variants, this test must fail.

With the help of the Zend_Test component, your tests can execute through the full MVC stact of your application (including views) to check to see if the resulting content matches certain criteria. He includes a few code examples showing content searching (contains), validating the query string and checking for a redirect.

tagged: zendtest acceptance testdriven development tdd zendframework

Link:

Blue Parabola Blog:
Getting Started with Zend_Test
Jan 12, 2010 @ 20:12:41

On the Blue Parabola blog today there's a look at working with the Zend_Test component of the Zend Framework (from Matthew Turland).

I went to the "tests" directory generated for me by the zf CLI utility to get started. What I found there was three files: application/bootstrap.php, library/bootstrap.php, phpunit.xml They were all completely empty, which didn't really provide much in the way of guidance on how to get started. The Zend_Test documentation is good, but was a bit lacking in that area as well; it really only covers how Zend_Test extends the capabilities of PHPUnit.

Matthew walks you through his process of creating a sample PHPUnit XML configuration file (with a little help), updating your bootstrap to load in paths to the test files and the creation of a sample test case for a MySQL database. He runs a test on the database to compare it to a standardized data set based on an XML file (seed.xml). He also looks briefly at testing controllers, some sample code included for this as well.

tagged: zendtest unittest phpunit mysql zendframework

Link:

Content with Style Blog:
Unit testing controllers with Zend Framework
Apr 14, 2009 @ 12:53:41

On the Content with Style blog Pascal has posted a new entry about testing your Zend Framework controllers with a combination of Zend_Test and the popular PHP unit testing software PHPUnit.

Unit testing your Zend Framework driven MVC applications is not hard at all. This post tries to give a brief overview on how to test your Controllers with Zend_Test.

There's only a few steps in his process - install PHPUnit, make a sample application to test (complete with controllers), run a test action against it and how to test the results of both normal posted values/a redirect and data manipulation in models.

tagged: zendframework test unittest phpunit zendtest controller

Link:

Till's Blog:
Avoiding common pitfalls with Zend_Test
Mar 31, 2009 @ 15:23:13

Till has recently made a post to his blog looking to help other developers avoid some of the common issues that he's seen with the Zend_Test component of the Zend Framework.

I feel like I've wasted a great deal of time last week with basics that were nowhere to be found or required debugging to no end. The following is the outcome, a rather random list of things to watch out for when you're starting on Zend_Test.

He has notes on a few different topics like debugging, environment control, crating an AllTests file, avoiding direct calls to PHP and bootstrapping correctly. A knowledge of PHPUnit and unit testing is recommended.

tagged: untitest zendtest zendframework component common problem

Link:

Matthew Weier O'Phinney's Blog:
Setting up your Zend_Test test suites
Sep 15, 2008 @ 12:58:11

In a new post to his blog Matthew Weier O'Phinney talks about using the Zend_Test component of the Zend Framework to set up test suites on your application.

Testing and test automation should be easy and the complex approach is overkill for most of our applications. Fortunately, PHPUnit offers some other methods that make doing so relatively simple. The easiest method is to use an XML configuration file.

He includes a basic XML config file for a "My Test Suite" setup defining the application's directory and where to log the end report to. This simple PHPUnit configuration can be used with the "phpunit" command line binary to auto-configure all you'll need for the testing. Matthew also includes the code for a sample TestHelper you can drop right into the app to help set up your environment correctly when testing is needed.

tagged: zendtest zendframework test unittest phpunit suite

Link:


Trending Topics: