Skip to content

File Export

aiqui edited this page May 16, 2014 · 20 revisions

This is a tutorial for using the FileExport PHPUnit extension.

Comparing large data elements

Unit testing can be painful. Building robust tests is time consuming, particularly when looking at large data structures. If only there was some way to automate the building of assert statements. This extension may help you. Rather than trying to break apart a large object or array, you can simply make the call:

$this->assertExportCompare($whatever);

This will compare the var_export of the element against a previously saved file.

Initial configuration

To use the file export class, extend the abstract class:

require_once('YOUR-PATH/PHPUnit/Extensions/FileExport/FileExportCompare.php')
class Example_uut extends PHPUnit_FileExport_TestCase {
}

How to save your exported elements

There are two command-line options for saving the export files:

  • --save-exports - save the export files for one method
  • --save-all-exports - save all the export files for all methods

It's recommended that you use --save-exports so that you can carefully compare you results. Saving all the exports at one time could allow you to overlook any issues.

When you

Clone this wiki locally