Skip to content

HTTPS clone URL

Subversion checkout URL

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