-
Notifications
You must be signed in to change notification settings - Fork 41
/
phpt_details.php
998 lines (941 loc) · 36.6 KB
/
phpt_details.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
<?php
include("include/functions.php");
$TITLE = "PHPT Test File Layout [PHP-QAT: Quality Assurance Team]";
$SITE_UPDATE = date("D M d H:i:s Y T", filectime(__FILE__));
common_header();
?>
<div style="padding: 10px">
<h1>PHPT - Test File Layout.</h1>
<p>Below is a reference manual for PHPT test file layouts.</p>
<dl>
<dt>Section Summary List.</dt>
<dd>
<p>[] indicates optional sections.</p>
<p><a href="#test_section">--TEST--</a><br/>
[<a href="#description_section">--DESCRIPTION--</a>]<br/>
[<a href="#credits_section">--CREDITS--</a>]<br/>
[<a href="#skipif_section">--SKIPIF--</a>]<br/>
[<a href="#conflicts_section">--CONFLICTS--</a>]<br/>
[<a href="#whitespace_sensitive_section">--WHITESPACE_SENSITIVE--</a>]<br/>
[<a href="#capture_stdio_section">--CAPTURE_STDIO--</a>]<br/>
[<a href="#extensions_section">--EXTENSIONS--</a>]<br/>
[<a href="#post_section">--POST--</a> | <a href="#put_section">--PUT--</a> | <a href="#post_raw_section">--POST_RAW--</a> | <a href="#gzip_post_section">--GZIP_POST--</a> | <a href="#deflate_post_section">--DEFLATE_POST--</a> | <a href="#get_section">--GET--</a>]<br/>
[<a href="#cookie_section">--COOKIE--</a>]<br/>
[<a href="#stdin_section">--STDIN--</a>]<br/>
[<a href="#ini_section">--INI--</a>]<br/>
[<a href="#args_section">--ARGS--</a>]<br/>
[<a href="#env_section">--ENV--</a>]<br/>
[<a href="#phpdbg_section">--PHPDBG--</a>]<br/>
<a href="#file_section">--FILE--</a> | <a href="#fileeof_section">--FILEEOF--</a> | <a href="#file_external_section">--FILE_EXTERNAL--</a> | <a href="#redirecttest_section">--REDIRECTTEST--</a><br/>
[<a href="#cgi_section">--CGI--</a>]<br/>
[<a href="#xfail_section">--XFAIL--</a>]<br/>
[<a href="#flaky_section">--FLAKY--</a>]<br/>
[<a href="#expectheaders_section">--EXPECTHEADERS</a>--]<br/>
<a href="#expect_section">--EXPECT--</a> | <a href="#expectf_section">--EXPECTF--</a> | <a href="#expectregex_section">--EXPECTREGEX--</a>
| <a href="#expect_external_section">--EXPECT_EXTERNAL--</a> | <a href="#expectf_external_section">--EXPECTF_EXTERNAL--</a> | <a href="#expectregex_external_section">--EXPECTREGEX_EXTERNAL--</a>
<br/>
[<a href="#clean_section">--CLEAN--</a>]
</dd>
<dt id="test_section">--TEST--</dt>
<dd>
<p><b>Description:</b><br/>
Title of test as a single line short description.</p>
<p><b>Required:</b><br/>
Yes</p>
<p><b>Format:</b><br/>
Plain text. We recommend a single line only.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--TEST--
Test filter_input() with GET and POST data.</pre>
</p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample001.php">sample001.phpt</a></p>
</dd>
<dt id="description_section">--DESCRIPTION--</dt>
<dd>
<p><b>Description:</b><br/>
If your test requires more than a single line title to adequately describe it,
you can use this section for further explanation. Multiple lines are allowed and
besides being used for information, this section is completely ignored by the
test binary.</p>
<p><b>Required:</b><br/>
No</p>
<p><b>Format:</b><br/>
Plain text, multiple lines.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--DESCRIPTION--
This test covers both valid and invalid usages of
filter_input() with INPUT_GET and INPUT_POST data
and several differnet filter sanitizers.</pre>
</p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample001.php">sample001.phpt</a></p>
</dd>
<dt id="credits_section">--CREDITS--</dt>
<dd>
<p><b>Description:</b><br/>
Used to credit contributors without CVS commit rights, who put their name and email on the first line.
If the test was part of a TestFest event, then # followed by the name of the event
and the date (YYYY-MM-DD) on the second line.</p>
<p><b>Required:</b><br/>
No. For newly created tests this section should no longer be included, as test authorship is already
accurately tracked by Git. If multiple authors should be credited, the `Co-authored-by` tag in the
commit message may be used.</p>
<p><b>Format:</b><br/>
Name Email<br/>
[Event]</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--CREDITS--
Felipe Pena <[email protected]></pre>
</p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample001.php">sample001.phpt</a></p>
<p><b>Example 2 (snippet):</b><br/>
<pre>--CREDITS--
Zoe Slattery [email protected]
# TestFest Munich 2009-05-19</pre>
</p>
<p><b>Example 2 (full):</b> <a href="sample_tests/sample002.php">sample002.phpt</a></p>
</dd>
<dt id="skipif_section">--SKIPIF--</dt>
<dd>
<p><b>Description:</b><br/>
A condition or set of conditions used to determine if a test should be skipped.
Tests that are only applicable to a certain platform, extension or PHP version
are good reasons for using a --SKIPIF-- section.</p>
<p>A common practice for extension tests is to write your --SKIPIF-- extension
criteria into a file call skipif.inc and then including that file in the
--SKIPIF-- section of all your extension tests. This promotes the DRY principle
and reduces future code maintenance.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Format:</b><br/>
PHP code enclosed by PHP tags. If the output of this scripts starts with "skip",
the test is skipped. If the output starts with "xfail", the test is marked as
<a href="#xfail_section">expected failure</a>. If the output starts with "flaky",
the test is marked as <a href="#flaky_section">flaky test</a>.
The "xfail" convention is supported as of PHP 7.2.0.
The "flaky" convention is supported as of PHP 8.2.25 and PHP 8.3.13, respectively.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--SKIPIF--
<?php if (!extension_loaded("filter")) die("Skipped: filter extension required."); ?></pre>
</p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample001.php">sample001.phpt</a></p>
<p><b>Example 2 (snippet):</b><br/>
<pre>--SKIPIF--
<?php include('skipif.inc'); ?></pre>
</p>
<p><b>Example 2 (full):</b> <a href="sample_tests/sample003.php">sample003.phpt</a></p>
<p><b>Example 3 (snippet):</b><br/>
<pre>--SKIPIF--
<?php if (getenv('SKIP_ASAN')) die('xfail Startup failure leak'); ?></pre>
</p>
<p><b>Example 3 (full):</b> <a href="sample_tests/xfailif.php">xfailif.phpt</a></p>
<p><b>Example 4 (snippet):</b><br/>
<pre>--SKIPIF--
<?php
if (getenv("GITHUB_ACTIONS") && PHP_OS_FAMILY === "Darwin") {
die("flaky Occasionally segfaults on macOS for unknown reasons");
}
>></pre>
</p>
<p><b>Example 4 (full):</b> <a href="sample_tests/flakyif.php">flakyif.phpt</a></p>
</dd>
<dt id="conflicts_section">--CONFLICTS--</dt>
<dd>
<p><b>Description:</b><br/>
<p>This section is only relevant for parallel test execution (available as of
PHP 7.4.0), and allows to specify conflict keys. While a test that conflicts
with key K is running, no other test that conflicts with K is run.
For tests conflicting with "all", no other tests are run in parallel.</p>
<p>An alternative to have a --CONFLICTS-- section is to add a file named
CONFLICTS to the directory containing the tests. The contents of the CONFLICTS
file must have the same format as the contents of the --CONFLICTS-- section.
</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Format:</b><br/>
One conflict key per line. Comment lines starting with # are also allowed.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--CONFLICTS--
server</pre>
</p>
<p><b>Example 1 (full):</b> <a href="sample_tests/conflicts_1.php">conflicts_1.phpt</a></p>
</dd>
<dt id="whitespace_sensitive_section">--WHITESPACE_SENSITIVE--</dt>
<dd>
<p><b>Description:</b><br/>
<p>This flag is used to indicate that the test should not be changed by
automated formatting changes. Available as of PHP 7.4.3.
</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Format:</b><br/>
No value, just the --WHITESPACE_SENSITIVE-- statement.</p>
</dd>
<dt id="capture_stdio_section">--CAPTURE_STDIO--</dt>
<dd>
<p><b>Description:</b><br/>
This section enables which I/O streams the run-tests.php test script will use
when comparing executed file to the expected output. The STDIN is the standard
input stream. When STDOUT is enabled, the test script will also check the
contents of the standard output. When STDERR is enabled, the test script will
also compare the contents of the standard error I/O stream.</p>
<p>If this section is left out of the test, by default, all three streams are
enabled, so the tests without this section capture all and is the same as enabling
all three manually.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Format:</b><br/>
A case insensitive space, newline or otherwise delimited list of one or more
strings of STDIN, STDOUT, and/or STDERR.
</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--CAPTURE_STDIO--
STDIN STDERR
</pre>
</p>
<p><b>Example 1 (full):</b> <a href="sample_tests/capture_stdio_1.php">capture_stdio_1.phpt</a></p>
<p><b>Example 2 (snippet):</b><br/>
<pre>--CAPTURE_STDIO--
STDIN STDOUT</pre>
</p>
<p><b>Example 2 (full):</b> <a href="sample_tests/capture_stdio_2.php">capture_stdio_2.phpt</a></p>
<p><b>Example 3 (snippet):</b><br/>
<pre>--CAPTURE_STDIO--
STDIN STDOUT STDERR</pre>
</p>
<p><b>Example 3(full):</b> <a href="sample_tests/capture_stdio_3.php">capture_stdio_3.phpt</a></p>
<dt id="extensions_section">--EXTENSIONS--</dt>
<dd>
<p><b>Description:</b><br/>
Additional required shared extensions to be loaded when running the test. When
the run-tests.php script is executed it loads all the extensions that are
available and enabled for that particular PHP at the time. If the test requires
additional extension to be loaded and they aren't loaded prior to running the
test, this section loads them.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Format:</b><br/>
A case sensitive newline separated list of extension names.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--EXTENSIONS--
curl
imagick
tokenizer
</pre>
</p>
<p><b>Example 1 (full):</b> <a href="sample_tests/extensions.php">extensions.phpt</a></p>
</dd>
<dt id="post_section">--POST--</dt>
<dd>
<p><b>Description:</b><br/>
POST variables or data to be passed to the test script. This section forces the
use of the CGI binary instead of the usual CLI one.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Requirements:</b><br/>
PHP CGI binary.</p>
<p><b>Format:</b><br/>
Follows the HTTP post data format.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--POST--
c=<p>string</p>&d=12345.7</pre>
</p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample001.php">sample001.phpt</a></p>
<p><b>Example 2 (snippet):</b><br/>
<pre>--POST--
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:si="http://soapinterop.org/xsd">
<SOAP-ENV:Body>
<ns1:test xmlns:ns1="http://testuri.org" />
</SOAP-ENV:Body>
</SOAP-ENV:Envelope></pre></p>
<p><b>Example 2 (full):</b> <a href="sample_tests/sample005.php">sample005.phpt</a></p>
</dd>
<dt id="post_raw_section">--POST_RAW--</dt>
<dd>
<p><b>Description:</b><br/>
Raw POST data to be passed to the test script. This differs from the section
above because it doesn't automatically set the Content-Type, this leaves you
free to define your own within the section. This section forces the use of the
CGI binary instead of the usual CLI one.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Requirements:</b><br/>
PHP CGI binary.</p>
<p><b>Test Script Support:</b><br/>
run-tests.php</p>
<p><b>Format:</b><br/>
Follows the HTTP post data format.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--POST_RAW--
Content-type: multipart/form-data, boundary=AaB03x
--AaB03x
content-disposition: form-data; name="field1"
Joe Blow
--AaB03x
content-disposition: form-data; name="pics"; filename="file1.txt"
Content-Type: text/plain
abcdef123456789
--AaB03x--</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample006.php">sample006.phpt</a></p>
</dd>
<dt id="put_section">--PUT--</dt>
<dd>
<p><b>Description:</b><br/>
Similar to the section above, PUT data to be passed to the test script.
This section forces the use of the CGI binary instead of the usual CLI one.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Requirements:</b><br/>
PHP CGI binary.</p>
<p><b>Test Script Support:</b><br/>
run-tests.php</p>
<p><b>Format:</b><br/>
Raw data optionally preceeded by a Content-Type header.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--PUT--
Content-Type: text/json
{"name":"default output handler","type":0,"flags":112,"level":0,"chunk_size":0,"buffer_size":16384,"buffer_used":3}</pre>
</p>
</dd>
<dt id="gzip_post_section">--GZIP_POST--</dt>
<dd>
<p><b>Description:</b><br/>
When this section exists, the POST data will be gzencode()'d. This section
forces the use of the CGI binary instead of the usual CLI one.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Test Script Support:</b><br/>
run-tests.php</p>
<p><b>Format:</b><br/>
Just add the content to be gzencode()'d in the section.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--GZIP_POST--
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:si="http://soapinterop.org/xsd">
<SOAP-ENV:Body>
<ns1:test xmlns:ns1="http://testuri.org" />
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</p></pre>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample005.php">sample005.phpt</a></p>
</dd>
<dt id="deflate_post_section">--DEFLATE_POST--</dt>
<dd>
<p><b>Description:</b><br/>
When this section exists, the POST data will be gzcompress()'ed. This section
forces the use of the CGI binary instead of the usual CLI one.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Requirements:</b><br/>
<p><b>Test Script Support:</b><br/>
run-tests.php</p>
<p><b>Format:</b><br/>
Just add the content to be gzcompress()'ed in the section.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--DEFLATE_POST--
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:si="http://soapinterop.org/xsd">
<SOAP-ENV:Body>
<ns1:test xmlns:ns1="http://testuri.org" />
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample007.php">sample007.phpt</a></p>
</dd>
<dt id="get_section">--GET--</dt>
<dd>
<p><b>Description:</b><br/>
GET variables to be passed to the test script. This section forces the use of
the CGI binary instead of the usual CLI one.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Requirements:</b><br/>
PHP CGI binary.</p>
<p><b>Format:</b><br/>
A single line of text passed as the GET data to the script.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--GET--
a=<b>test</b>&b=http://example.com</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample001.php">sample001.phpt</a></p>
<p><b>Example 2 (snippet):</b><br/>
<pre>--GET--
ar[elm1]=1234&ar[elm2]=0660&a=0234</pre></p>
<p><b>Example 2 (full):</b> <a href="sample_tests/sample008.php">sample008.phpt</a></p>
</dd>
<dt id="cookie_section">--COOKIE--</dt>
<dd>
<p><b>Description:</b><br/>
Cookies to be passed to the test script. This section forces the use of the CGI
binary instead of the usual CLI one.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Requirements:</b><br/>
PHP CGI binary.</p>
<p><b>Test Script Support:</b><br/>
run-tests.php</p>
<p><b>Format:</b><br/>
A single line of text in a valid HTTP cookie format.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--COOKIE--
hello=World;goodbye=MrChips</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample002.php">sample002.phpt</a></p>
</dd>
<dt id="stdin_section">--STDIN--</dt>
<dd>
<p><b>Description:</b><br/>
Data to be fed to the test script's standard input.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Test Script Support:</b><br/>
run-tests.php</p>
<p><b>Format:</b><br/>
Any text within this section is passed as STDIN to PHP.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--STDIN--
fooBar
use this to input some thing to the php script</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample009.php">sample009.phpt</a></p>
</dd>
<dt id="ini_section">--INI--</dt>
<dd>
<p><b>Description:</b><br/>
To be used if you need a specific php.ini setting for the test.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Format:</b><br/>
Key value pairs including automatically replaced tags. One setting per line. Content that is not a valid ini setting may cause failures.</p>
<p>The following is a list of all tags and what they are used to represent:</p>
<ul>
<li>{PWD}: Represents the directory of the file containing the --INI-- section.</li>
<li>{TMP}: Represents the system's temporary directory. Available as of PHP 7.2.19 and 7.3.6.</li>
</ul>
<p><b>Example 1 (snippet):</b><br/>
<pre>--INI--
precision=14</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample001.php">sample001.phpt</a></p>
<p><b>Example 2 (snippet):</b><br/>
<pre>--INI--
session.use_cookies=0
session.cache_limiter=
register_globals=1
session.serialize_handler=php
session.save_handler=files</pre></p>
<p><b>Example 2 (full):</b> <a href="sample_tests/sample003.php">sample003.phpt</a></p>
</dd>
<dt id="args_section">--ARGS--</dt>
<dd>
<p><b>Description:</b><br/>
A single line defining the arguments passed to php.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Format:</b><br/>
A single line of text that is passed as the argument(s) to the PHP CLI.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--ARGS--
--arg value --arg=value -avalue -a=value -a value</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample010.php">sample010.phpt</a></p>
</dd>
<dt id="env_section">--ENV--</dt>
<dd>
<p><b>Description:</b><br/>
Configures environment variables such as those found in the $_SERVER global
array.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Format:</b><br/>
Key value pairs. One setting per line.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--ENV--
SCRIPT_NAME=/frontcontroller10.php
REQUEST_URI=/frontcontroller10.php/hi
PATH_INFO=/hi</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample018.php">sample018.phpt</a></p>
</dd>
<dt id="phpdbg_section">--PHPDBG--</dt>
<dd>
<p><b>Description:</b><br/>
This section takes arbitrary phpdbg commands and executes the test file
according to them as it would be run in the phpdbg prompt.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Format:</b><br/>
arbitrary phpdbg commands</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--PHPDBG--
b 4
b del 0
b 5
r
b del 1
r
y
q
</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/phpdbg_1.php">phpdbg_1.phpt</a></p>
</dd>
<dt id="file_section">--FILE--</dt>
<dd>
<p><b>Description:</b><br/>
The test source code.</p>
<p><b>Required:</b><br/>
One of the FILE type sections is required.</p>
<p><b>Format:</b><br/>
PHP source code enclosed by PHP tags.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--FILE--
<?php
ini_set('html_errors', false);
var_dump(filter_input(INPUT_GET, "a", FILTER_SANITIZE_STRIPPED));
var_dump(filter_input(INPUT_GET, "b", FILTER_SANITIZE_URL));
var_dump(filter_input(INPUT_GET, "a", FILTER_SANITIZE_SPECIAL_CHARS, array(1,2,3,4,5)));
var_dump(filter_input(INPUT_GET, "b", FILTER_VALIDATE_FLOAT, new stdClass));
var_dump(filter_input(INPUT_POST, "c", FILTER_SANITIZE_STRIPPED, array(5,6,7,8)));
var_dump(filter_input(INPUT_POST, "d", FILTER_VALIDATE_FLOAT));
var_dump(filter_input(INPUT_POST, "c", FILTER_SANITIZE_SPECIAL_CHARS));
var_dump(filter_input(INPUT_POST, "d", FILTER_VALIDATE_INT));
var_dump(filter_var(new stdClass, "d"));
var_dump(filter_input(INPUT_POST, "c", "", ""));
var_dump(filter_var("", "", "", "", ""));
var_dump(filter_var(0, 0, 0, 0, 0));
echo "Done\n";
?></pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample001.php">sample001.phpt</a></p>
</dd>
<dt id="fileeof_section">--FILEEOF--</dt>
<dd>
<p><b>Description:</b><br/>
An alternative to --FILE-- where any trailing line breaks (\n || \r || \r\n
found at the end of the section) are omitted. This is an extreme edge-case
feature, so 99.99% of the time you won't need this section.</p>
<p><b>Required:</b><br/>
One of the FILE type sections is required.</p>
<p><b>Test Script Support:</b><br/>
run-tests.php</p>
<p><b>Format:</b><br/>
PHP source code enclosed by PHP tags.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--FILEEOF--
<?php
eval("echo 'Hello'; // comment");
echo " World";
//last line comment</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample011.php">sample011.phpt</a></p>
</dd>
<dt id="file_external_section">--FILE_EXTERNAL--</dt>
<dd>
<p><b>Description:</b><br/>
An alternative to --FILE--. This is used to specify that an external file should
be used as the --FILE-- contents of the test file, and is designed for running
the same test file with different ini, environment, post/get or other external
inputs. Basically it allows you to DRY up some of your tests. The file must be
in the same directory as the test file, or in a subdirectory.</p>
<p><b>Required:</b><br/>
One of the FILE type sections is required.</p>
<p><b>Test Script Support:</b><br/>
run-tests.php</p>
<p><b>Format:</b><br/>
path/to/file. Single line.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--FILE_EXTERNAL--
files/file012.inc</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample012.php">sample012.phpt</a></p>
</dd>
<dt id="redirecttest_section">--REDIRECTTEST--</dt>
<dd>
<p><b>Description:</b><br/>
This block allows you to redirect from one test to a bunch of other tests. It
also allows you to set configurations which are used on all tests in your
destination.</p>
<p><b>Required:</b><br/>
One of the FILE type sections is required.</p>
<p><b>Test Script Support:</b><br/>
run-tests.php</p>
<p><b>Format:</b><br/>
PHP source which is run through eval(). The tests destination is the value of an
array index 'TESTS'. Also, keep in mind, you can not use a REDIRECTTEST which is
being pointed to by another test which contains a REDIRECTTEST. In other words,
no nesting.</p>
<p>The relative path declared in 'TESTS' is relative to the base directory for the
PHP source code, not relative to the current directory.</p>
<p>Last note, the array in this section must be returned to work.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--REDIRECTTEST--
return array(
'ENV' => array(
'PDOTEST_DSN' => 'sqlite2::memory:'
),
'TESTS' => 'ext/pdo/tests'
);</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample013.php">sample013.phpt</a><br/>
Note: The destination tests for this example are not included. See the PDO
extension tests for reference to live tests using this section.</p>
<p><b>Example 2 (snippet):</b><br/>
<pre>--REDIRECTTEST--
# magic auto-configuration
$config = array(
'TESTS' => 'ext/pdo/tests'
);
if (false !== getenv('PDO_MYSQL_TEST_DSN')) {
# user set them from their shell
$config['ENV']['PDOTEST_DSN'] = getenv('PDO_MYSQL_TEST_DSN');
$config['ENV']['PDOTEST_USER'] = getenv('PDO_MYSQL_TEST_USER');
$config['ENV']['PDOTEST_PASS'] = getenv('PDO_MYSQL_TEST_PASS');
if (false !== getenv('PDO_MYSQL_TEST_ATTR')) {
$config['ENV']['PDOTEST_ATTR'] = getenv('PDO_MYSQL_TEST_ATTR');
}
} else {
$config['ENV']['PDOTEST_DSN'] = 'mysql:host=localhost;dbname=test';
$config['ENV']['PDOTEST_USER'] = 'root';
$config['ENV']['PDOTEST_PASS'] = '';
}
return $config;</pre></p>
<p><b>Example 2 (full):</b> <a href="sample_tests/sample014.php">sample014.phpt</a><br/>
Note: The destination tests for this example are not included. See the PDO
extension tests for reference to live tests using this section.</p>
</dd>
<dt id="cgi_section">--CGI--</dt>
<dd>
<p><b>Description:</b><br/>
This section takes no value. It merely provides a simple marker for tests that
MUST be run as CGI, even if there is no --POST-- or --GET-- sections in the test
file. Available as of PHP 7.3.0.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Format:</b><br/>
No value, just the --CGI-- statement.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--CGI--</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample016.php">sample016.phpt</a></p>
</dd>
<dt id="xfail_section">--XFAIL--</dt>
<dd>
<p><b>Description:</b><br/>
This section identifies this test as one that is currently expected to fail. It
should include a brief description of why it's expected to fail. Reasons for
such expectations include tests that are written before the functionality
they are testing is implemented or notice of a bug which is due to upstream code
such as an extension which provides PHP support for some other software.</p>
<p>Please do NOT include an --XFAIL-- without providing a text description for
the reason it's being used.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Test Script Support:</b><br/>
run-tests.php</p>
<p><b>Format:</b><br/>
A short plain text description of why this test is currently expected to fail.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--XFAIL--
This bug might be still open on aix5.2-ppc64 and hpux11.23-ia64</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample017.php">sample017.phpt</a></p>
</dd>
<dt id="flaky_section">--FLAKY--</dt>
<dd>
<p><b>Description:</b><br/>
This section identifies this test as one that occassionally fails. If the test
actually fails, it will be retried one more time, and that result will be reported.
The section should include a brief description of why the test is flaky. Reasons for
this include tests that rely on relatively precise timing, or
temporary disc states. Available as of PHP 8.1.22 and 8.2.9, respectively.</p>
<p>Please do NOT include a --FLAKY-- section without providing a text description for
the reason it is being used.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Test Script Support:</b><br/>
run-tests.php</p>
<p><b>Format:</b><br/>
A short plain text description of why this test is flaky.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--FLAKY--
This test frequently fails in CI</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/flaky.php">flaky.phpt</a></p>
</dd>
<dt id="expectheaders_section">--EXPECTHEADERS--</dt>
<dd>
<p><b>Description:</b><br/>
The expected headers. Any header specified here must exist in the response and
have the same value or the test fails. Additional headers found in the actual
tests while running are ignored.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Format:</b><br/>
HTTP style headers. May include multiple lines.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--EXPECTHEADERS--
Status: 404</pre></p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--EXPECTHEADERS--
Content-type: text/html; charset=UTF-8
Status: 403 Access Denied</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample018.php">sample018.phpt</a><br/>
Note: The destination tests for this example are not included. See the phar
extension tests for reference to live tests using this section.</p>
</dd>
<dt id="expect_section">--EXPECT--</dt>
<dd>
<p><b>Description:</b><br/>
The expected output from the test script. This must match the actual output from
the test script exactly for the test to pass.</p>
<p><b>Required:</b><br/>
One of the EXPECT type sections is required.</p>
<p><b>Format:</b><br/>
Plain text. Multiple lines of text are allowed.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--EXPECT--
array(2) {
["hello"]=>
string(5) "World"
["goodbye"]=>
string(7) "MrChips"
}</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample002.php">sample002.phpt</a></p>
</dd>
<dt id="expect_external_section">--EXPECT_EXTERNAL--</dt>
<dd>
<p><b>Description:</b><br/>
Similar to to <a href="#expect_section">--EXPECT--</a> section, but just stating
a filename where to load the expected output from.
</p>
<p><b>Required:</b><br/>
One of the EXPECT type sections is required.</p>
<p><b>Test Script Support:</b><br/>
run-tests.php</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--EXPECT_EXTERNAL--
test001.expected.txt
</pre>
<p><b>test001.expected.txt</b>
<pre>array(2) {
["hello"]=>
string(5) "World"
["goodbye"]=>
string(7) "MrChips"
}</pre></p>
</dd>
<dt id="expectf_section">--EXPECTF--</dt>
<dd>
<p><b>Description:</b><br/>
An alternative of --EXPECT--. Where it differs from --EXPECT-- is that it uses a
number of substitution tags for strings, spaces, digits, etc. that appear in
test case output but which may vary between test runs. The most common example
of this is to use %s and %d to match the file path and line number which are
output by PHP Warnings.</p>
<p><b>Required:</b><br/>
One of the EXPECT type sections is required.</p>
<p><b>Format:</b><br/>
Plain text including tags which are inserted to represent different types of
output which are not guaranteed to have the same value on subsequent runs or
when run on different platforms.</p>
<p>The following is a list of all tags and what they are used to represent:<br/>
<ul>
<li>%e: Represents a directory separator, for example / on Linux.</li>
<li>%s: One or more of anything (character or white space) except the end of line
character.</li>
<li>%S: Zero or more of anything (character or white space) except the end of line
character.</li>
<li>%a: One or more of anything (character or white space) including the end of line
character.</li>
<li>%A: Zero or more of anything (character or white space) including the end of line
character.</li>
<li>%w: Zero or more white space characters.</li>
<li>%i: A signed integer value, for example +3142, -3142, 3142.</li>
<li>%d: An unsigned integer value, for example 123456.</li>
<li>%x: One or more hexadecimal character. That is, characters in the range 0-9, a-f,
A-F.</li>
<li>%f: A floating point number, for example: 3.142, -3.142, 3.142E-10, 3.142e+10.</li>
<li>%c: A single character of any sort (.).</li>
<li>%r...%r: Any string (...) enclosed between two %r will be treated as a regular
expression.</li>
</ul>
</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--EXPECTF--
string(4) "test"
string(18) "http://example.com"
string(27) "&#60;b&#62;test&#60;/b&#62;"
Notice: Object of class stdClass could not be converted to int in %ssample001.php on line %d
bool(false)
string(6) "string"
float(12345.7)
string(29) "&#60;p&#62;string&#60;/p&#62;"
bool(false)
Warning: filter_var() expects parameter 2 to be long, string given in %s011.php on line %d
NULL
Warning: filter_input() expects parameter 3 to be long, string given in %s011.php on line %d
NULL
Warning: filter_var() expects at most 3 parameters, 5 given in %s011.php on line %d
NULL
Warning: filter_var() expects at most 3 parameters, 5 given in %s011.php on line %d
NULL
Done</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample001.php">sample001.phpt</a></p>
<p><b>Example 2 (snippet):</b><br/>
<pre>--EXPECTF--
Warning: bzopen() expects exactly 2 parameters, 0 given in %s on line %d
NULL
Warning: bzopen(): '' is not a valid mode for bzopen(). Only 'w' and 'r' are supported. in %s on line %d
bool(false)
Warning: bzopen(): filename cannot be empty in %s on line %d
bool(false)
Warning: bzopen(): filename cannot be empty in %s on line %d
bool(false)
Warning: bzopen(): 'x' is not a valid mode for bzopen(). Only 'w' and 'r' are supported. in %s on line %d
bool(false)
Warning: bzopen(): 'rw' is not a valid mode for bzopen(). Only 'w' and 'r' are supported. in %s on line %d
bool(false)
Warning: bzopen(no_such_file): failed to open stream: No such file or directory in %s on line %d
bool(false)
resource(%d) of type (stream)
Done</pre></p>
<p><b>Example 2 (full):</b> <a href="sample_tests/sample019.php">sample019.phpt</a></p>
<p><b>Example 3 (snippet):</b><br/>
<pre>--EXPECTF--
object(DOMNodeList)#%d (0) {
}
int(0)
bool(true)
bool(true)
string(0) ""
bool(true)
bool(true)
bool(false)
bool(false)</pre></p>
<p><b>Example 2 (full):</b> <a href="sample_tests/sample020.php">sample020.phpt</a></p>
</dd>
<dt id="expectf_external_section">--EXPECTF_EXTERNAL--</dt>
<dd>
<p><b>Description:</b><br/>
Similar to to <a href="#expectf_section">--EXPECTF--</a> section, but like the
<a href="#expect_external">--EXPECT_EXTERNAL--</a> section just stating
a filename where to load the expected output from.
</p>
<p><b>Required:</b><br/>
One of the EXPECT type sections is required.</p>
<p><b>Test Script Support:</b><br/>
run-tests.php</p>
</dd>
<dt id="expectregex_section">--EXPECTREGEX--</dt>
<dd>
<p><b>Description:</b><br/>
An alternative of --EXPECT--. This form allows the tester to specify the result
in a regular expression.</p>
<p><b>Required:</b><br/>
One of the EXPECT type sections is required.</p>
<p><b>Format:</b><br/>
Plain text including regular expression patterns which represent data that can
vary between subsequent runs of a test or when run on different platforms.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--EXPECTREGEX--
M_E : 2.718281[0-9]*
M_LOG2E : 1.442695[0-9]*
M_LOG10E : 0.434294[0-9]*
M_LN2 : 0.693147[0-9]*
M_LN10 : 2.302585[0-9]*
M_PI : 3.141592[0-9]*
M_PI_2 : 1.570796[0-9]*
M_PI_4 : 0.785398[0-9]*
M_1_PI : 0.318309[0-9]*
M_2_PI : 0.636619[0-9]*
M_SQRTPI : 1.772453[0-9]*
M_2_SQRTPI: 1.128379[0-9]*
M_LNPI : 1.144729[0-9]*
M_EULER : 0.577215[0-9]*
M_SQRT2 : 1.414213[0-9]*
M_SQRT1_2 : 0.707106[0-9]*
M_SQRT3 : 1.732050[0-9]*</pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample021.php">sample021.phpt</a></p>
<p><b>Example 2 (snippet):</b><br/>
<pre>--EXPECTF--
*** Testing imap_append() : basic functionality ***
Create a new mailbox for test
Create a temporary mailbox and add 0 msgs
.. mailbox '%s' created
Add a couple of msgs to new mailbox {%s}INBOX.%s
bool(true)
bool(true)
Msg Count after append : 2
List the msg headers
array(2) {
[0]=>
string(%d) "%w%s 1)%s webmaster@something. Test message (%d chars)"
[1]=>
string(%d) "%w%s 2)%s webmaster@something. Another test (%d chars)"
}</pre></p>
<p><b>Example 2 (full):</b> <a href="sample_tests/sample025.php">sample025.phpt</a></p>
<p><b>Example 3 (snippet):</b><br/>
<pre>--EXPECTREGEX--
string\(4\) \"-012\"
string\(8\) \"2d303132\"
(string\(13\) \" 4294967284\"|string\(20\) \"18446744073709551604\")
(string\(26\) \"20202034323934393637323834\"|string\(40\) \"3138343436373434303733373039353531363034\")</pre></p>
<p><b>Example 3 (full):</b> <a href="sample_tests/sample023.php">sample023.phpt</a></p>
</dd>
<dt id="expectregex_external_section">--EXPECTREGEX_EXTERNAL--</dt>
<dd>
<p><b>Description:</b><br/>
Similar to to <a href="#expectregex_section">--EXPECTREGEX--</a> section, but like the
<a href="#expect_external">--EXPECT_EXTERNAL--</a> section just stating
a filename where to load the expected output from.
</p>
<p><b>Required:</b><br/>
One of the EXPECT type sections is required.</p>
<p><b>Test Script Support:</b><br/>
run-tests.php</p>
</dd>
<dt id="clean_section">--CLEAN--</dt>
<dd>
<p><b>Description:</b><br/>
Code that is executed after a test completes. It's main purpose is to allow you
to clean up after yourself. You might need to remove files created during the
test or close sockets or database connections following a test. Infact, even
if a test fails or encounters a fatal error during the test, the code found in
the --CLEAN-- section will still run.</p>
<p>Code in the clean section is run in a completely different process than the
one the test was run in. So do not try accessing variables you created in the
--FILE-- section from inside the --CLEAN-- section, they won't exist.</p>
<p>Using the switch --no-clean on run-tests.php, you can prevent the code found
in the --CLEAN-- section of a test from running. This allows you to inspect
generated data or files without them being removed by the --CLEAN-- section.</p>
<p><b>Required:</b><br/>
No.</p>
<p><b>Test Script Support:</b><br/>
run-tests.php</p>
<p><b>Format:</b><br/>
PHP source code enclosed by PHP tags.</p>
<p><b>Example 1 (snippet):</b><br/>
<pre>--CLEAN--
<?php
unlink(__DIR__.'/DomDocument_save_basic.tmp');
?></pre></p>
<p><b>Example 1 (full):</b> <a href="sample_tests/sample024.php">sample024.phpt</a></p>
<p><b>Example 2 (snippet):</b><br/>
<pre>--CLEAN--
<?php
require_once('clean.inc');
?></pre></p>
<p><b>Example 2 (full):</b> <a href="sample_tests/sample025.php">sample025.phpt</a></p>
<p><b>Example 3 (snippet):</b><br/>
<pre>--CLEAN--
<?php
$key = ftok(__DIR__.'/003.phpt', 'q');
$s = shm_attach($key);
shm_remove($s);
?></pre></p>
<p><b>Example 3 (full):</b> <a href="sample_tests/sample022.php">sample022.phpt</a></p>
</dd>
</dl>
</div>
<?php
common_footer();