Skip to content

Commit 308a241

Browse files
authored
Zend: write tests for some ZPP specifiers (#23192)
This adds dedicated tests for ZPP specifiers with dedicated functions defined in ext/zend_test rather than using whatever function might be suitable, as it may get refactored. This covers the ZPP specifiers for "slow" and fast ZPP, including nullable, for: - `bool` - `int` - `float` - `int|float` - `int|float|string` (Fast ZPP only) - `resource` - `object` - `object|string` (Fast ZPP only) - Object of a class - Object of class OR int (Fast ZPP only) - Object of class OR string (Fast ZPP only) - Class name - Object OR class name Missing specifiers that are relagated to later are: - `array` - `array|object` - `array|int` - `array|string` - `callable` - `string` (including "path" checking for null bytes) - `string|int` - Enum - Zval - Variadics
1 parent 8b00475 commit 308a241

43 files changed

Lines changed: 5454 additions & 395 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Zend/Optimizer/zend_func_infos.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,10 @@ static const func_info_t func_infos[] = {
615615
F1("serialize", MAY_BE_STRING),
616616
F1("xml_error_string", MAY_BE_STRING|MAY_BE_NULL),
617617
F1("xml_parser_get_option", MAY_BE_STRING|MAY_BE_LONG|MAY_BE_BOOL),
618+
FN("zend_resource", MAY_BE_RESOURCE),
619+
FN("zend_resource_or_null", MAY_BE_RESOURCE|MAY_BE_NULL),
620+
FN("zend_resource_slow_zpp", MAY_BE_RESOURCE),
621+
FN("zend_resource_or_null_slow_zpp", MAY_BE_RESOURCE|MAY_BE_NULL),
618622
FN("zend_test_create_throwing_resource", MAY_BE_RESOURCE),
619623
FN("zip_open", MAY_BE_RESOURCE|MAY_BE_LONG|MAY_BE_FALSE),
620624
FN("zip_read", MAY_BE_RESOURCE|MAY_BE_FALSE),

‎Zend/tests/number_or_str_zpp.phpt‎

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

‎Zend/tests/str_or_obj_of_class_zpp.phpt‎

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

‎Zend/tests/str_or_obj_zpp.phpt‎

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
--TEST--
2+
Test bool ZPP specifier (strict_mode)
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
declare(strict_types=1);
9+
10+
$types = require 'types.inc';
11+
12+
foreach ($types as $name => $type) {
13+
echo "Using $name:\n";
14+
try {
15+
var_dump(zend_bool($type));
16+
} catch (Throwable $e) {
17+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
18+
}
19+
try {
20+
var_dump(zend_bool_or_null($type));
21+
} catch (Throwable $e) {
22+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
23+
}
24+
try {
25+
var_dump(zend_bool_slow_zpp($type));
26+
} catch (Throwable $e) {
27+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
28+
}
29+
try {
30+
var_dump(zend_bool_or_null_slow_zpp($type));
31+
} catch (Throwable $e) {
32+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
33+
}
34+
$ref =& $type;
35+
try {
36+
var_dump(zend_bool($ref));
37+
} catch (Throwable $e) {
38+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
39+
}
40+
try {
41+
var_dump(zend_bool_or_null($ref));
42+
} catch (Throwable $e) {
43+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
44+
}
45+
try {
46+
var_dump(zend_bool_slow_zpp($ref));
47+
} catch (Throwable $e) {
48+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
49+
}
50+
try {
51+
var_dump(zend_bool_or_null_slow_zpp($ref));
52+
} catch (Throwable $e) {
53+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
54+
}
55+
}
56+
57+
?>
58+
--EXPECT--
59+
Using null:
60+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, null given
61+
NULL
62+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, null given
63+
NULL
64+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, null given
65+
NULL
66+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, null given
67+
NULL
68+
Using false:
69+
bool(false)
70+
bool(false)
71+
bool(false)
72+
bool(false)
73+
bool(false)
74+
bool(false)
75+
bool(false)
76+
bool(false)
77+
Using true:
78+
bool(true)
79+
bool(true)
80+
bool(true)
81+
bool(true)
82+
bool(true)
83+
bool(true)
84+
bool(true)
85+
bool(true)
86+
Using 42:
87+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, int given
88+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, int given
89+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, int given
90+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, int given
91+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, int given
92+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, int given
93+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, int given
94+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, int given
95+
Using 73.5:
96+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, float given
97+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, float given
98+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, float given
99+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, float given
100+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, float given
101+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, float given
102+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, float given
103+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, float given
104+
Using 'string':
105+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, string given
106+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, string given
107+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, string given
108+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, string given
109+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, string given
110+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, string given
111+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, string given
112+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, string given
113+
Using '15':
114+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, string given
115+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, string given
116+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, string given
117+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, string given
118+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, string given
119+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, string given
120+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, string given
121+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, string given
122+
Using '56.7':
123+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, string given
124+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, string given
125+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, string given
126+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, string given
127+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, string given
128+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, string given
129+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, string given
130+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, string given
131+
Using 'stdClass':
132+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, string given
133+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, string given
134+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, string given
135+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, string given
136+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, string given
137+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, string given
138+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, string given
139+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, string given
140+
Using anon class name:
141+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, string given
142+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, string given
143+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, string given
144+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, string given
145+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, string given
146+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, string given
147+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, string given
148+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, string given
149+
Using []:
150+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, array given
151+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, array given
152+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, array given
153+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, array given
154+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, array given
155+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, array given
156+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, array given
157+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, array given
158+
Using new stdClass():
159+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, stdClass given
160+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, stdClass given
161+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, stdClass given
162+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, stdClass given
163+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, stdClass given
164+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, stdClass given
165+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, stdClass given
166+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, stdClass given
167+
Using new S():
168+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, S given
169+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, S given
170+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, S given
171+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, S given
172+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, S given
173+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, S given
174+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, S given
175+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, S given
176+
Using STDOUT:
177+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, resource given
178+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, resource given
179+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, resource given
180+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, resource given
181+
TypeError: zend_bool(): Argument #1 ($param) must be of type bool, resource given
182+
TypeError: zend_bool_or_null(): Argument #1 ($param) must be of type ?bool, resource given
183+
TypeError: zend_bool_slow_zpp(): Argument #1 ($param) must be of type bool, resource given
184+
TypeError: zend_bool_or_null_slow_zpp(): Argument #1 ($param) must be of type ?bool, resource given

0 commit comments

Comments
 (0)