Chapter 9. Testing

Table of Contents

1. The PHPUnit Test Tool
Installing PHPUnit
2. Running Tests
All Automated Tests
A Single Test Suite
All Automated Tests
REST On-Network Tests

The How To Test Guide.

1. The PHPUnit Test Tool

This project uses pear package PHPUnit to run the unit tests. See the PHPUnit web site [PHPUNIT-DE] for more details on how to use it.

Installing PHPUnit

 pear channel-discover pear.phpunit.de
 pear install phpunit/PHPUnit

2. Running Tests

All Automated Tests

By all tests we mean, all tests that don't need require connection.

 cd tests
 phpunit --verbose AllTests

A Single Test Suite

The test suites are in the tests directory and have names ending with Test.php by convention.

 cd tests
 phpunit FileIWantToTest.php

All Automated Tests

By all tests we mean, all tests that don't need require connection.

 cd tests
 phpunit --verbose AllTests

REST On-Network Tests

The network test requires an Apache setup on a server with doc patch pointing to the distribution files. Because of this, it is not a part of the larger test suite. The test is identical to tests/restNarutoTest.php except in this test a real network connection is used.

  • Determine your URL path to tests/testRestServer.php on the server. It should be something like http://localhost/naruto/tests/testRestServer.php. Try it in your browser.

  • On the client machine, set the environment variable SERVICE_URL to that url.

     export SERVICE_URL=http://localhost/naruto/tests/testRestServer.php
  • Run the test tests/restNarutoNetTest.php using php unit.

     cd tests
     phpunit restNarutoNetTest.php