Skip to content

Commit 03133ff

Browse files
committed
Split out print_r tests and reduce them
1 parent 131b25a commit 03133ff

10 files changed

+768
-3396
lines changed

ext/standard/tests/general_functions/print_r.phpt

Lines changed: 0 additions & 1696 deletions
This file was deleted.

ext/standard/tests/general_functions/print_r_64bit.phpt

Lines changed: 0 additions & 1700 deletions
This file was deleted.
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
--TEST--
2+
print_r(): Test printing of arrays
3+
--INI--
4+
precision=14
5+
--WHITESPACE_SENSITIVE--
6+
--FILE--
7+
<?php
8+
9+
function check_print_r($variables) {
10+
$counter = 1;
11+
foreach($variables as $variable ) {
12+
echo "-- Iteration $counter --\n";
13+
ob_start();
14+
$should_be_true = print_r($variable, /* $return */ false);
15+
$output_content = ob_get_flush();
16+
var_dump($should_be_true);
17+
$print_r_with_return = print_r($variable, /* $return */ true);
18+
var_dump($output_content === $print_r_with_return);
19+
$output_content = null;
20+
$counter++;
21+
}
22+
}
23+
24+
$arrays = [
25+
[],
26+
[null],
27+
[false],
28+
[true],
29+
[''],
30+
[ [], [] ],
31+
[ [1, 2], ['a', 'b'] ],
32+
[1 => 'One'],
33+
["test" => "is_array"],
34+
[0],
35+
[-1],
36+
[10.5, 5.6],
37+
["string", "test"],
38+
['string', 'test'],
39+
];
40+
41+
check_print_r($arrays);
42+
43+
?>
44+
--EXPECT--
45+
-- Iteration 1 --
46+
Array
47+
(
48+
)
49+
bool(true)
50+
bool(true)
51+
-- Iteration 2 --
52+
Array
53+
(
54+
[0] =>
55+
)
56+
bool(true)
57+
bool(true)
58+
-- Iteration 3 --
59+
Array
60+
(
61+
[0] =>
62+
)
63+
bool(true)
64+
bool(true)
65+
-- Iteration 4 --
66+
Array
67+
(
68+
[0] => 1
69+
)
70+
bool(true)
71+
bool(true)
72+
-- Iteration 5 --
73+
Array
74+
(
75+
[0] =>
76+
)
77+
bool(true)
78+
bool(true)
79+
-- Iteration 6 --
80+
Array
81+
(
82+
[0] => Array
83+
(
84+
)
85+
86+
[1] => Array
87+
(
88+
)
89+
90+
)
91+
bool(true)
92+
bool(true)
93+
-- Iteration 7 --
94+
Array
95+
(
96+
[0] => Array
97+
(
98+
[0] => 1
99+
[1] => 2
100+
)
101+
102+
[1] => Array
103+
(
104+
[0] => a
105+
[1] => b
106+
)
107+
108+
)
109+
bool(true)
110+
bool(true)
111+
-- Iteration 8 --
112+
Array
113+
(
114+
[1] => One
115+
)
116+
bool(true)
117+
bool(true)
118+
-- Iteration 9 --
119+
Array
120+
(
121+
[test] => is_array
122+
)
123+
bool(true)
124+
bool(true)
125+
-- Iteration 10 --
126+
Array
127+
(
128+
[0] => 0
129+
)
130+
bool(true)
131+
bool(true)
132+
-- Iteration 11 --
133+
Array
134+
(
135+
[0] => -1
136+
)
137+
bool(true)
138+
bool(true)
139+
-- Iteration 12 --
140+
Array
141+
(
142+
[0] => 10.5
143+
[1] => 5.6
144+
)
145+
bool(true)
146+
bool(true)
147+
-- Iteration 13 --
148+
Array
149+
(
150+
[0] => string
151+
[1] => test
152+
)
153+
bool(true)
154+
bool(true)
155+
-- Iteration 14 --
156+
Array
157+
(
158+
[0] => string
159+
[1] => test
160+
)
161+
bool(true)
162+
bool(true)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
--TEST--
2+
print_r(): Test printing basic primitive types
3+
--INI--
4+
precision=14
5+
--FILE--
6+
<?php
7+
8+
function check_print_r($variables) {
9+
$counter = 1;
10+
foreach($variables as $variable ) {
11+
echo "-- Iteration $counter --\n";
12+
$should_be_true = print_r($variable, /* $return */ false);
13+
echo PHP_EOL;
14+
var_dump($should_be_true);
15+
var_dump(print_r($variable, /* $return */ true));
16+
$counter++;
17+
}
18+
}
19+
20+
$basic_types = [
21+
null,
22+
false,
23+
true,
24+
0,
25+
42,
26+
-245,
27+
0o14,
28+
0xFA5,
29+
0b1101,
30+
];
31+
32+
check_print_r($basic_types);
33+
34+
?>
35+
--EXPECT--
36+
-- Iteration 1 --
37+
38+
bool(true)
39+
string(0) ""
40+
-- Iteration 2 --
41+
42+
bool(true)
43+
string(0) ""
44+
-- Iteration 3 --
45+
1
46+
bool(true)
47+
string(1) "1"
48+
-- Iteration 4 --
49+
0
50+
bool(true)
51+
string(1) "0"
52+
-- Iteration 5 --
53+
42
54+
bool(true)
55+
string(2) "42"
56+
-- Iteration 6 --
57+
-245
58+
bool(true)
59+
string(4) "-245"
60+
-- Iteration 7 --
61+
12
62+
bool(true)
63+
string(2) "12"
64+
-- Iteration 8 --
65+
4005
66+
bool(true)
67+
string(4) "4005"
68+
-- Iteration 9 --
69+
13
70+
bool(true)
71+
string(2) "13"
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
--TEST--
2+
print_r(): Test printing floats
3+
--FILE--
4+
<?php
5+
6+
function check_print_r($variables) {
7+
$counter = 1;
8+
foreach($variables as $variable ) {
9+
echo "-- Iteration $counter --\n";
10+
ob_start();
11+
$should_be_true = print_r($variable, /* $return */ false);
12+
$output_content = ob_get_flush();
13+
echo PHP_EOL;
14+
var_dump($should_be_true);
15+
$print_r_with_return = print_r($variable, /* $return */ true);
16+
var_dump($output_content === $print_r_with_return);
17+
$output_content = null;
18+
$counter++;
19+
}
20+
}
21+
22+
$floats = [
23+
-0.0,
24+
+0.0,
25+
1.234,
26+
-1.234,
27+
-2.000000,
28+
000002.00,
29+
-.5,
30+
.567,
31+
-.6700000e-3,
32+
.6700000e+3,
33+
-4.10003e-3,
34+
4.100003e-3,
35+
1e5,
36+
-1e5,
37+
1e-5,
38+
-1e-5,
39+
1e+5,
40+
-1e+5,
41+
PHP_INT_MIN*2,
42+
PHP_INT_MAX*3,
43+
];
44+
45+
check_print_r($floats);
46+
47+
?>
48+
--EXPECT--
49+
-- Iteration 1 --
50+
-0
51+
bool(true)
52+
bool(true)
53+
-- Iteration 2 --
54+
0
55+
bool(true)
56+
bool(true)
57+
-- Iteration 3 --
58+
1.234
59+
bool(true)
60+
bool(true)
61+
-- Iteration 4 --
62+
-1.234
63+
bool(true)
64+
bool(true)
65+
-- Iteration 5 --
66+
-2
67+
bool(true)
68+
bool(true)
69+
-- Iteration 6 --
70+
2
71+
bool(true)
72+
bool(true)
73+
-- Iteration 7 --
74+
-0.5
75+
bool(true)
76+
bool(true)
77+
-- Iteration 8 --
78+
0.567
79+
bool(true)
80+
bool(true)
81+
-- Iteration 9 --
82+
-0.00067
83+
bool(true)
84+
bool(true)
85+
-- Iteration 10 --
86+
670
87+
bool(true)
88+
bool(true)
89+
-- Iteration 11 --
90+
-0.00410003
91+
bool(true)
92+
bool(true)
93+
-- Iteration 12 --
94+
0.004100003
95+
bool(true)
96+
bool(true)
97+
-- Iteration 13 --
98+
100000
99+
bool(true)
100+
bool(true)
101+
-- Iteration 14 --
102+
-100000
103+
bool(true)
104+
bool(true)
105+
-- Iteration 15 --
106+
1.0E-5
107+
bool(true)
108+
bool(true)
109+
-- Iteration 16 --
110+
-1.0E-5
111+
bool(true)
112+
bool(true)
113+
-- Iteration 17 --
114+
100000
115+
bool(true)
116+
bool(true)
117+
-- Iteration 18 --
118+
-100000
119+
bool(true)
120+
bool(true)
121+
-- Iteration 19 --
122+
-1.844674407371E+19
123+
bool(true)
124+
bool(true)
125+
-- Iteration 20 --
126+
2.7670116110564E+19
127+
bool(true)
128+
bool(true)

0 commit comments

Comments
 (0)