From 3a9b6b280e4408c3a38a74d9c127b15c75558f2b Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Mon, 6 Oct 2025 15:46:29 +0300 Subject: [PATCH 1/3] Make TimeSpan::__construct() public --- src/TimeSpan.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 1418465739a02244cc67bf2415a2aa15ea07fb94 Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Mon, 6 Oct 2025 15:52:27 +0300 Subject: [PATCH 2/3] Add constructor test --- tests/TimeSpanTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/TimeSpanTest.php b/tests/TimeSpanTest.php index c32dc62..050dc97 100644 --- a/tests/TimeSpanTest.php +++ b/tests/TimeSpanTest.php @@ -179,6 +179,20 @@ 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()); + } + #[TestWith([0, 0])] #[TestWith([0.0, 0])] #[TestWith([100, 100])] From 050f31c4b09efb7f09c068bd5b028998ffc03f9e Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Mon, 6 Oct 2025 15:58:47 +0300 Subject: [PATCH 3/3] Add testConstructorWithoutArgs() --- tests/TimeSpanTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/TimeSpanTest.php b/tests/TimeSpanTest.php index 050dc97..e40630c 100644 --- a/tests/TimeSpanTest.php +++ b/tests/TimeSpanTest.php @@ -193,6 +193,13 @@ public function testConstructor(int $nanoseconds): void 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])]