Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4c5a6b0

Browse filesBrowse files
authored
tree-wide: Remove stacktraces from tests testing throwing clones (#18748)
This is in preparation for the possible future transformation of `clone` into a function call, but also meaningful on its own, since the purpose of the tests is not to test the stack trace generation, but rather that an exception was thrown. It also cleans up some unreachable code in the tests.
1 parent 0a8961a commit 4c5a6b0
Copy full SHA for 4c5a6b0
Expand file treeCollapse file tree

15 files changed

+115
-111
lines changed

‎Zend/tests/generators/clone.phpt

Copy file name to clipboardExpand all lines: Zend/tests/generators/clone.phpt
+9-7Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ function gen() {
77
yield;
88
}
99

10-
$gen = gen();
11-
clone $gen;
10+
11+
try {
12+
$gen = gen();
13+
clone $gen;
14+
} catch (Throwable $e) {
15+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
16+
}
1217

1318
?>
14-
--EXPECTF--
15-
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class Generator in %s:%d
16-
Stack trace:
17-
#0 {main}
18-
thrown in %s on line %d
19+
--EXPECT--
20+
Error: Trying to clone an uncloneable object of class Generator

‎ext/dom/tests/modern/token_list/clone.phpt

Copy file name to clipboardExpand all lines: ext/dom/tests/modern/token_list/clone.phpt
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ dom
77

88
$dom = DOM\XMLDocument::createFromString('<root class="a b c"><child/></root>');
99
$element = $dom->documentElement;
10-
clone $element->classList;
10+
try {
11+
clone $element->classList;
12+
} catch (Throwable $e) {
13+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
14+
}
1115

1216
?>
13-
--EXPECTF--
14-
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class Dom\TokenList in %s:%d
15-
Stack trace:
16-
#0 {main}
17-
thrown in %s on line %d
17+
--EXPECT--
18+
Error: Trying to clone an uncloneable object of class Dom\TokenList

‎ext/gd/tests/gdimage_prevent_cloning.phpt

Copy file name to clipboardExpand all lines: ext/gd/tests/gdimage_prevent_cloning.phpt
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ gd
55
--FILE--
66
<?php
77

8+
try {
89
$img_src = imagecreatetruecolor(32, 32);
910
$img_dst = clone $img_src;
11+
} catch (Throwable $e) {
12+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
13+
}
1014

1115
?>
12-
--EXPECTF--
13-
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class GdImage in %s:%d
14-
Stack trace:
15-
#0 {main}
16-
thrown in %s on line %d
16+
--EXPECT--
17+
Error: Trying to clone an uncloneable object of class GdImage

‎ext/mysqli/tests/mysqli_driver_unclonable.phpt

Copy file name to clipboardExpand all lines: ext/mysqli/tests/mysqli_driver_unclonable.phpt
+8-6Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ Trying to clone mysqli_driver object
44
mysqli
55
--FILE--
66
<?php
7+
8+
try {
79
$driver = new mysqli_driver;
810
$driver_clone = clone $driver;
9-
print "done!";
11+
} catch (Throwable $e) {
12+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
13+
}
14+
1015
?>
11-
--EXPECTF--
12-
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class mysqli_driver in %s:%d
13-
Stack trace:
14-
#0 {main}
15-
thrown in %s on line %d
16+
--EXPECT--
17+
Error: Trying to clone an uncloneable object of class mysqli_driver

‎ext/mysqli/tests/mysqli_result_unclonable.phpt

Copy file name to clipboardExpand all lines: ext/mysqli/tests/mysqli_result_unclonable.phpt
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ require_once 'skipifconnectfailure.inc';
1717
if (!($res = mysqli_query($link, "SELECT 'good' AS morning")))
1818
printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
1919

20-
$res_clone = clone $res;
21-
print "done!";
20+
try {
21+
$res_clone = clone $res;
22+
} catch (Throwable $e) {
23+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
24+
}
2225
?>
23-
--EXPECTF--
24-
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class mysqli_result in %s:%d
25-
Stack trace:
26-
#0 {main}
27-
thrown in %s on line %d
26+
--EXPECT--
27+
Error: Trying to clone an uncloneable object of class mysqli_result

‎ext/mysqli/tests/mysqli_stmt_unclonable.phpt

Copy file name to clipboardExpand all lines: ext/mysqli/tests/mysqli_stmt_unclonable.phpt
+7-8Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ require_once 'skipifconnectfailure.inc';
1717
if (!$stmt = mysqli_stmt_init($link))
1818
printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
1919

20-
/* no, still bails out */
21-
$stmt_clone = clone $stmt;
22-
print "done!";
20+
try {
21+
$stmt_clone = clone $stmt;
22+
} catch (Throwable $e) {
23+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
24+
}
2325
?>
24-
--EXPECTF--
25-
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class mysqli_stmt in %s:%d
26-
Stack trace:
27-
#0 {main}
28-
thrown in %s on line %d
26+
--EXPECT--
27+
Error: Trying to clone an uncloneable object of class mysqli_stmt

‎ext/mysqli/tests/mysqli_unclonable.phpt

Copy file name to clipboardExpand all lines: ext/mysqli/tests/mysqli_unclonable.phpt
+7-8Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ require_once 'skipifconnectfailure.inc';
1414
printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
1515
$host, $user, $db, $port, $socket);
1616

