Skip to content

Commit 0e7b4d0

Browse files
committed
Add tests for mysqli property writing
Forgot to git add these in the previous commit.
1 parent d905e77 commit 0e7b4d0

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

ext/mysqli/tests/write_property.phpt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Writing to mysqli properties
3+
--EXTENSIONS--
4+
mysqli
5+
--FILE--
6+
<?php
7+
8+
$driver = new mysqli_driver;
9+
try {
10+
/* Read-only property */
11+
$driver->client_info = 'test';
12+
} catch (Error $e) {
13+
echo $e->getMessage(), "\n";
14+
}
15+
16+
$driver->reconnect = 0;
17+
var_dump($driver->reconnect);
18+
$str = '4';
19+
$str .= '2';
20+
$driver->reconnect = $str;
21+
var_dump($driver->reconnect);
22+
try {
23+
$driver->reconnect = [];
24+
} catch (Error $e) {
25+
echo $e->getMessage(), "\n";
26+
}
27+
28+
$driver->report_mode = "1";
29+
var_dump($driver->report_mode);
30+
try {
31+
$driver->report_mode = [];
32+
} catch (Error $e) {
33+
echo $e->getMessage(), "\n";
34+
}
35+
36+
?>
37+
--EXPECT--
38+
Cannot write read-only property mysqli_driver::$client_info
39+
bool(false)
40+
bool(true)
41+
Cannot assign array to property mysqli_driver::$reconnect of type bool
42+
int(1)
43+
Cannot assign array to property mysqli_driver::$report_mode of type int
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Writing to mysqli properties (strict_types)
3+
--EXTENSIONS--
4+
mysqli
5+
--FILE--
6+
<?php
7+
8+
declare(strict_types=1);
9+
10+
$driver = new mysqli_driver;
11+
try {
12+
/* Read-only property */
13+
$driver->client_info = 42;
14+
} catch (Error $e) {
15+
echo $e->getMessage(), "\n";
16+
}
17+
18+
try {
19+
$driver->reconnect = 0;
20+
} catch (Error $e) {
21+
echo $e->getMessage(), "\n";
22+
}
23+
24+
try {
25+
$driver->report_mode = "1";
26+
} catch (Error $e) {
27+
echo $e->getMessage(), "\n";
28+
}
29+
30+
?>
31+
--EXPECT--
32+
Cannot write read-only property mysqli_driver::$client_info
33+
Cannot assign int to property mysqli_driver::$reconnect of type bool
34+
Cannot assign string to property mysqli_driver::$report_mode of type int

0 commit comments

Comments
 (0)