diff --git a/src/TimeSpan.php b/src/TimeSpan.php index 2c7f25b..d48103f 100644 --- a/src/TimeSpan.php +++ b/src/TimeSpan.php @@ -135,8 +135,8 @@ public static function fromInterval(\DateInterval $interval): self return $timeSpan; } - private function __construct( - private int $nanoseconds, + public function __construct( + private int $nanoseconds = 0, ) {} public function toNanoseconds(): int diff --git a/tests/TimeSpanTest.php b/tests/TimeSpanTest.php index c32dc62..e40630c 100644 --- a/tests/TimeSpanTest.php +++ b/tests/TimeSpanTest.php @@ -179,6 +179,27 @@ public function testItThrowsForDateTimeInterfaceDiffInterval(): void TimeSpan::fromInterval($interval); } + #[TestWith([0])] + #[TestWith([100])] + #[TestWith([-100])] + #[TestWith([PHP_INT_MAX])] + #[TestWith([PHP_INT_MIN])] + #[TestWith([9_223_372_036_854_775_000])] + #[TestWith([-9_223_372_036_854_775_000])] + public function testConstructor(int $nanoseconds): void + { + $span = new TimeSpan($nanoseconds); + + self::assertSame($nanoseconds, $span->toNanoseconds()); + } + + public function testConstructorWithoutArgs(): void + { + $span = new TimeSpan(); + + self::assertSame(0, $span->toNanoseconds()); + } + #[TestWith([0, 0])] #[TestWith([0.0, 0])] #[TestWith([100, 100])]