From b18a2d5ac61e54fe1a6dc8dbd7e3f89148474b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 1 Nov 2023 23:29:48 +0100 Subject: [PATCH] Enhancement: Extract Duration --- CHANGELOG.md | 5 + psalm-baseline.xml | 2 +- src/Comparator/DurationComparator.php | 6 +- src/Duration.php | 88 ++++++++++ src/Exception/InvalidNanoseconds.php | 36 ++++ src/Exception/InvalidSeconds.php | 28 +++ src/Formatter/DefaultDurationFormatter.php | 4 +- src/Formatter/DurationFormatter.php | 4 +- src/MaximumDuration.php | 10 +- src/Reporter/DefaultReporter.php | 6 +- src/SlowTest.php | 12 +- src/Subscriber/TestPassedSubscriber.php | 7 +- src/TimeKeeper.php | 11 +- .../Comparator/DurationComparatorTest.php | 14 +- test/Unit/DurationTest.php | 162 ++++++++++++++++++ .../Unit/Exception/InvalidNanosecondsTest.php | 52 ++++++ test/Unit/Exception/InvalidSecondsTest.php | 38 ++++ .../DefaultDurationFormatterTest.php | 22 +-- test/Unit/MaximumDurationTest.php | 24 +-- 19 files changed, 472 insertions(+), 59 deletions(-) create mode 100644 src/Duration.php create mode 100644 src/Exception/InvalidNanoseconds.php create mode 100644 src/Exception/InvalidSeconds.php create mode 100644 test/Unit/DurationTest.php create mode 100644 test/Unit/Exception/InvalidNanosecondsTest.php create mode 100644 test/Unit/Exception/InvalidSecondsTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a700a23..56b10c6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), For a full diff see [`2.3.2...main`][2.3.2...main]. +### Changed + +- Extracted `Duration` ([#351]), by [@localheinz] + ### Fixed - Marked `DefaultDurationFormatter` as internal ([#350]), by [@localheinz] @@ -169,5 +173,6 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0]. [#342]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/342 [#343]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/343 [#350]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/350 +[#351]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/351 [@localheinz]: https://github.com/localheinz diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 9e728ccc..81881ebb 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -78,7 +78,7 @@ - provideMillisecondsAndTelemetryDuration + provideMillisecondsAndDuration diff --git a/src/Comparator/DurationComparator.php b/src/Comparator/DurationComparator.php index 9e3da71b..133a80db 100644 --- a/src/Comparator/DurationComparator.php +++ b/src/Comparator/DurationComparator.php @@ -13,7 +13,7 @@ namespace Ergebnis\PHPUnit\SlowTestDetector\Comparator; -use PHPUnit\Event; +use Ergebnis\PHPUnit\SlowTestDetector\Duration; /** * @internal @@ -21,8 +21,8 @@ final class DurationComparator { public function compare( - Event\Telemetry\Duration $one, - Event\Telemetry\Duration $two, + Duration $one, + Duration $two, ): int { if ($one->isLessThan($two)) { return -1; diff --git a/src/Duration.php b/src/Duration.php new file mode 100644 index 00000000..2b19d376 --- /dev/null +++ b/src/Duration.php @@ -0,0 +1,88 @@ + $seconds) { + throw Exception\InvalidSeconds::notGreaterThanZero($seconds); + } + + if (0 > $nanoseconds) { + throw Exception\InvalidNanoseconds::notGreaterThanZero($nanoseconds); + } + + if (999_999_999 < $nanoseconds) { + throw Exception\InvalidNanoseconds::notLessThanOrEqualTo999999999($nanoseconds); + } + + return new self( + $seconds, + $nanoseconds, + ); + } + + public function seconds(): int + { + return $this->seconds; + } + + public function nanoseconds(): int + { + return $this->nanoseconds; + } + + public function isLessThan(self $other): bool + { + if ($this->seconds < $other->seconds) { + return true; + } + + if ($this->seconds > $other->seconds) { + return false; + } + + return $this->nanoseconds < $other->nanoseconds; + } + + public function isGreaterThan(self $other): bool + { + if ($this->seconds > $other->seconds) { + return true; + } + + if ($this->seconds < $other->seconds) { + return false; + } + + return $this->nanoseconds > $other->nanoseconds; + } +} diff --git a/src/Exception/InvalidNanoseconds.php b/src/Exception/InvalidNanoseconds.php new file mode 100644 index 00000000..6c11e38d --- /dev/null +++ b/src/Exception/InvalidNanoseconds.php @@ -0,0 +1,36 @@ +seconds() * 1000 + $duration->nanoseconds() / 1000000; diff --git a/src/Formatter/DurationFormatter.php b/src/Formatter/DurationFormatter.php index 88a474fb..52ce141b 100644 --- a/src/Formatter/DurationFormatter.php +++ b/src/Formatter/DurationFormatter.php @@ -13,12 +13,12 @@ namespace Ergebnis\PHPUnit\SlowTestDetector\Formatter; -use PHPUnit\Event; +use Ergebnis\PHPUnit\SlowTestDetector\Duration; /** * @internal */ interface DurationFormatter { - public function format(Event\Telemetry\Duration $duration): string; + public function format(Duration $duration): string; } diff --git a/src/MaximumDuration.php b/src/MaximumDuration.php index 8f9a3a5d..5fd01ac8 100644 --- a/src/MaximumDuration.php +++ b/src/MaximumDuration.php @@ -13,14 +13,12 @@ namespace Ergebnis\PHPUnit\SlowTestDetector; -use PHPUnit\Event; - /** * @internal */ final class MaximumDuration { - private function __construct(private readonly Event\Telemetry\Duration $duration) + private function __construct(private readonly Duration $duration) { } @@ -33,7 +31,7 @@ public static function fromSeconds(int $seconds): self throw Exception\InvalidMaximumDuration::notGreaterThanZero($seconds); } - return new self(Event\Telemetry\Duration::fromSecondsAndNanoseconds( + return new self(Duration::fromSecondsAndNanoseconds( $seconds, 0, )); @@ -55,13 +53,13 @@ public static function fromMilliseconds(int $milliseconds): self $nanoseconds = ($milliseconds - $seconds * 1_000) * 1_000_000; - return new self(Event\Telemetry\Duration::fromSecondsAndNanoseconds( + return new self(Duration::fromSecondsAndNanoseconds( $seconds, $nanoseconds, )); } - public function toTelemetryDuration(): Event\Telemetry\Duration + public function toDuration(): Duration { return $this->duration; } diff --git a/src/Reporter/DefaultReporter.php b/src/Reporter/DefaultReporter.php index 5d694390..833c3c2f 100644 --- a/src/Reporter/DefaultReporter.php +++ b/src/Reporter/DefaultReporter.php @@ -14,11 +14,11 @@ namespace Ergebnis\PHPUnit\SlowTestDetector\Reporter; use Ergebnis\PHPUnit\SlowTestDetector\Comparator; +use Ergebnis\PHPUnit\SlowTestDetector\Duration; use Ergebnis\PHPUnit\SlowTestDetector\Formatter; use Ergebnis\PHPUnit\SlowTestDetector\MaximumCount; use Ergebnis\PHPUnit\SlowTestDetector\MaximumDuration; use Ergebnis\PHPUnit\SlowTestDetector\SlowTest; -use PHPUnit\Event; /** * @internal @@ -98,14 +98,14 @@ private function list(SlowTest ...$slowTests): string $longestMaximumDuration = \array_reduce( $slowTestsToReport, - static function (Event\Telemetry\Duration $maximumDuration, SlowTest $slowTest): Event\Telemetry\Duration { + static function (Duration $maximumDuration, SlowTest $slowTest): Duration { if ($maximumDuration->isLessThan($slowTest->maximumDuration())) { return $slowTest->maximumDuration(); } return $maximumDuration; }, - $this->maximumDuration->toTelemetryDuration(), + $this->maximumDuration->toDuration(), ); $durationFormatter = $this->durationFormatter; diff --git a/src/SlowTest.php b/src/SlowTest.php index 034d1d8b..3c35698d 100644 --- a/src/SlowTest.php +++ b/src/SlowTest.php @@ -22,15 +22,15 @@ final class SlowTest { private function __construct( private readonly Event\Code\Test $test, - private readonly Event\Telemetry\Duration $duration, - private readonly Event\Telemetry\Duration $maximumDuration, + private readonly Duration $duration, + private readonly Duration $maximumDuration, ) { } public static function fromTestDurationAndMaximumDuration( Event\Code\Test $test, - Event\Telemetry\Duration $duration, - Event\Telemetry\Duration $maximumDuration, + Duration $duration, + Duration $maximumDuration, ): self { return new self( $test, @@ -44,12 +44,12 @@ public function test(): Event\Code\Test return $this->test; } - public function duration(): Event\Telemetry\Duration + public function duration(): Duration { return $this->duration; } - public function maximumDuration(): Event\Telemetry\Duration + public function maximumDuration(): Duration { return $this->maximumDuration; } diff --git a/src/Subscriber/TestPassedSubscriber.php b/src/Subscriber/TestPassedSubscriber.php index cbe923c1..28ad3db7 100644 --- a/src/Subscriber/TestPassedSubscriber.php +++ b/src/Subscriber/TestPassedSubscriber.php @@ -14,6 +14,7 @@ namespace Ergebnis\PHPUnit\SlowTestDetector\Subscriber; use Ergebnis\PHPUnit\SlowTestDetector\Collector; +use Ergebnis\PHPUnit\SlowTestDetector\Duration; use Ergebnis\PHPUnit\SlowTestDetector\MaximumDuration; use Ergebnis\PHPUnit\SlowTestDetector\SlowTest; use Ergebnis\PHPUnit\SlowTestDetector\TimeKeeper; @@ -54,7 +55,7 @@ public function notify(Event\Test\Passed $event): void $this->collector->collect($slowTest); } - private function resolveMaximumDuration(Event\Code\Test $test): Event\Telemetry\Duration + private function resolveMaximumDuration(Event\Code\Test $test): Duration { $annotations = [ 'maximumDuration', @@ -84,9 +85,9 @@ private function resolveMaximumDuration(Event\Code\Test $test): Event\Telemetry\ continue; } - return MaximumDuration::fromMilliseconds((int) $maximumDuration)->toTelemetryDuration(); + return MaximumDuration::fromMilliseconds((int) $maximumDuration)->toDuration(); } - return $this->maximumDuration->toTelemetryDuration(); + return $this->maximumDuration->toDuration(); } } diff --git a/src/TimeKeeper.php b/src/TimeKeeper.php index 1d714a74..029abbbd 100644 --- a/src/TimeKeeper.php +++ b/src/TimeKeeper.php @@ -37,11 +37,11 @@ public function start( public function stop( Event\Code\Test $test, Event\Telemetry\HRTime $stoppedTime, - ): Event\Telemetry\Duration { + ): Duration { $key = $test->id(); if (!\array_key_exists($key, $this->startedTimes)) { - return Event\Telemetry\Duration::fromSecondsAndNanoseconds( + return Duration::fromSecondsAndNanoseconds( 0, 0, ); @@ -51,6 +51,11 @@ public function stop( unset($this->startedTimes[$key]); - return $stoppedTime->duration($startedTime); + $duration = $stoppedTime->duration($startedTime); + + return Duration::fromSecondsAndNanoseconds( + $duration->seconds(), + $duration->nanoseconds(), + ); } } diff --git a/test/Unit/Comparator/DurationComparatorTest.php b/test/Unit/Comparator/DurationComparatorTest.php index 1119356e..d0e36add 100644 --- a/test/Unit/Comparator/DurationComparatorTest.php +++ b/test/Unit/Comparator/DurationComparatorTest.php @@ -14,8 +14,8 @@ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Unit\Comparator; use Ergebnis\PHPUnit\SlowTestDetector\Comparator; +use Ergebnis\PHPUnit\SlowTestDetector\Duration; use Ergebnis\PHPUnit\SlowTestDetector\Test; -use PHPUnit\Event; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Comparator\DurationComparator::class)] @@ -25,12 +25,12 @@ final class DurationComparatorTest extends Framework\TestCase public function testReturnsMinusOneWhenOneIsLessThanTwo(): void { - $one = Event\Telemetry\Duration::fromSecondsAndNanoseconds( + $one = Duration::fromSecondsAndNanoseconds( 5, 0, ); - $two = Event\Telemetry\Duration::fromSecondsAndNanoseconds( + $two = Duration::fromSecondsAndNanoseconds( 5, 1, ); @@ -42,12 +42,12 @@ public function testReturnsMinusOneWhenOneIsLessThanTwo(): void public function testReturnsZeroWhenOneEqualsTwo(): void { - $one = Event\Telemetry\Duration::fromSecondsAndNanoseconds( + $one = Duration::fromSecondsAndNanoseconds( 5, 0, ); - $two = Event\Telemetry\Duration::fromSecondsAndNanoseconds( + $two = Duration::fromSecondsAndNanoseconds( 5, 0, ); @@ -59,12 +59,12 @@ public function testReturnsZeroWhenOneEqualsTwo(): void public function testReturnsPlusOneWhenOneIsGreaterThanTwo(): void { - $one = Event\Telemetry\Duration::fromSecondsAndNanoseconds( + $one = Duration::fromSecondsAndNanoseconds( 5, 1, ); - $two = Event\Telemetry\Duration::fromSecondsAndNanoseconds( + $two = Duration::fromSecondsAndNanoseconds( 5, 0, ); diff --git a/test/Unit/DurationTest.php b/test/Unit/DurationTest.php new file mode 100644 index 00000000..3e760c2c --- /dev/null +++ b/test/Unit/DurationTest.php @@ -0,0 +1,162 @@ +numberBetween(0, 999_999_999); + + $this->expectException(Exception\InvalidSeconds::class); + + Duration::fromSecondsAndNanoseconds( + $seconds, + $nanoseconds, + ); + } + + #[Framework\Attributes\DataProviderExternal(DataProvider\IntProvider::class, 'lessThanZero')] + public function testFromSecondsAndNanosecondsRejectsNanosecondsLessThanZero(int $nanoseconds): void + { + $seconds = self::faker()->numberBetween(0, 123); + + $this->expectException(Exception\InvalidNanoseconds::class); + + Duration::fromSecondsAndNanoseconds( + $seconds, + $nanoseconds, + ); + } + + #[Framework\Attributes\DataProviderExternal(DataProvider\IntProvider::class, 'greaterThanOne')] + public function testFromSecondsAndNanosecondsRejectsNanosecondsGreaterThan999999999(int $offset): void + { + $seconds = self::faker()->numberBetween(0, 123); + $nanoseconds = 999_999_999 + $offset; + + $this->expectException(Exception\InvalidNanoseconds::class); + + Duration::fromSecondsAndNanoseconds( + $seconds, + $nanoseconds, + ); + } + + public function testFromSecondsAndNanosecondsReturnsDuration(): void + { + $faker = self::faker(); + + $seconds = $faker->numberBetween(0, 999); + $nanoseconds = $faker->numberBetween(0, 999_999_999); + + $duration = Duration::fromSecondsAndNanoseconds( + $seconds, + $nanoseconds, + ); + + self::assertSame($seconds, $duration->seconds()); + self::assertSame($nanoseconds, $duration->nanoseconds()); + } + + public function testIsLessThanReturnsFalseWhenSecondsAreGreater(): void + { + $one = Duration::fromSecondsAndNanoseconds(123, 456); + $two = Duration::fromSecondsAndNanoseconds(122, 456); + + self::assertFalse($one->isLessThan($two)); + } + + public function testIsLessThanReturnsFalseWhenSecondsAreEqualAndNanosecondsAreGreater(): void + { + $one = Duration::fromSecondsAndNanoseconds(123, 456); + $two = Duration::fromSecondsAndNanoseconds(123, 455); + + self::assertFalse($one->isLessThan($two)); + } + + public function testIsLessThanReturnsFalseWhenValuesAreSame(): void + { + $one = Duration::fromSecondsAndNanoseconds(123, 456); + $two = Duration::fromSecondsAndNanoseconds(123, 456); + + self::assertFalse($one->isLessThan($two)); + } + + public function testIsLessThanReturnsTrueWhenSecondsAreLess(): void + { + $one = Duration::fromSecondsAndNanoseconds(123, 456); + $two = Duration::fromSecondsAndNanoseconds(124, 456); + + self::assertTrue($one->isLessThan($two)); + } + + public function testIsLessThanReturnsTrueWhenSecondsAreEqualAndNanosecondsAreLess(): void + { + $one = Duration::fromSecondsAndNanoseconds(123, 456); + $two = Duration::fromSecondsAndNanoseconds(123, 457); + + self::assertTrue($one->isLessThan($two)); + } + + public function testIsGreaterThanReturnsFalseWhenSecondsAreLess(): void + { + $one = Duration::fromSecondsAndNanoseconds(123, 456); + $two = Duration::fromSecondsAndNanoseconds(124, 456); + + self::assertFalse($one->isGreaterThan($two)); + } + + public function testIsGreaterThanReturnsFalseWhenSecondsAreEqualAndNanosecondsAreLess(): void + { + $one = Duration::fromSecondsAndNanoseconds(123, 456); + $two = Duration::fromSecondsAndNanoseconds(123, 457); + + self::assertFalse($one->isGreaterThan($two)); + } + + public function testIsGreaterThanReturnsFalseWhenValuesAreSame(): void + { + $one = Duration::fromSecondsAndNanoseconds(123, 456); + $two = Duration::fromSecondsAndNanoseconds(123, 456); + + self::assertFalse($one->isGreaterThan($two)); + } + + public function testIsGreaterThanReturnsTrueWhenSecondsAreGreater(): void + { + $one = Duration::fromSecondsAndNanoseconds(123, 456); + $two = Duration::fromSecondsAndNanoseconds(122, 456); + + self::assertTrue($one->isGreaterThan($two)); + } + + public function testIsGreaterThanReturnsTrueWhenSecondsAreEqualAndNanosecondsAreGreater(): void + { + $one = Duration::fromSecondsAndNanoseconds(123, 456); + $two = Duration::fromSecondsAndNanoseconds(123, 455); + + self::assertTrue($one->isGreaterThan($two)); + } +} diff --git a/test/Unit/Exception/InvalidNanosecondsTest.php b/test/Unit/Exception/InvalidNanosecondsTest.php new file mode 100644 index 00000000..b11e9896 --- /dev/null +++ b/test/Unit/Exception/InvalidNanosecondsTest.php @@ -0,0 +1,52 @@ +numberBetween(); + + $exception = Exception\InvalidNanoseconds::notGreaterThanZero($value); + + $message = \sprintf( + 'Value should be greater than 0, but %d is not.', + $value, + ); + + self::assertSame($message, $exception->getMessage()); + } + + public function testNotLessThanOrEqualTo999999999ReturnsException(): void + { + $value = self::faker()->numberBetween(); + + $exception = Exception\InvalidNanoseconds::notLessThanOrEqualTo999999999($value); + + $message = \sprintf( + 'Value should be less than or equal to 999999999, but %d is not.', + $value, + ); + + self::assertSame($message, $exception->getMessage()); + } +} diff --git a/test/Unit/Exception/InvalidSecondsTest.php b/test/Unit/Exception/InvalidSecondsTest.php new file mode 100644 index 00000000..409b0b5a --- /dev/null +++ b/test/Unit/Exception/InvalidSecondsTest.php @@ -0,0 +1,38 @@ +numberBetween(); + + $exception = Exception\InvalidSeconds::notGreaterThanZero($value); + + $message = \sprintf( + 'Value should be greater than 0, but %d is not.', + $value, + ); + + self::assertSame($message, $exception->getMessage()); + } +} diff --git a/test/Unit/Formatter/DefaultDurationFormatterTest.php b/test/Unit/Formatter/DefaultDurationFormatterTest.php index 324c9047..06911402 100644 --- a/test/Unit/Formatter/DefaultDurationFormatterTest.php +++ b/test/Unit/Formatter/DefaultDurationFormatterTest.php @@ -13,9 +13,9 @@ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Unit\Formatter; +use Ergebnis\PHPUnit\SlowTestDetector\Duration; use Ergebnis\PHPUnit\SlowTestDetector\Formatter; use Ergebnis\PHPUnit\SlowTestDetector\Test; -use PHPUnit\Event; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Formatter\DefaultDurationFormatter::class)] @@ -25,7 +25,7 @@ final class DefaultDurationFormatterTest extends Framework\TestCase #[Framework\Attributes\DataProvider('provideDurationAndFormattedDuration')] public function testFormatFormats( - Event\Telemetry\Duration $duration, + Duration $duration, string $formattedDuration, ): void { $formatter = new Formatter\DefaultDurationFormatter(); @@ -34,62 +34,62 @@ public function testFormatFormats( } /** - * @return array + * @return array */ public static function provideDurationAndFormattedDuration(): array { return [ 'zero' => [ - Event\Telemetry\Duration::fromSecondsAndNanoseconds( + Duration::fromSecondsAndNanoseconds( 0, 0, ), '0.000', ], 'milliseconds' => [ - Event\Telemetry\Duration::fromSecondsAndNanoseconds( + Duration::fromSecondsAndNanoseconds( 0, 123_999_000, ), '0.123', ], 'seconds-digits-one' => [ - Event\Telemetry\Duration::fromSecondsAndNanoseconds( + Duration::fromSecondsAndNanoseconds( 1, 234_456_789, ), '1.234', ], 'seconds-digits-two' => [ - Event\Telemetry\Duration::fromSecondsAndNanoseconds( + Duration::fromSecondsAndNanoseconds( 12, 345_678_912, ), '12.345', ], 'minutes-digits-one' => [ - Event\Telemetry\Duration::fromSecondsAndNanoseconds( + Duration::fromSecondsAndNanoseconds( 1 * 60 + 23, 456_789_012, ), '1:23.456', ], 'minutes-digits-two' => [ - Event\Telemetry\Duration::fromSecondsAndNanoseconds( + Duration::fromSecondsAndNanoseconds( 12 * 60 + 34, 567_890_123, ), '12:34.567', ], 'hours-digits-one' => [ - Event\Telemetry\Duration::fromSecondsAndNanoseconds( + Duration::fromSecondsAndNanoseconds( 60 * 60 + 23 * 60 + 45, 567_890_123, ), '1:23:45.567', ], 'hours-digits-two' => [ - Event\Telemetry\Duration::fromSecondsAndNanoseconds( + Duration::fromSecondsAndNanoseconds( 12 * 60 * 60 + 34 * 60 + 56, 789_012_345, ), diff --git a/test/Unit/MaximumDurationTest.php b/test/Unit/MaximumDurationTest.php index 409fd6aa..e3201a07 100644 --- a/test/Unit/MaximumDurationTest.php +++ b/test/Unit/MaximumDurationTest.php @@ -14,10 +14,10 @@ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Unit; use Ergebnis\DataProvider; +use Ergebnis\PHPUnit\SlowTestDetector\Duration; use Ergebnis\PHPUnit\SlowTestDetector\Exception; use Ergebnis\PHPUnit\SlowTestDetector\MaximumDuration; use Ergebnis\PHPUnit\SlowTestDetector\Test; -use PHPUnit\Event; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(MaximumDuration::class)] @@ -35,26 +35,26 @@ public function testFromMillisecondsRejectsInvalidValue(int $milliseconds): void MaximumDuration::fromMilliseconds($milliseconds); } - #[Framework\Attributes\DataProvider('provideMillisecondsAndTelemetryDuration')] + #[Framework\Attributes\DataProvider('provideMillisecondsAndDuration')] public function testFromMillisecondsReturnsMaximumDuration( int $milliseconds, - Event\Telemetry\Duration $duration, + Duration $duration, ): void { $maximumDuration = MaximumDuration::fromMilliseconds($milliseconds); - self::assertEquals($duration, $maximumDuration->toTelemetryDuration()); + self::assertEquals($duration, $maximumDuration->toDuration()); } /** - * @return \Generator + * @return \Generator */ - public static function provideMillisecondsAndTelemetryDuration(): \Generator + public static function provideMillisecondsAndDuration(): \Generator { $values = [ - 1 => Event\Telemetry\Duration::fromSecondsAndNanoseconds(0, 1_000_000), - 999 => Event\Telemetry\Duration::fromSecondsAndNanoseconds(0, 999_000_000), - 1_000 => Event\Telemetry\Duration::fromSecondsAndNanoseconds(1, 0), - 1_234 => Event\Telemetry\Duration::fromSecondsAndNanoseconds(1, 234_000_000), + 1 => Duration::fromSecondsAndNanoseconds(0, 1_000_000), + 999 => Duration::fromSecondsAndNanoseconds(0, 999_000_000), + 1_000 => Duration::fromSecondsAndNanoseconds(1, 0), + 1_234 => Duration::fromSecondsAndNanoseconds(1, 234_000_000), ]; foreach ($values as $milliseconds => $duration) { @@ -79,11 +79,11 @@ public function testFromSecondsReturnsMaximumDuration(int $seconds): void { $maximumDuration = MaximumDuration::fromSeconds($seconds); - $expected = Event\Telemetry\Duration::fromSecondsAndNanoseconds( + $expected = Duration::fromSecondsAndNanoseconds( $seconds, 0, ); - self::assertEquals($expected, $maximumDuration->toTelemetryDuration()); + self::assertEquals($expected, $maximumDuration->toDuration()); } }