Skip to content

Commit da6818c

Browse files
committed
fix
1 parent 60ceb16 commit da6818c

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

src/ErrorHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ private function initializeOnce(): void
192192
});
193193

194194
if (!(PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg')) {
195+
/**
196+
* @var string
197+
*/
195198
$this->workingDirectory = getcwd();
196199
}
197200

src/Exception/ErrorException.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use function array_slice;
1212
use function in_array;
1313
use function function_exists;
14+
use function ini_get;
1415

1516
/**
1617
* `ErrorException` represents a PHP error.
@@ -40,7 +41,7 @@ class ErrorException extends \ErrorException implements FriendlyExceptionInterfa
4041
];
4142

4243
/** @psalm-param DebugBacktraceType $backtrace */
43-
public function __construct(string $message = '', int $code = 0, int $severity = 1, string $filename = __FILE__, int $line = __LINE__, Exception $previous = null, private readonly array $backtrace = [])
44+
public function __construct(string $message = '', int $code = 0, int $severity = 1, string $filename = __FILE__, int $line = __LINE__, ?Exception $previous = null, private readonly array $backtrace = [])
4445
{
4546
parent::__construct($message, $code, $severity, $filename, $line, $previous);
4647
$this->addXDebugTraceToFatalIfAvailable();
@@ -149,6 +150,6 @@ private function isXdebugStackAvailable(): bool
149150
}
150151

151152
// Xdebug 3 and later, proper mode is required
152-
return str_contains(ini_get('xdebug.mode'), 'develop');
153+
return str_contains((string) ini_get('xdebug.mode'), 'develop');
153154
}
154155
}

src/Renderer/HtmlRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ private function renderTemplate(string $path, array $parameters): string
530530
try {
531531
/** @psalm-suppress PossiblyNullFunctionCall */
532532
$renderer->bindTo($this)($path, $parameters);
533-
return ob_get_clean();
533+
return (string) ob_get_clean();
534534
} catch (Throwable $e) {
535535
while (ob_get_level() > $obInitialLevel) {
536536
if (!@ob_end_clean()) {

src/Renderer/JsonRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function renderVerbose(Throwable $t, ?ServerRequestInterface $request = n
4040
'line' => $t->getLine(),
4141
'trace' => $t->getTrace(),
4242
],
43-
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_SUBSTITUTE | JSON_PARTIAL_OUTPUT_ON_ERROR
43+
JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_SUBSTITUTE | JSON_PARTIAL_OUTPUT_ON_ERROR
4444
)
4545
);
4646
}

tests/Renderer/HtmlRendererTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Exception;
88
use HttpSoft\Message\Uri;
99
use PHPUnit\Framework\Attributes\DataProvider;
10+
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
1011
use PHPUnit\Framework\TestCase;
1112
use Psr\Http\Message\ServerRequestInterface;
1213
use ReflectionClass;
@@ -131,9 +132,16 @@ public function testRenderCallStack(): void
131132
);
132133
}
133134

135+
#[WithoutErrorHandler]
134136
public function testRenderCallStackItemIfFileIsNotExistAndLineMoreZero(): void
135137
{
136-
$this->assertEmpty($this->invokeMethod(new HtmlRenderer(), 'renderCallStackItem', [
138+
$errorMessage = null;
139+
set_error_handler(
140+
static function (int $code, string $message) use (&$errorMessage) {
141+
$errorMessage = $message;
142+
}
143+
);
144+
$result = $this->invokeMethod(new HtmlRenderer(), 'renderCallStackItem', [
137145
'file' => 'not-exist',
138146
'line' => 1,
139147
'class' => null,
@@ -142,7 +150,11 @@ public function testRenderCallStackItemIfFileIsNotExistAndLineMoreZero(): void
142150
'index' => 1,
143151
'isVendorFile' => false,
144152
'reflectionParameters' => [],
145-
]));
153+
]);
154+
restore_error_handler();
155+
156+
$this->assertSame('', $result);
157+
$this->assertSame('file(not-exist): Failed to open stream: No such file or directory', $errorMessage);
146158
}
147159

148160
public function testRenderRequest(): void

0 commit comments

Comments
 (0)