Skip to content

Commit b58087d

Browse files
authored
test: improve tests for in_array (#21087)
By splitting the massive tests into more specific, smaller tests.
1 parent 42baffd commit b58087d

16 files changed

+1215
-649
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
--TEST--
2+
Test in_array() function : usage variations - haystack with booleans
3+
--FILE--
4+
<?php
5+
include(__DIR__ . '/in_array_variation1_data.inc');
6+
7+
$haystack = [TRUE, FALSE];
8+
9+
foreach ($values as $desc => $needle) {
10+
echo "-- $desc --\n";
11+
echo "in_array() strict=false\n";
12+
var_dump(in_array($needle, $haystack));
13+
echo "in_array() strict=true\n";
14+
var_dump(in_array($needle, $haystack, TRUE));
15+
}
16+
17+
?>
18+
--EXPECT--
19+
-- integer 4 --
20+
in_array() strict=false
21+
bool(true)
22+
in_array() strict=true
23+
bool(false)
24+
-- string '4' --
25+
in_array() strict=false
26+
bool(true)
27+
in_array() strict=true
28+
bool(false)
29+
-- float 4.00 --
30+
in_array() strict=false
31+
bool(true)
32+
in_array() strict=true
33+
bool(false)
34+
-- string 'b' --
35+
in_array() strict=false
36+
bool(true)
37+
in_array() strict=true
38+
bool(false)
39+
-- string '5' --
40+
in_array() strict=false
41+
bool(true)
42+
in_array() strict=true
43+
bool(false)
44+
-- integer -2 --
45+
in_array() strict=false
46+
bool(true)
47+
in_array() strict=true
48+
bool(false)
49+
-- float -2.0 --
50+
in_array() strict=false
51+
bool(true)
52+
in_array() strict=true
53+
bool(false)
54+
-- float -2.98989 --
55+
in_array() strict=false
56+
bool(true)
57+
in_array() strict=true
58+
bool(false)
59+
-- string '-.9' --
60+
in_array() strict=false
61+
bool(true)
62+
in_array() strict=true
63+
bool(false)
64+
-- string 'True' --
65+
in_array() strict=false
66+
bool(true)
67+
in_array() strict=true
68+
bool(false)
69+
-- empty string --
70+
in_array() strict=false
71+
bool(true)
72+
in_array() strict=true
73+
bool(false)
74+
-- empty array --
75+
in_array() strict=false
76+
bool(true)
77+
in_array() strict=true
78+
bool(false)
79+
-- null --
80+
in_array() strict=false
81+
bool(true)
82+
in_array() strict=true
83+
bool(false)
84+
-- string 'ab' --
85+
in_array() strict=false
86+
bool(true)
87+
in_array() strict=true
88+
bool(false)
89+
-- string 'abcd' --
90+
in_array() strict=false
91+
bool(true)
92+
in_array() strict=true
93+
bool(false)
94+
-- float 0.0 --
95+
in_array() strict=false
96+
bool(true)
97+
in_array() strict=true
98+
bool(false)
99+
-- integer -0 --
100+
in_array() strict=false
101+
bool(true)
102+
in_array() strict=true
103+
bool(false)
104+
-- string with null bytes --
105+
in_array() strict=false
106+
bool(true)
107+
in_array() strict=true
108+
bool(false)
109+
-- enum Sample::A --
110+
in_array() strict=false
111+
bool(true)
112+
in_array() strict=true
113+
bool(false)
114+
-- enum Sample::B --
115+
in_array() strict=false
116+
bool(true)
117+
in_array() strict=true
118+
bool(false)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
enum Sample {
3+
case A;
4+
case B;
5+
}
6+
7+
$values = [
8+
"integer 4" => 4,
9+
"string '4'" => "4",
10+
"float 4.00" => 4.00,
11+
"string 'b'" => "b",
12+
"string '5'" => "5",
13+
"integer -2" => -2,
14+
"float -2.0" => -2.0,
15+
"float -2.98989" => -2.98989,
16+
"string '-.9'" => "-.9",
17+
"string 'True'" => "True",
18+
"empty string" => "",
19+
"empty array" => [],
20+
"null" => NULL,
21+
"string 'ab'" => "ab",
22+
"string 'abcd'" => "abcd",
23+
"float 0.0" => 0.0,
24+
"integer -0" => -0,
25+
"string with null bytes" => "abcd\x00abcd\x00abcd",
26+
"enum Sample::A" => Sample::A,
27+
"enum Sample::B" => Sample::B,
28+
];
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
--TEST--
2+
Test in_array() function : usage variations - haystack with empty string and array
3+
--FILE--
4+
<?php
5+
include(__DIR__ . '/in_array_variation1_data.inc');
6+
7+
$haystack = ["", []];
8+
9+
foreach ($values as $desc => $needle) {
10+
echo "-- $desc --\n";
11+
echo "in_array() strict=false\n";
12+
var_dump(in_array($needle, $haystack));
13+
echo "in_array() strict=true\n";
14+
var_dump(in_array($needle, $haystack, TRUE));
15+
}
16+
17+
?>
18+
--EXPECT--
19+
-- integer 4 --
20+
in_array() strict=false
21+
bool(false)
22+
in_array() strict=true
23+
bool(false)
24+
-- string '4' --
25+
in_array() strict=false
26+
bool(false)
27+
in_array() strict=true
28+
bool(false)
29+
-- float 4.00 --
30+
in_array() strict=false
31+
bool(false)
32+
in_array() strict=true
33+
bool(false)
34+
-- string 'b' --
35+
in_array() strict=false
36+
bool(false)
37+
in_array() strict=true
38+
bool(false)
39+
-- string '5' --
40+
in_array() strict=false
41+
bool(false)
42+
in_array() strict=true
43+
bool(false)
44+
-- integer -2 --
45+
in_array() strict=false
46+
bool(false)
47+
in_array() strict=true
48+
bool(false)
49+
-- float -2.0 --
50+
in_array() strict=false
51+
bool(false)
52+
in_array() strict=true
53+
bool(false)
54+
-- float -2.98989 --
55+
in_array() strict=false
56+
bool(false)
57+
in_array() strict=true
58+
bool(false)
59+
-- string '-.9' --
60+
in_array() strict=false
61+
bool(false)
62+
in_array() strict=true
63+
bool(false)
64+
-- string 'True' --
65+
in_array() strict=false
66+
bool(false)
67+
in_array() strict=true
68+
bool(false)
69+
-- empty string --
70+
in_array() strict=false
71+
bool(true)
72+
in_array() strict=true
73+
bool(true)
74+
-- empty array --
75+
in_array() strict=false
76+
bool(true)
77+
in_array() strict=true
78+
bool(true)
79+
-- null --
80+
in_array() strict=false
81+
bool(true)
82+
in_array() strict=true
83+
bool(false)
84+
-- string 'ab' --
85+
in_array() strict=false
86+
bool(false)
87+
in_array() strict=true
88+
bool(false)
89+
-- string 'abcd' --
90+
in_array() strict=false
91+
bool(false)
92+
in_array() strict=true
93+
bool(false)
94+
-- float 0.0 --
95+
in_array() strict=false
96+
bool(false)
97+
in_array() strict=true
98+
bool(false)
99+
-- integer -0 --
100+
in_array() strict=false
101+
bool(false)
102+
in_array() strict=true
103+
bool(false)
104+
-- string with null bytes --
105+
in_array() strict=false
106+
bool(false)
107+
in_array() strict=true
108+
bool(false)
109+
-- enum Sample::A --
110+
in_array() strict=false
111+
bool(false)
112+
in_array() strict=true
113+
bool(false)
114+
-- enum Sample::B --
115+
in_array() strict=false
116+
bool(false)
117+
in_array() strict=true
118+
bool(false)
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
--TEST--
2+
Test in_array() function : usage variations - haystack with enum values
3+
--FILE--
4+
<?php
5+
include(__DIR__ . '/in_array_variation1_data.inc');
6+
7+
$haystack = [Sample::A];
8+
9+
foreach ($values as $desc => $needle) {
10+
echo "-- $desc --\n";
11+
echo "in_array() strict=false\n";
12+
var_dump(in_array($needle, $haystack));
13+
echo "in_array() strict=true\n";
14+
var_dump(in_array($needle, $haystack, TRUE));
15+
}
16+
17+
?>
18+
--EXPECT--
19+
-- integer 4 --
20+
in_array() strict=false
21+
bool(false)
22+
in_array() strict=true
23+
bool(false)
24+
-- string '4' --
25+
in_array() strict=false
26+
bool(false)
27+
in_array() strict=true
28+
bool(false)
29+
-- float 4.00 --
30+
in_array() strict=false
31+
bool(false)
32+
in_array() strict=true
33+
bool(false)
34+
-- string 'b' --
35+
in_array() strict=false
36+
bool(false)
37+
in_array() strict=true
38+
bool(false)
39+
-- string '5' --
40+
in_array() strict=false
41+
bool(false)
42+
in_array() strict=true
43+
bool(false)
44+
-- integer -2 --
45+
in_array() strict=false
46+
bool(false)
47+
in_array() strict=true
48+
bool(false)
49+
-- float -2.0 --
50+
in_array() strict=false
51+
bool(false)
52+
in_array() strict=true
53+
bool(false)
54+
-- float -2.98989 --
55+
in_array() strict=false
56+
bool(false)
57+
in_array() strict=true
58+
bool(false)
59+
-- string '-.9' --
60+
in_array() strict=false
61+
bool(false)
62+
in_array() strict=true
63+
bool(false)
64+
-- string 'True' --
65+
in_array() strict=false
66+
bool(false)
67+
in_array() strict=true
68+
bool(false)
69+
-- empty string --
70+
in_array() strict=false
71+
bool(false)
72+
in_array() strict=true
73+
bool(false)
74+
-- empty array --
75+
in_array() strict=false
76+
bool(false)
77+
in_array() strict=true
78+
bool(false)
79+
-- null --
80+
in_array() strict=false
81+
bool(false)
82+
in_array() strict=true
83+
bool(false)
84+
-- string 'ab' --
85+
in_array() strict=false
86+
bool(false)
87+
in_array() strict=true
88+
bool(false)
89+
-- string 'abcd' --
90+
in_array() strict=false
91+
bool(false)
92+
in_array() strict=true
93+
bool(false)
94+
-- float 0.0 --
95+
in_array() strict=false
96+
bool(false)
97+
in_array() strict=true
98+
bool(false)
99+
-- integer -0 --
100+
in_array() strict=false
101+
bool(false)
102+
in_array() strict=true
103+
bool(false)
104+
-- string with null bytes --
105+
in_array() strict=false
106+
bool(false)
107+
in_array() strict=true
108+
bool(false)
109+
-- enum Sample::A --
110+
in_array() strict=false
111+
bool(true)
112+
in_array() strict=true
113+
bool(true)
114+
-- enum Sample::B --
115+
in_array() strict=false
116+
bool(false)
117+
in_array() strict=true
118+
bool(false)

0 commit comments

Comments
 (0)