News Feed
Sections




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

Qafoo.com:
Practical PHPUnit Testing XML generation
September 17, 2010 @ 13:51:02

On the Qafoo blog today there's a new post from Tobias Schlitt about a method you can use to unit test methods that generate XML without messing with a lot of extra overhead just to test the results.

Testing classes which generate XML can be a cumbersome work. At least, if you don't know the right tricks to make your life easier. In this article, I will throw some light upon different approaches and show you, how XML generation can be tested quite easily using XPath.

He includes a sample class, qaPersonVisitor, that has methods inside it to create a simple XML documents based on the first and last name data into a DOM element. He sets up the basic test case that creates a simple person - including gender and date of birth - and offer a few different suggestions on handling the check (in PHPUnit tests):

  • the naive way of rebuilding the DOM object and assert that they are equal
  • testing the resulting XML from the DOM object against a pre-generated XML document
  • matching the contents via CSS selectors
  • using the tag matching assertions
  • using XPath in a custom assertion (with short and long uses of it included)
0 comments voice your opinion now!
unittest phpunit xml generation xpath dom


blog comments powered by Disqus

Similar Posts

Mike Purcell's Blog: PHPUnit - Upgrade - Convert assertType to assertInternalType

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

WebReference.com: XML and PHP Simplified - XML,PHP and the Database

Matthias Noback: Test Symfony2 commands using the Process component and asynchronous assertions

Matthew Weier O'Phinney's Blog: Setting up your Zend_Test test suites


Community Events





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


symfony package interview language podcast community bugfix install api library tips introduction opinion list laravel framework series deployment release voicesoftheelephpant

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