17-
$link_clone = clone $link;
18-
mysqli_close($link);
17+
try {
18+
$link_clone = clone $link;
19+
} catch (Throwable $e) {
20+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
21+
}
1922

20-
print "done!";
2123
?>
22-
--EXPECTF--
23-
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class mysqli in %s:%d
24-
Stack trace:
25-
#0 {main}
26-
thrown in %s on line %d
24+
--EXPECT--
25+
Error: Trying to clone an uncloneable object of class mysqli

‎ext/pdo/tests/bug_77849.phpt

Copy file name to clipboardExpand all lines: ext/pdo/tests/bug_77849.phpt
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE_
1515
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
1616

1717
$db = PDOTest::factory();
18-
$db2 = clone $db;
18+
try {
19+
$db2 = clone $db;
20+
} catch (Throwable $e) {
21+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
22+
}
1923
?>
20-
--EXPECTF--
21-
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class PDO in %s
22-
Stack trace:
23-
#0 {main}
24-
thrown in %s on line %d
24+
--EXPECT--
25+
Error: Trying to clone an uncloneable object of class PDO

‎ext/pdo/tests/bug_77849_2.phpt

Copy file name to clipboardExpand all lines: ext/pdo/tests/bug_77849_2.phpt
+9-8Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ PDO Common: Bug #77849 (inconsistent state of cloned statament object)
44
pdo
55
--FILE--
66
<?php
7-
$stmt = new PDOStatement();
87

9-
clone $stmt;
10-
?>
11-
--EXPECTF--
12-
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class PDOStatement in %s:4
13-
Stack trace:
14-
#0 {main}
15-
thrown in %s on line 4
8+
try {
9+
$stmt = new PDOStatement();
10+
clone $stmt;
11+
} catch (Throwable $e) {
12+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
13+
}
1614

15+
?>
16+
--EXPECT--
17+
Error: Trying to clone an uncloneable object of class PDOStatement

‎ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt

Copy file name to clipboardExpand all lines: ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ TestFest PHP|Tek
66
--FILE--
77
<?php
88
$rc = new ReflectionClass("stdClass");
9-
$rc2 = clone($rc);
9+
try {
10+
$rc2 = clone($rc);
11+
} catch (Throwable $e) {
12+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
13+
}
1014
?>
11-
--EXPECTF--
12-
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class ReflectionClass in %s:%d
13-
Stack trace:
14-
#0 {main}
15-
thrown in %s on line %d
15+
--EXPECT--
16+
Error: Trying to clone an uncloneable object of class ReflectionClass

‎ext/reflection/tests/ReflectionClass_isCloneable_001.phpt

