Skip to content

Commit

Permalink
Optimize signature of the FailureConverter::renderTraceAttributes()
Browse files Browse the repository at this point in the history
… method
  • Loading branch information
roxblnfk committed Mar 11, 2024
1 parent c5db23f commit ec4c8fd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/Exception/Failure/FailureConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,9 @@ private static function generateStackTraceString(\Throwable $e, bool $skipIntern
return \implode("\n", $result);
}

private static function renderTraceAttributes(?array $args): string
private static function renderTraceAttributes(array $args): string
{
/** @psalm-suppress RiskyTruthyFalsyComparison */
if (empty($args)) {
if ($args === []) {
return '';
}

Expand Down
39 changes: 32 additions & 7 deletions tests/Unit/Exception/FailureConverterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public function testApplicationFailureCanTransferData(): void
$this->assertSame(123, $restoredDetails->getValue(1));
}

public function testShouldSetStackTraceStringForAdditionalContext(): void
public function testStackTraceStringForAdditionalContext(): void
{
$trace = FailureConverter::mapExceptionToFailure(
new Exception(),
DataConverter::createDefault(),
)->getStackTrace();

self::assertStringContainsString(
'Temporal\Tests\Unit\Exception\FailureConverterTestCase->testShouldSetStackTraceStringForAdditionalContext()',
'Temporal\Tests\Unit\Exception\FailureConverterTestCase->testStackTraceStringForAdditionalContext()',
$trace,
);

Expand All @@ -50,14 +50,19 @@ public function testShouldSetStackTraceStringForAdditionalContext(): void
);
}

public function testShouldSetStackTraceStringForAdditionalContextEvenWhenClassIsNotPresented(): void
public function testStackTraceStringForAdditionalContextEvenWhenClassIsNotPresented(): void
{
$previous = \ini_get('zend.exception_ignore_args');
\ini_set('zend.exception_ignore_args', 'Off');

$trace = FailureConverter::mapExceptionToFailure(
call_user_func(fn () => new Exception()),
DataConverter::createDefault(),
)->getStackTrace();
try {
$trace = FailureConverter::mapExceptionToFailure(
call_user_func(fn () => new Exception()),
DataConverter::createDefault(),
)->getStackTrace();
} finally {
\ini_set('zend.exception_ignore_args', $previous);
}

self::assertStringContainsString(
'[internal function]',
Expand All @@ -79,4 +84,24 @@ public function testShouldSetStackTraceStringForAdditionalContextEvenWhenClassIs
$trace,
);
}

public function testStackTraceStringWithoutExceptionArgs(): void
{
$previous = \ini_get('zend.exception_ignore_args');
\ini_set('zend.exception_ignore_args', 'On');

try {
$trace = FailureConverter::mapExceptionToFailure(
call_user_func(static fn() => new Exception()),
DataConverter::createDefault(),
)->getStackTrace();
} finally {
\ini_set('zend.exception_ignore_args', $previous);
}

self::assertStringContainsString(
'call_user_func()',
$trace,
);
}
}

0 comments on commit ec4c8fd

Please sign in to comment.