mirror of
https://github.com/php/php-src.git
synced 2024-09-22 02:17:32 +00:00
- Moved to http://qa.php.net/write-test.php
This commit is contained in:
parent
b51b6f0fbf
commit
5eb912554d
139
README.TESTING
139
README.TESTING
@ -141,145 +141,8 @@ advised to test for non-zero, rather then a specific value.
|
||||
[Creating new test files]
|
||||
-------------------------
|
||||
Writing test file is very easy if you are used to PHP.
|
||||
See the HOWTO at http://qa.php.net/write-test.php
|
||||
|
||||
Here is an actual test file from standard module.
|
||||
|
||||
===== ext/standard/tests/strings/strtr.phpt =======
|
||||
--TEST--
|
||||
strtr() function
|
||||
--FILE--
|
||||
<?php
|
||||
/* Do not change this test it is a REATME.TESTING example. */
|
||||
$trans = array("hello"=>"hi", "hi"=>"hello", "a"=>"A", "world"=>"planet");
|
||||
var_dump(strtr("# hi all, I said hello world! #", $trans));
|
||||
?>
|
||||
--EXPECT--
|
||||
string(32) "# hello All, I sAid hi planet! #"
|
||||
===== ext/standard/tests/strings/strtr.phpt =======
|
||||
|
||||
As you can see the file is devided into several sections. Below is a
|
||||
list of all possible sections:
|
||||
|
||||
"--TEST--" is title of the test (required).
|
||||
"--SKIPIF--" is condition when to skip this test (optional).
|
||||
"--POST--" is POST variable passed to test script (optional).
|
||||
"--GET--" is GET variable passed to test script (optional).
|
||||
"--INI--" each line contains an ini setting e.g. foo=bar (optional).
|
||||
"--FILE--" is the test script (required).
|
||||
"--EXPECT--" is the expected output from the test script (required).
|
||||
"--EXPECTF--" is an alternative of --EXPECT--. The difference is that
|
||||
this form uses sscanf for output validation (alternative).
|
||||
"--EXPECTREGEX--" is an alternative of --EXPECT--. This form allows the tester
|
||||
to specify the result in a regular expression (alternative).
|
||||
|
||||
A test must at least contain the sections TEST, FILE and either EXPECT
|
||||
or EXPECTF. When a test is called run-test.php takes the name from the
|
||||
TEST section and writes the FILE section into a ".php" file with the
|
||||
same name as the ".phpt" file. This ".php" file will then be executed
|
||||
and its output compared to the contents of the EXPECT section. It is a
|
||||
good idea to generate output with var_dump() calls.
|
||||
|
||||
/ext/standard/tests/strings/str_shuffle.phpt is a good example for using
|
||||
EXPECTF instead of EXPECT. From time to time the algorithm used for shuffle
|
||||
changed and sometimes the machine used to execute the code has influence
|
||||
on the result of shuffle. But it always returns a three character string
|
||||
detectable by %s. Other scan-able forms are %i for integers, %d for numbers
|
||||
only, %f for floating point values, %c for single characters and %x for
|
||||
hexadecimal values.
|
||||
|
||||
==== /ext/standard/tests/strings/str_shuffle.phpt ===
|
||||
--TEST--
|
||||
Testing str_shuffle.
|
||||
--FILE--
|
||||
<?php
|
||||
/* Do not change this test it is a REATME.TESTING example. */
|
||||
$s = '123';
|
||||
var_dump(str_shuffle($s));
|
||||
var_dump($s);
|
||||
?>
|
||||
--EXPECTF--
|
||||
string(3) %s
|
||||
string(3) "123"
|
||||
==== end of /ext/standard/tests/strings/str_shuffle.phpt ===
|
||||
|
||||
/ext/standard/tests/strings/strings001.phpt is a good example for using
|
||||
EXPECTREGEX instead of EXPECT. This test also shows that in EXPECTREGEX
|
||||
some characters need to be escaped since otherwise they would be
|
||||
interpreted as a regular expression.
|
||||
|
||||
==== /ext/standard/tests/strings/strings001.phpt ===
|
||||
--TEST--
|
||||
Test whether strstr() and strrchr() are binary safe.
|
||||
--FILE--
|
||||
<?php
|
||||
/* Do not change this test it is a REATME.TESTING example. */
|
||||
$s = "alabala nica".chr(0)."turska panica";
|
||||
var_dump(strstr($s, "nic"));
|
||||
var_dump(strrchr($s," nic"));
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
string\(18\) \"nica\x00turska panica\"
|
||||
string\(19\) \" nica\x00turska panica\"
|
||||
==== end of /ext/standard/tests/strings/strings001.phpt ===
|
||||
|
||||
Some tests depend on modules or functions available only in certain versions
|
||||
or they even require minimum version of php or zend. These tests should be
|
||||
skipped when the requirement cannot be fullfilled. To achieve this you can
|
||||
use the SKIPIF section. To tell run-test.php that your test should be skipped
|
||||
the SKIPIF section must print out the word "skip" followed by a reason why
|
||||
the test should skip.
|
||||
|
||||
==== /ext/exif/tests/exif005.phpt ===
|
||||
--TEST--
|
||||
Check for exif_read_data, unusual IFD start
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('exif')) print 'skip exif extension not available';
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
/* Do not change this test it is a REATME.TESTING example.
|
||||
* test5.jpg is a 1*1 image that contains an Exif section with ifd = 00000009h
|
||||
*/
|
||||
$image = exif_read_data('./ext/exif/tests/test5.jpg','',true,false);
|
||||
var_dump($image['IFD0']);
|
||||
?>
|
||||
--EXPECT--
|
||||
array(2) {
|
||||
["ImageDescription"]=>
|
||||
string(11) "Ifd00000009"
|
||||
["DateTime"]=>
|
||||
string(19) "2002:10:18 20:06:00"
|
||||
}
|
||||
==== end of /ext/exif/tests/exif005.phpt ===
|
||||
|
||||
Test script and SKIPIF code should be directly written into *.phpt. However,
|
||||
it is recommended to use include files when more test scripts depend on the
|
||||
same SKIPIF code or when certain test files need the same values for some
|
||||
input. But no file used by any test should have one of the following
|
||||
extensions: ".php", ".log", ".exp", ".out" or ".diff".
|
||||
|
||||
Tests should be named according to the following list:
|
||||
|
||||
Class: Name: Example:
|
||||
Tests for bugs bug<bugid>.phpt bug17123.phpt
|
||||
Tests for functions <functionname>.phpt dba_open.phpt
|
||||
General tests for extensions <extname><no>.phpt dba3.phpt
|
||||
|
||||
When you use an include file for the SKIPIF section it should be named
|
||||
"skipif.inc" and an include file used in the FILE section of many tests
|
||||
should be named "test.inc".
|
||||
|
||||
NOTE: All tests should run correctly with error_reporting(E_ALL) and
|
||||
display_errors=1. This is the default when called from run-test.php.
|
||||
If you have a good reason for lowering the error reporting, use --INI--
|
||||
section and comment this in your testcode.
|
||||
|
||||
NOTE: If your test intentionally generates a PHP warning message use
|
||||
$php_errormsg variable, which you can then output. This will result
|
||||
in a consistent error message output across all platforms and PHP
|
||||
configurations, preventing your test from failing due inconsistencies
|
||||
in the error message content.
|
||||
|
||||
[How to help us]
|
||||
----------------
|
||||
|
Loading…
Reference in New Issue
Block a user