PHPUnit Testing

Unit testing is a procedure to test your code to ensure that individual units of source code are working properly and that the right output is being generated. Tests can be run on all or some functions within files, meaning that tests can be conducted before the file has been fully developed. Each test case should be independent of others to ensure that test results can pinpoint the location of the error.

Running unit tests can ensure that your code is stable and functioning correctly, and can help you to diagnose errors.

Note:

PHPUnit4 is supported from Zend Studio 13.5 and above.

PHPUnit Test Cases

PHPUnit Test Cases can be created for each class within a file. Running a PHPUnit Test allows you to see which functions within the test are working correctly.

See Creating a PHPUnit Test Case and Running a PHPUnit Test Case for more information.

PHPUnit Test Suites

PHPUnit Test Suites can be created to run several PHPUnit test cases at once. See Creating a PHPUnit Test Suite and Running a PHPUnit Test Suite for more information.

Running PHPUnit Test Cases/Suites

Running a PHP Unit Test Case/Suite will result in the PHPUnit view being displayed, showing the results of the tests that were run.

Debugging PHPUnit Test Cases/Suites

Debugging a PHPUnit Test Case/Suite will result in the PHPUnit view being displayed, showing the results of the tests that were run, in addition to the normal debug functionality. This will also allow you to debug and analyze PHPUnit libraries.

Profiling PHPUnit Test Cases/Suites

Profiling a PHPUnit Test Case/Suite will result in the PHPUnit view being displayed, showing the results of the tests that were run, in addition to the normal profiling functionality. This will also allow you to profile and analyze PHPUnit libraries.

PHPUnit Reporting

Once a PHPUnit Test has been run, Zend Studio can generate a range of reports to easily view and analyze your tests.

The types of reports available are:

  • XML - Generates an XML output of your test results. This can be used to create your own reports.

  • 'plain.xsl' - Creates a report based on a predefined 'plain.xsl' format. The report shows It shows percentages, elapsed time, total tests, errors and failures. In addition it shows individual report status, message, stack trace and warnings with their stack traces.

  • 'packages.xsl' - Creates a report based on a predefined 'packages.xsl' format.  This is an extension of the plain report which divides the unit tests into 'packages'. Packages are defined by adding an "@package" annotation to the PHPDoc of test classes. Test classes without an @package annotation will be categorized in a 'default package'.

Custom XSL reports can also be generated by selecting the 'Generate with XSL...' option and selecting a previously created XSL report. These will then be added to the list of available reports.

See Reporting on PHPUnit Test Results for more information.