diff --git a/src/Client/Caster/Trace.php b/src/Client/Caster/Trace.php index 7b936bd2..9be5c575 100644 --- a/src/Client/Caster/Trace.php +++ b/src/Client/Caster/Trace.php @@ -15,7 +15,7 @@ final class Trace /** * @param int<0, max> $number The tick number. * @param float $delta The time delta between the current and previous tick. - * @param int $memory The memory usage. + * @param int<0, max> $memory The memory usage. * @param list \sprintf('+%.2fms', $delta * 1000), $delta < 1 => \sprintf('+%.1fms', ($delta * 1000)), $delta < 10 => \sprintf('+%.2fs', $delta), - $delta < 60 => \sprintf('+%.3fs', $delta), + $delta < 60 => \sprintf('+%.1fs', $delta), default => \sprintf('+%dm %ds', (int) $delta % 60, (int) $delta % 60), }; diff --git a/src/functions.php b/src/functions.php index 0bb74ce9..2776bf89 100644 --- a/src/functions.php +++ b/src/functions.php @@ -77,6 +77,8 @@ function tr(mixed ...$values): mixed * When no arguments passed, it works like {@see tr()}. * * @param mixed ...$values + * + * @codeCoverageIgnore */ function td(mixed ...$values): never { diff --git a/tests/Unit/Client/Caster/TraceFileTest.php b/tests/Unit/Client/Caster/TraceFileTest.php new file mode 100644 index 00000000..14012a0f --- /dev/null +++ b/tests/Unit/Client/Caster/TraceFileTest.php @@ -0,0 +1,43 @@ + 'foo', + 'line' => 42, + 'file' => '/path/to/file.php', + 'class' => 'Foo', + 'type' => '->', + 'args' => ['bar'], + ]); + + self::assertSame('file.php:42', (string) $traceFile); + } + + public function testToStringWithoutFile(): void + { + $traceFile = new \Buggregator\Trap\Client\Caster\TraceFile([ + 'function' => 'foo', + ]); + + self::assertSame('', (string) $traceFile); + } + + public function testToStringWithoutLine(): void + { + $traceFile = new \Buggregator\Trap\Client\Caster\TraceFile([ + 'function' => 'foo', + 'file' => '/path/to/file.php', + ]); + + self::assertSame('', (string) $traceFile); + } +} diff --git a/tests/Unit/Client/Caster/TraceTest.php b/tests/Unit/Client/Caster/TraceTest.php new file mode 100644 index 00000000..1b822684 --- /dev/null +++ b/tests/Unit/Client/Caster/TraceTest.php @@ -0,0 +1,58 @@ + $number + * @param int<0, max> $memory + * @param non-empty-string $result + */ + #[DataProvider('provideToString')] + public function testToString(int $number, float $delta, int $memory, string $result): void + { + $trace = new Trace( + number: $number, + delta: $delta, + memory: $memory, + stack: [ + [ + 'function' => 'foo', + 'line' => 42, + 'file' => '/path/to/file.php', + 'class' => 'Foo', + 'type' => '->', + 'args' => ['bar'], + ], + [ + 'function' => 'bar', + 'line' => 23, + 'file' => '/path/to/file.php', + 'class' => 'Bar', + 'type' => '::', + 'args' => ['baz'], + ], + ], + ); + + self::assertSame($result, (string) $trace); + } +}