26 views

CHAPTER 12 - BUILDING PACKAGES - Regression Tests

Testing involves two things:
Installing and uninstalling the package to verify that the package
scripts, if any, work and to finally test that the tarball is good
Running package regression tests with pear run-tests
This means we need to make a regression test for our HelloWorld package.
These tests use PHP’s “.phpt” format; here is an example:
–TEST–
HelloWorld test
–FILE–
<?php
include dirname(__FILE__).’/../HelloWorld.php’;
new HelloWorld(false);
new HelloWorld(true);
–EXPECT–
Hello, World!
Hello, World!<br />
The –FOO– lines mark the start of different sections. The .phpt format
defines these sections:
TEST. Title of the test.
SKIPIF. PHP code (must start with <?php) run to determine whether the test
should be executed at all. The test is skipped if this code prints skip.
FILE. PHP code that comprises the test itself.
EXPECT. The expected output of the PHP code in the FILE section.
GET. HTTP GET input variables (for example, foo=bar&ya=da, which requires
CGI binary).
POST. Raw HTTP POST data (same format as GET data), which requires CGI
binary.
The pear run-tests command looks for files with the ending “.phpt” in the
current directory, or subdirectories called “tests.”

Post a Comment

You must be logged in to post a comment.