Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 174 lines (132 sloc) 4.675 kb
08fead5b » Yasuo Ohgaki
2002-03-05 Added README.TESTING
1 [IMPORTANT NOTICE]
2 ------------------
3 Do _not_ ask to developers why some or all tests are failed under
4 your environment! Let us know if you find why it fails. Thank you.
5
6
7 [Testing Basics]
8 --------
9 You must build CGI SAPI, then you can do "make test" to
10 execute all or some test scripts saved under
11 "tests" directory under source root directory.
12
13 Usage:
14 make test
15
16 "make test" basically executes "run-tests.php" script
17 under source root. Therefore you can execute the script
18 like
19
20 ./php -c php.ini-dist run-tests.php [ext/some_extension_name]
21
22
23
24 [Which "php" executable "make test" look for]
25 ---------------------------------------------
26 "make test" executes "run-tests.php" script with "./sapi/cli/php".
27 Although, "run-tests.php" is executed by CLI SAPI binary, test
28 scripts must be executed by CGI SAPI. Therefore, you must build
29 PHP with CGI SAPI to perform tests.
30
31 "run-tests.php" look for "php" executable in build top directory,
32 then look for search path. Therefore, if you have "php" executable
33 other than CGI SAPI in your search path or source root, tests may fail.
34
35
36
37 [Which php.ini is used]
38 -----------------------
39 "make test" force to use php.ini-dist as default config file. If
40 you would like to test with other configuration file, user
41 "run-tests.php" script.
42
43 Example:
44 ./php -c ./your_php.ini ext/standard
45
46 If you use php.ini other than php.ini-dist, you may see more
47 failed.
48
49
50 [Which test scripts are executed]
51 ---------------------------------
52 "run-tests.php" ("make test") executes all test scripts by default
53 by looking all directory named "tests". If there are files have "phpt"
54 extension, "run-tests.php" takes test php code from the file and
55 executes it.
56
57 Tester can easily executes tests selectively with as follows.
58
59 Example:
60 ./php -c php.ini-dist run-tests.php ext/mbstring
61
62
63 [Test results]
64 --------------
65 Test results are printed to standard output. If there is a failed test,
66 "run-tests.php" script saves the result, expected result and code
67 executed to the test script directory. For example, if
68 ext/myext/tests/myext.phpt is failed to pass, following files are
69 created:
70
71 ext/myext/tests/myext.out - output from test script
72 ext/myext/tests/myext.exp - expected output
73 ext/myext/tests/myext.php - test script executed
74
75 Tester can verify these files, if failed test is actually a bug
76 or not.
77
78
79 [Creating new test files]
80 -------------------------
81 Writing test file is very easy if you are used to PHP. Test file
82 has following format. Here is a actual test file from iconv module.
83
84 ===== ext/iconv/002.phpt =======
85 --TEST--
86 UCS4BE to ASCII
87 --SKIPIF--
88 <?php include('skipif.inc'); ?>
89 --POST--
90 --GET--
91 --FILE--
92 <?php include('002.inc'); ?>
93 --EXPECT--
94 &#97;&#98;&#99;&#100;
95 abcd
96 ===== end of ext/iconv/002.phpt =======
97
98 "--TEST--" is title of the test.
99 "--SKIPIF--" is condition when to skip this test.
100 "--POST--" is POST variable passed to test script.
101 "--GET--" is GET variable passed to test script.
102 "--FILE--" is the test script.
103 "--EXPECT--" is the expected output from the test script.
104
105 ext/iconv/002.phpt uses 2 files. "skipif.inc" is used to skip
106 test when test cannot be performed such as iconv module is not
107 compiled or loaded.
108
109 ==== ext/iconv/skipif.inc ====
110 <?php
111 // This script prints "skip" if condition does not meet.
112
113 if (!extension_loaded("iconv") && ini_get("enable_dl")) {
114 $dlext = (substr(PHP_OS, 0, 3) == "WIN") ? ".dll" : ".so";
115 @dl("iconv$dlext");
116 }
117 if (!extension_loaded("iconv")) {
118 die("skip\n");
119 }
120 ?>
121 ==== end of ext/iconv/skipif.inc ====
122
123 ext/inconv/002.inc is the test script. "run-tests.php" script
124 executes test script with CGI executable.
125
126 ==== ext/iconv/002.inc ===
127 <?php
128 /*
129 Expected output:
130 &#97;&#98;&#99;&#100;
131 abcd
132 */
133
134 $s = unpack("V*", iconv("ascii","UCS-4LE", "abcd"));
135 foreach($s as $c) { print "&#$c;"; } print "\n";
136
137 $s = pack("NNNN", 97, 98, 99, 100);
138 $q = iconv("UCS-4BE", "ascii", $s);
139 print $q; print "\n";
140 ?>
141 === end of ext/iconv/002.inc ===
142
143 Test script and skipif code may be directly write into *.phpt.
144 However, it is recommended to use other files for ease of writing
145 test script. For instance, you can execute test script under
146 ext/iconv as follows:
147
148 ./php -c /etc/php.ini-dist ext/iconv
149
150
151 [How to help us]
152 ----------------
153 If you find bug in PHP, you can submit bug report AND test script
154 for us. You don't have to write complete script, just give us test
155 script with following format. Please test the script and make sure
156 you write the correct ACTUAL OUTPUT and EXPECTED OUTPUT before you
157 submit.
158
159 <?php
160 /*
161 Bug #12345
162 substr() bug. Do not return expected string.
163
164 ACTUAL OUTPUT
165 XYXA
166
167 EXPECTED OUTPUT
168 ABCD
169 */
170
171 $str = "XYZABCD";
172 echo substr($str,3,7);
173
174 ?>
Something went wrong with that request. Please try again.