Skip to content

Commit 59b8ea0

Browse files
derickrjmikola
authored andcommitted
Better messages for when things go wrong with exceptions
1 parent 3c4ab01 commit 59b8ea0

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

tests/utils/tools.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,26 +236,25 @@ function throws($function, $exceptionname, $infunction = null) {
236236
try {
237237
$function();
238238
} catch(Exception $e) {
239+
$message = str_replace(array("\n", "\r"), ' ', $e->getMessage());
239240
if ($e instanceof $exceptionname) {
240241
if ($infunction) {
241242
$trace = $e->getTrace();
242243
$function = $trace[0]["function"];
243244
if (strcasecmp($function, $infunction) == 0) {
244245
printf("OK: Got %s thrown from %s\n", $exceptionname, $infunction);
245246
} else {
246-
$message = str_replace(array("\n", "\r"), ' ', $e->getMessage());
247247
printf("ALMOST: Got %s - but was thrown in %s, not %s (%s)\n", $exceptionname, $function, $infunction, $message);
248248
}
249249
return $e->getMessage();
250250
}
251251
printf("OK: Got %s\n", $exceptionname);
252252
} else {
253-
$message = str_replace(array("\n", "\r"), ' ', $e->getMessage());
254-
printf("ALMOST: Got %s - expected %s: %s\n", get_class($e), $exceptionname, $message);
253+
printf("ALMOST: Got %s (%s) - expected %s\n", get_class($e), $message, $exceptionname);
255254
}
256255
return $e->getMessage();
257256
}
258-
echo "FAILED: Expected $exceptionname thrown!\n";
257+
echo "FAILED: Expected $exceptionname thrown, but no exception thrown!\n";
259258
}
260259
function printServer(MongoDB\Driver\Server $server)
261260
{

0 commit comments

Comments
 (0)