Copy file name to clipboardExpand all lines: ext/reflection/tests/ReflectionClass_isCloneable_001.phpt
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ $obj = new ReflectionClass('xmlwriter');
4949
var_dump($obj->isCloneable());
5050
$obj = new ReflectionObject(new XMLWriter);
5151
var_dump($obj->isCloneable());
52-
$h = clone new xmlwriter;
52+
try {
53+
$h = clone new xmlwriter;
54+
} catch (Throwable $e) {
55+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
56+
}
5357

5458
?>
55-
--EXPECTF--
59+
--EXPECT--
5660
User class
5761
bool(true)
5862
bool(true)
@@ -68,8 +72,4 @@ bool(true)
6872
Internal class - XMLWriter
6973
bool(false)
7074
bool(false)
71-
72-
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class XMLWriter in %s:%d
73-
Stack trace:
74-
#0 {main}
75-
thrown in %s on line %d
75+
Error: Trying to clone an uncloneable object of class XMLWriter

‎ext/xml/tests/bug78563.phpt

Copy file name to clipboardExpand all lines: ext/xml/tests/bug78563.phpt
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ xml
55
--FILE--
66
<?php
77

8-
$parser = xml_parser_create();
9-
clone $parser;
8+
try {
9+
$parser = xml_parser_create();
10+
clone $parser;
11+
} catch (Throwable $e) {
12+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
13+
}
1014

1115
?>
12-
===DONE===
13-
--EXPECTF--
14-
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class XMLParser in %s:%d
15-
Stack trace:
16-
#0 {main}
17-
thrown in %s on line %d
16+
--EXPECT--
17+
Error: Trying to clone an uncloneable object of class XMLParser

‎ext/xmlreader/tests/bug51936.phpt

Copy file name to clipboardExpand all lines: ext/xmlreader/tests/bug51936.phpt
+10-11Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@ Bug #51936 (Crash with clone XMLReader)
44
xmlreader
55
--FILE--
66
<?php
7-
echo "Test\n";
87

98
$xmlreader = new XMLReader();
109
$xmlreader->xml("<a><b/></a>");
1110

1211
$xmlreader->next();
13-
$xmlreader2 = clone $xmlreader;
14-
$xmlreader2->next();
15-
?>
16-
Done
17-
--EXPECTF--
18-
Test
1912

20-
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class XMLReader in %s:%d
21-
Stack trace:
22-
#0 {main}
23-
thrown in %s on line %d
13+
try {
14+
$xmlreader2 = clone $xmlreader;
15+
$xmlreader2->next();
16+
} catch (Throwable $e) {
17+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
18+
}
19+
20+
?>
21+
--EXPECT--
22+
Error: Trying to clone an uncloneable object of class XMLReader

‎tests/classes/factory_and_singleton_007.phpt

Copy file name to clipboardExpand all lines: tests/classes/factory_and_singleton_007.phpt
+8-9Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ class test {
88
}
99
}
1010

11-
$obj = new test;
12-
$clone = clone $obj;
13-
$obj = NULL;
11+
try {
12+
$obj = new test;
13+
$clone = clone $obj;
14+
} catch (Throwable $e) {
15+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
16+
}
1417

15-
echo "Done\n";
1618
?>
17-
--EXPECTF--
18-
Fatal error: Uncaught Error: Call to protected test::__clone() from global scope in %s:%d
19-
Stack trace:
20-
#0 {main}
21-
thrown in %s on line %d
19+
--EXPECT--
20+
Error: Call to protected test::__clone() from global scope

‎tests/classes/factory_and_singleton_008.phpt

Copy file name to clipboardExpand all lines: tests/classes/factory_and_singleton_008.phpt
+8-9Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ class test {
88
}
99
}
1010

11-
$obj = new test;
12-
$clone = clone $obj;
13-
$obj = NULL;
11+
try {
12+
$obj = new test;
13+
$clone = clone $obj;
14+
} catch (Throwable $e) {
15+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
16+
}
1417

15-
echo "Done\n";
1618
?>
17-
--EXPECTF--
18-
Fatal error: Uncaught Error: Call to private test::__clone() from global scope in %s:%d
19-
Stack trace:
20-
#0 {main}
21-
thrown in %s on line %d
19+
--EXPECT--
20+
Error: Call to private test::__clone() from global scope

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.