How to output in CLI during execution of PHP Unit tests?

UPDATE Just realized another way to do this that works much better than the –verbose command line option: class TestSomething extends PHPUnit_Framework_TestCase { function testSomething() { $myDebugVar = array(1, 2, 3); fwrite(STDERR, print_r($myDebugVar, TRUE)); } } This lets you dump anything to your console at any time without all the unwanted output that comes along … Read more

Run PHPUnit Tests in Certain Order

PHPUnit supports test dependencies via the @depends annotation. Here is an example from the documentation where tests will be run in an order that satisfies dependencies, with each dependent test passing an argument to the next: class StackTest extends PHPUnit_Framework_TestCase { public function testEmpty() { $stack = array(); $this->assertEmpty($stack); return $stack; } /** * @depends … Read more

How to install an older version of PHPUnit through PEAR?

You need to know the exact version number you wish to downgrade to. At the time of writing, the last release you’re after is 3.3.17, which can be found out by checking the appropriate PEAR channel. To downgrade to that particular version execute two commands: pear uninstall phpunit/PHPUnit pear install phpunit/PHPUnit-3.3.17

How to run a specific phpunit xml testsuite?

Here’s the code as if PHPUnit 3.7.13 $ phpunit –configuration config.xml –testsuite Library $ phpunit –configuration config.xml –testsuite XXX_Form If you want to run a group of the test suites then you can do this <testsuites> <testsuite name=”Library”> <directory>library</directory> </testsuite> <testsuite name=”XXX_Form”> <file>library/XXX/FormTest.php</file> <directory>library/XXX/Form</directory> </testsuite> <testsuite name=”Both”> <directory>library</directory> <file>library/XXX/FormTest.php</file> <directory>library/XXX/Form</directory> </testsuite> </testsuites> Then $ phpunit … Read more

Test PHP headers with PHPUnit

The issue is that PHPUnit will print a header to the screen and at that point you can’t add more headers. The work around is to run the test in an isolated process. Here is an example <?php class FooTest extends PHPUnit_Framework_TestCase { /** * @runInSeparateProcess */ public function testBar() { header(‘Location : http://foo.com’); } … Read more