Skip to content

Commit b550a96

Browse files
Use stricter comparison
1 parent 2669d69 commit b550a96

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/TextUI/Output/TestDox/ResultPrinter.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,12 @@ private function printThrowable(TestDoxTestResult $test): void
264264
*/
265265
private function colorizeMessageAndDiff(string $buffer, string $style): array
266266
{
267-
$lines = $buffer ? array_map('\rtrim', explode(PHP_EOL, $buffer)) : [];
267+
$lines = [];
268+
269+
if ($buffer !== '') {
270+
$lines = array_map('\rtrim', explode(PHP_EOL, $buffer));
271+
}
272+
268273
$message = [];
269274
$diff = [];
270275
$insideDiff = false;
@@ -329,11 +334,17 @@ private function formatStackTrace(string $stackTrace): string
329334

330335
private function prefixLines(string $prefix, string $message): string
331336
{
337+
$lines = preg_split('/\r\n|\r|\n/', $message);
338+
339+
if ($lines === false) {
340+
$lines = [];
341+
}
342+
332343
return implode(
333344
PHP_EOL,
334345
array_map(
335-
static fn (string $line) => ' ' . $prefix . ($line ? ' ' . $line : ''),
336-
preg_split('/\r\n|\r|\n/', $message) ?: [],
346+
static fn (string $line) => ' ' . $prefix . ($line !== '' ? ' ' . $line : ''),
347+
$lines,
337348
),
338349
);
339350
}

src/Util/Filter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function stackTraceFromThrowableAsString(Throwable $t, bool $unwra
4242
$file = $t->getFile();
4343
$line = $t->getLine();
4444
} else {
45-
if ($unwrap && $t->getPrevious()) {
45+
if ($unwrap && $t->getPrevious() !== null) {
4646
$t = $t->getPrevious();
4747
}
4848

src/Util/Json.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ public static function canonicalize(string $json): array
7777
*/
7878
private static function recursiveSort(mixed &$json): void
7979
{
80-
// Nulls, empty arrays, and scalars need no further handling.
81-
if (!$json || is_scalar($json)) {
80+
if ($json === null || $json === [] || is_scalar($json)) {
8281
return;
8382
}
8483

src/Util/ThrowableToStringMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static function map(Throwable $t): string
3232
if ($t instanceof SelfDescribing) {
3333
$buffer = $t->toString();
3434

35-
if ($t instanceof ExpectationFailedException && $t->getComparisonFailure()) {
35+
if ($t instanceof ExpectationFailedException && $t->getComparisonFailure() !== null) {
3636
$buffer .= $t->getComparisonFailure()->getDiff();
3737
}
3838

0 commit comments

Comments
 (0)