From acbe935583eea9e3173b68c63828a4e3e15a4796 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Wed, 27 Mar 2024 00:08:29 +0100 Subject: [PATCH] PHPUnit 10 attributes --- tests/Clock/OffsetClockTest.php | 4 +- tests/Clock/ScaleClockTest.php | 4 +- tests/DayOfWeekTest.php | 31 ++---- tests/DurationTest.php | 146 ++++++++-------------------- tests/Field/DayOfMonthTest.php | 5 +- tests/InstantTest.php | 84 ++++++----------- tests/IntervalTest.php | 24 +++-- tests/LocalDateRangeTest.php | 46 +++------ tests/LocalDateTest.php | 123 ++++++++---------------- tests/LocalDateTimeTest.php | 162 ++++++++++---------------------- tests/LocalTimeTest.php | 103 +++++++------------- tests/MonthDayTest.php | 66 +++++-------- tests/MonthTest.php | 32 +++---- tests/PeriodTest.php | 38 +++----- tests/StopwatchTest.php | 33 ++----- tests/TimeZoneOffsetTest.php | 36 +++---- tests/TimeZoneRegionTest.php | 20 ++-- tests/TimeZoneTest.php | 11 +-- tests/Utility/MathTest.php | 7 +- tests/YearMonthRangeTest.php | 27 ++---- tests/YearMonthTest.php | 75 +++++---------- tests/YearTest.php | 65 +++++-------- tests/YearWeekTest.php | 60 ++++-------- tests/ZonedDateTimeTest.php | 58 ++++-------- tools/rector/rector.php | 4 + 25 files changed, 405 insertions(+), 859 deletions(-) diff --git a/tests/Clock/OffsetClockTest.php b/tests/Clock/OffsetClockTest.php index 02a896f2..78a2a5fc 100644 --- a/tests/Clock/OffsetClockTest.php +++ b/tests/Clock/OffsetClockTest.php @@ -9,6 +9,7 @@ use Brick\DateTime\Duration; use Brick\DateTime\Instant; use Brick\DateTime\Tests\AbstractTestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * Unit tests for class OffsetClock. @@ -16,14 +17,13 @@ class OffsetClockTest extends AbstractTestCase { /** - * @dataProvider providerOffsetClock - * * @param int $second The epoch second to set the base clock to. * @param int $nano The nano to set the base clock to. * @param string $duration A parsable duration string. * @param int $expectedSecond The expected epoch second returned by the clock. * @param int $expectedNano The expected nano returned by the clock. */ + #[DataProvider('providerOffsetClock')] public function testOffsetClock(int $second, int $nano, string $duration, int $expectedSecond, int $expectedNano): void { $baseClock = new FixedClock(Instant::of($second, $nano)); diff --git a/tests/Clock/ScaleClockTest.php b/tests/Clock/ScaleClockTest.php index e0a0d697..594e5d32 100644 --- a/tests/Clock/ScaleClockTest.php +++ b/tests/Clock/ScaleClockTest.php @@ -9,6 +9,7 @@ use Brick\DateTime\Duration; use Brick\DateTime\Instant; use Brick\DateTime\Tests\AbstractTestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * Unit tests for class ScaleClock. @@ -16,14 +17,13 @@ class ScaleClockTest extends AbstractTestCase { /** - * @dataProvider providerScaleClock - * * @param int $second The epoch second to set the base clock to. * @param int $nano The nano to set the base clock to. * @param string $duration The time elapsed, as a parsable duration string. * @param int $scale The time scale. * @param string $expectedInstant The expected epoch second returned by the clock. */ + #[DataProvider('providerScaleClock')] public function testScaleClock(int $second, int $nano, string $duration, int $scale, string $expectedInstant): void { $baseInstant = Instant::of($second, $nano); diff --git a/tests/DayOfWeekTest.php b/tests/DayOfWeekTest.php index 8ef94121..ca75afe0 100644 --- a/tests/DayOfWeekTest.php +++ b/tests/DayOfWeekTest.php @@ -10,6 +10,7 @@ use Brick\DateTime\Instant; use Brick\DateTime\TimeZone; use Generator; +use PHPUnit\Framework\Attributes\DataProvider; use function json_encode; @@ -21,11 +22,10 @@ class DayOfWeekTest extends AbstractTestCase { /** - * @dataProvider providerValues - * * @param int $expectedValue The expected value of the constant. * @param DayOfWeek $dayOfWeek The day-of-week instance. */ + #[DataProvider('providerValues')] public function testValues(int $expectedValue, DayOfWeek $dayOfWeek): void { self::assertSame($expectedValue, $dayOfWeek->value); @@ -51,9 +51,7 @@ public function testOf(): void self::assertSame(DayOfWeek::FRIDAY, DayOfWeek::of(DayOfWeek::FRIDAY)); } - /** - * @dataProvider providerOfInvalidDayOfWeekThrowsException - */ + #[DataProvider('providerOfInvalidDayOfWeekThrowsException')] public function testOfInvalidDayOfWeekThrowsException(int $dayOfWeek): void { $this->expectException(DateTimeException::class); @@ -70,12 +68,11 @@ public static function providerOfInvalidDayOfWeekThrowsException(): array } /** - * @dataProvider providerNow - * * @param int $epochSecond The epoch second to set the clock time to. * @param string $timeZone The time-zone to get the current day-of-week in. * @param DayOfWeek $expectedDayOfWeek The expected day-of-week. */ + #[DataProvider('providerNow')] public function testNow(int $epochSecond, string $timeZone, DayOfWeek $expectedDayOfWeek): void { $clock = new FixedClock(Instant::of($epochSecond)); @@ -160,9 +157,7 @@ public function testIsEqualTo(): void } } - /** - * @dataProvider providerIsWeekday - */ + #[DataProvider('providerIsWeekday')] public function testIsWeekday(DayOfWeek $dayOfWeek, bool $isWeekday): void { self::assertSame($isWeekday, $dayOfWeek->isWeekday()); @@ -181,9 +176,7 @@ public static function providerIsWeekday(): array ]; } - /** - * @dataProvider providerIsWeekend - */ + #[DataProvider('providerIsWeekend')] public function testIsWeekend(DayOfWeek $dayOfWeek, bool $isWeekend): void { self::assertSame($isWeekend, $dayOfWeek->isWeekend()); @@ -203,24 +196,22 @@ public static function providerIsWeekend(): array } /** - * @dataProvider providerPlus - * * @param DayOfWeek $dayOfWeek The base day-of-week. * @param int $plusDays The number of days to add. * @param DayOfWeek $expectedDayOfWeek The expected day-of-week. */ + #[DataProvider('providerPlus')] public function testPlus(DayOfWeek $dayOfWeek, int $plusDays, DayOfWeek $expectedDayOfWeek): void { self::assertSame($expectedDayOfWeek, $dayOfWeek->plus($plusDays)); } /** - * @dataProvider providerPlus - * * @param DayOfWeek $dayOfWeek The base day-of-week. * @param int $plusDays The number of days to add. * @param DayOfWeek $expectedDayOfWeek The expected day-of-week. */ + #[DataProvider('providerPlus')] public function testMinus(DayOfWeek $dayOfWeek, int $plusDays, DayOfWeek $expectedDayOfWeek): void { self::assertSame($expectedDayOfWeek, $dayOfWeek->minus(-$plusDays)); @@ -245,22 +236,20 @@ public static function providerPlus(): Generator } /** - * @dataProvider providerToString - * * @param DayOfWeek $dayOfWeek The day-of-week. * @param string $expectedName The expected name. */ + #[DataProvider('providerToString')] public function testJsonSerialize(DayOfWeek $dayOfWeek, string $expectedName): void { self::assertSame(json_encode($expectedName, JSON_THROW_ON_ERROR), json_encode($dayOfWeek, JSON_THROW_ON_ERROR)); } /** - * @dataProvider providerToString - * * @param DayOfWeek $dayOfWeek The day-of-week. * @param string $expectedName The expected name. */ + #[DataProvider('providerToString')] public function testToString(DayOfWeek $dayOfWeek, string $expectedName): void { self::assertSame($expectedName, $dayOfWeek->toString()); diff --git a/tests/DurationTest.php b/tests/DurationTest.php index fbb7fe1e..be0e85f8 100644 --- a/tests/DurationTest.php +++ b/tests/DurationTest.php @@ -9,6 +9,7 @@ use Brick\DateTime\Duration; use Brick\DateTime\Instant; use Brick\DateTime\Parser\DateTimeParseException; +use PHPUnit\Framework\Attributes\DataProvider; use function abs; use function count; @@ -33,13 +34,12 @@ public function testZero(): void } /** - * @dataProvider providerOfSeconds - * * @param int $seconds The duration in seconds. * @param int $nanoAdjustment The nanoseconds adjustment to the duration. * @param int $expectedSeconds The expected adjusted duration seconds. * @param int $expectedNanos The expected adjusted duration nanoseconds. */ + #[DataProvider('providerOfSeconds')] public function testOfSeconds(int $seconds, int $nanoAdjustment, int $expectedSeconds, int $expectedNanos): void { $duration = Duration::ofSeconds($seconds, $nanoAdjustment); @@ -60,9 +60,7 @@ public static function providerOfSeconds(): array ]; } - /** - * @dataProvider providerOfMillis - */ + #[DataProvider('providerOfMillis')] public function testOfMillis(int $millis): void { $duration = Duration::ofMillis($millis); @@ -80,9 +78,7 @@ public static function providerOfMillis(): array ]; } - /** - * @dataProvider providerOfNanos - */ + #[DataProvider('providerOfNanos')] public function testOfNanos(int $nanos, int $expectedSeconds, int $expectedNanos): void { $duration = Duration::ofNanos($nanos); @@ -121,9 +117,7 @@ public function testOfDays(): void } } - /** - * @dataProvider providerBetween - */ + #[DataProvider('providerBetween')] public function testBetween(int $seconds1, int $nanos1, int $seconds2, int $nanos2, int $seconds, int $nanos): void { $i1 = Instant::of($seconds1, $nanos1); @@ -154,12 +148,11 @@ public static function providerBetween(): array } /** - * @dataProvider providerParse - * * @param string $text The string to test. * @param int $seconds The expected seconds. * @param int $nanos The expected nanos. */ + #[DataProvider('providerParse')] public function testParse(string $text, int $seconds, int $nanos): void { self::assertDurationIs($seconds, $nanos, Duration::parse($text)); @@ -254,10 +247,9 @@ public static function providerParse(): array } /** - * @dataProvider providerParseFailureThrowsException - * * @param string $text The string to test. */ + #[DataProvider('providerParseFailureThrowsException')] public function testParseFailureThrowsException(string $text): void { $this->expectException(DateTimeParseException::class); @@ -304,60 +296,55 @@ public static function providerParseFailureThrowsException(): array } /** - * @dataProvider providerCompareToZero - * * @param int $seconds The seconds of the duration. * @param int $nanos The nanos of the duration. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareToZero')] public function testIsZero(int $seconds, int $nanos, int $cmp): void { self::assertSame($cmp === 0, Duration::ofSeconds($seconds, $nanos)->isZero()); } /** - * @dataProvider providerCompareToZero - * * @param int $seconds The seconds of the duration. * @param int $nanos The nanos of the duration. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareToZero')] public function testIsPositive(int $seconds, int $nanos, int $cmp): void { self::assertSame($cmp > 0, Duration::ofSeconds($seconds, $nanos)->isPositive()); } /** - * @dataProvider providerCompareToZero - * * @param int $seconds The seconds of the duration. * @param int $nanos The nanos of the duration. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareToZero')] public function testIsPositiveOrZero(int $seconds, int $nanos, int $cmp): void { self::assertSame($cmp >= 0, Duration::ofSeconds($seconds, $nanos)->isPositiveOrZero()); } /** - * @dataProvider providerCompareToZero - * * @param int $seconds The seconds of the duration. * @param int $nanos The nanos of the duration. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareToZero')] public function testIsNegative(int $seconds, int $nanos, int $cmp): void { self::assertSame($cmp < 0, Duration::ofSeconds($seconds, $nanos)->isNegative()); } /** - * @dataProvider providerCompareToZero - * * @param int $seconds The seconds of the duration. * @param int $nanos The nanos of the duration. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareToZero')] public function testIsNegativeOrZero(int $seconds, int $nanos, int $cmp): void { self::assertSame($cmp <= 0, Duration::ofSeconds($seconds, $nanos)->isNegativeOrZero()); @@ -379,14 +366,13 @@ public static function providerCompareToZero(): array } /** - * @dataProvider providerCompareTo - * * @param int $seconds1 The seconds of the 1st duration. * @param int $nanos1 The nanoseconds of the 1st duration. * @param int $seconds2 The seconds of the 2nd duration. * @param int $nanos2 The nanoseconds of the 2nd duration. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareTo')] public function testCompareTo(int $seconds1, int $nanos1, int $seconds2, int $nanos2, int $cmp): void { $duration1 = Duration::ofSeconds($seconds1, $nanos1); @@ -456,8 +442,6 @@ public static function providerCompareTo(): array } /** - * @dataProvider providerPlus - * * @param int $s1 The 1st duration's seconds. * @param int $n1 The 1st duration's nanoseconds. * @param int $s2 The 2nd duration's seconds. @@ -465,6 +449,7 @@ public static function providerCompareTo(): array * @param int $s The expected seconds. * @param int $n The expected nanoseconds. */ + #[DataProvider('providerPlus')] public function testPlus(int $s1, int $n1, int $s2, int $n2, int $s, int $n): void { $duration1 = Duration::ofSeconds($s1, $n1); @@ -474,8 +459,6 @@ public function testPlus(int $s1, int $n1, int $s2, int $n2, int $s, int $n): vo } /** - * @dataProvider providerPlus - * * @param int $s1 The 1st duration's seconds. * @param int $n1 The 1st duration's nanoseconds. * @param int $s2 The 2nd duration's seconds. @@ -483,6 +466,7 @@ public function testPlus(int $s1, int $n1, int $s2, int $n2, int $s, int $n): vo * @param int $s The expected seconds. * @param int $n The expected nanoseconds. */ + #[DataProvider('providerPlus')] public function testMinus(int $s1, int $n1, int $s2, int $n2, int $s, int $n): void { $duration1 = Duration::ofSeconds($s1, $n1); @@ -551,9 +535,7 @@ public static function providerPlus(): array ]; } - /** - * @dataProvider providerPlusSeconds - */ + #[DataProvider('providerPlusSeconds')] public function testPlusSeconds(int $seconds, int $nanos, int $secondsToAdd, int $expectedSeconds, int $expectedNanos): void { $duration = Duration::ofSeconds($seconds, $nanos)->plusSeconds($secondsToAdd); @@ -586,9 +568,7 @@ public static function providerPlusSeconds(): array ]; } - /** - * @dataProvider providerPlusMinutes - */ + #[DataProvider('providerPlusMinutes')] public function testPlusMinutes(int $seconds, int $minutesToAdd, int $expectedSeconds): void { $duration = Duration::ofSeconds($seconds)->plusMinutes($minutesToAdd); @@ -614,9 +594,7 @@ public static function providerPlusMinutes(): array ]; } - /** - * @dataProvider providerPlusHours - */ + #[DataProvider('providerPlusHours')] public function testPlusHours(int $seconds, int $hoursToAdd, int $expectedSeconds): void { $duration = Duration::ofSeconds($seconds)->plusHours($hoursToAdd); @@ -642,9 +620,7 @@ public static function providerPlusHours(): array ]; } - /** - * @dataProvider providerPlusDays - */ + #[DataProvider('providerPlusDays')] public function testPlusDays(int $seconds, int $daysToAdd, int $expectedSeconds): void { $duration = Duration::ofSeconds($seconds)->plusDays($daysToAdd); @@ -670,9 +646,7 @@ public static function providerPlusDays(): array ]; } - /** - * @dataProvider providerMinusSeconds - */ + #[DataProvider('providerMinusSeconds')] public function testMinusSeconds(int $seconds, int $secondsToSubtract, int $expectedSeconds): void { $duration = Duration::ofSeconds($seconds)->minusSeconds($secondsToSubtract); @@ -701,9 +675,7 @@ public static function providerMinusSeconds(): array ]; } - /** - * @dataProvider providerMinusMinutes - */ + #[DataProvider('providerMinusMinutes')] public function testMinusMinutes(int $seconds, int $minutesToSubtract, int $expectedSeconds): void { $duration = Duration::ofSeconds($seconds)->minusMinutes($minutesToSubtract); @@ -729,9 +701,7 @@ public static function providerMinusMinutes(): array ]; } - /** - * @dataProvider providerMinusHours - */ + #[DataProvider('providerMinusHours')] public function testMinusHours(int $seconds, int $hoursToSubtract, int $expectedSeconds): void { $duration = Duration::ofSeconds($seconds)->minusHours($hoursToSubtract); @@ -757,9 +727,7 @@ public static function providerMinusHours(): array ]; } - /** - * @dataProvider providerMinusDays - */ + #[DataProvider('providerMinusDays')] public function testMinusDays(int $seconds, int $daysToSubtract, int $expectedSeconds): void { $duration = Duration::ofSeconds($seconds)->minusDays($daysToSubtract); @@ -785,9 +753,7 @@ public static function providerMinusDays(): array ]; } - /** - * @dataProvider providerMultipliedBy - */ + #[DataProvider('providerMultipliedBy')] public function testMultipliedBy(int $second, int $nano, int $multiplicand, int $expectedSecond, int $expectedNano): void { $duration = Duration::ofSeconds($second, $nano); @@ -879,9 +845,7 @@ public static function providerMultipliedBy(): array ]; } - /** - * @dataProvider providerDividedBy - */ + #[DataProvider('providerDividedBy')] public function testDividedBy(int $seconds, int $nanos, int $divisor, int $expectedSeconds, int $expectedNanos): void { $duration = Duration::ofSeconds($seconds, $nanos)->dividedBy($divisor); @@ -951,13 +915,12 @@ public function testDividedByZeroThrowsException(): void } /** - * @dataProvider providerNegated - * * @param int $seconds The duration in seconds. * @param int $nanos The nanoseconds adjustment to the duration. * @param int $expectedSeconds The expected seconds of the negated duration. * @param int $expectedNanos The expected nanoseconds adjustment of the negated duration. */ + #[DataProvider('providerNegated')] public function testNegated(int $seconds, int $nanos, int $expectedSeconds, int $expectedNanos): void { $duration = Duration::ofSeconds($seconds, $nanos); @@ -1035,12 +998,11 @@ public function testEquals(): void } /** - * @dataProvider providerGetTotalMillis - * * @param int $seconds The duration in seconds. * @param int $nanos The nanoseconds adjustment to the duration. * @param int $expectedMillis The expected total number of milliseconds. */ + #[DataProvider('providerGetTotalMillis')] public function testGetTotalMillis(int $seconds, int $nanos, int $expectedMillis): void { $duration = Duration::ofSeconds($seconds, $nanos); @@ -1058,12 +1020,11 @@ public static function providerGetTotalMillis(): array } /** - * @dataProvider providerGetTotalMicros - * * @param int $seconds The duration in seconds. * @param int $nanos The nanoseconds adjustment to the duration. * @param int $expectedMicros The expected total number of microseconds. */ + #[DataProvider('providerGetTotalMicros')] public function testGetTotalMicros(int $seconds, int $nanos, int $expectedMicros): void { $duration = Duration::ofSeconds($seconds, $nanos); @@ -1081,12 +1042,11 @@ public static function providerGetTotalMicros(): array } /** - * @dataProvider providerGetTotalNanos - * * @param int $seconds The duration in seconds. * @param int $nanos The nanoseconds adjustment to the duration. * @param int $expectedNanos The expected total number of nanoseconds. */ + #[DataProvider('providerGetTotalNanos')] public function testGetTotalNanos(int $seconds, int $nanos, int $expectedNanos): void { $duration = Duration::ofSeconds($seconds, $nanos); @@ -1103,9 +1063,7 @@ public static function providerGetTotalNanos(): array ]; } - /** - * @dataProvider providerToDaysPart - */ + #[DataProvider('providerToDaysPart')] public function testToDaysPart(Duration $duration, int $days): void { self::assertSame($days, $duration->toDaysPart()); @@ -1123,9 +1081,7 @@ public static function providerToDaysPart(): array ]; } - /** - * @dataProvider providerToHoursPart - */ + #[DataProvider('providerToHoursPart')] public function testToHoursPart(Duration $duration, int $hours): void { self::assertSame($hours, $duration->toHoursPart()); @@ -1142,9 +1098,7 @@ public static function providerToHoursPart(): array ]; } - /** - * @dataProvider providerToMinutesPart - */ + #[DataProvider('providerToMinutesPart')] public function testToMinutesPart(Duration $duration, int $minutes): void { self::assertSame($minutes, $duration->toMinutesPart()); @@ -1161,9 +1115,7 @@ public static function providerToMinutesPart(): array ]; } - /** - * @dataProvider providerToSecondsPart - */ + #[DataProvider('providerToSecondsPart')] public function testToSecondsPart(Duration $duration, int $seconds): void { self::assertSame($seconds, $duration->toSecondsPart()); @@ -1181,9 +1133,7 @@ public static function providerToSecondsPart(): array ]; } - /** - * @dataProvider providerToMillis - */ + #[DataProvider('providerToMillis')] public function testToMillis(Duration $duration, int $millis): void { self::assertSame($millis, $duration->toMillis()); @@ -1200,9 +1150,7 @@ public static function providerToMillis(): array ]; } - /** - * @dataProvider providerToMillisOutOfRange - */ + #[DataProvider('providerToMillisOutOfRange')] public function testToMillisOutOfRange(Duration $duration): void { $this->expectException(ArithmeticError::class); @@ -1217,9 +1165,7 @@ public static function providerToMillisOutOfRange(): array ]; } - /** - * @dataProvider providerToMillisPart - */ + #[DataProvider('providerToMillisPart')] public function testToMillisPart(Duration $duration, int $millis): void { self::assertSame($millis, $duration->toMillisPart()); @@ -1237,9 +1183,7 @@ public static function providerToMillisPart(): array ]; } - /** - * @dataProvider providerToNanos - */ + #[DataProvider('providerToNanos')] public function testToNanos(Duration $duration, int $nanos): void { self::assertSame($nanos, $duration->toNanos()); @@ -1255,9 +1199,7 @@ public static function providerToNanos(): array ]; } - /** - * @dataProvider providerToNanosPart - */ + #[DataProvider('providerToNanosPart')] public function testToNanosPart(Duration $duration, int $nanos): void { self::assertSame($nanos, $duration->toNanosPart()); @@ -1275,25 +1217,19 @@ public static function providerToNanosPart(): array ]; } - /** - * @dataProvider providerToString - */ + #[DataProvider('providerToString')] public function testJsonSerialize(int $seconds, int $nanos, string $expected): void { self::assertSame(json_encode($expected, JSON_THROW_ON_ERROR), json_encode(Duration::ofSeconds($seconds, $nanos), JSON_THROW_ON_ERROR)); } - /** - * @dataProvider providerToString - */ + #[DataProvider('providerToString')] public function testToISOString(int $seconds, int $nanos, string $expected): void { self::assertSame($expected, Duration::ofSeconds($seconds, $nanos)->toISOString()); } - /** - * @dataProvider providerToString - */ + #[DataProvider('providerToString')] public function testToString(int $seconds, int $nanos, string $expected): void { self::assertSame($expected, (string) Duration::ofSeconds($seconds, $nanos)); diff --git a/tests/Field/DayOfMonthTest.php b/tests/Field/DayOfMonthTest.php index 9b6f66d2..489dc915 100644 --- a/tests/Field/DayOfMonthTest.php +++ b/tests/Field/DayOfMonthTest.php @@ -6,15 +6,14 @@ use Brick\DateTime\Field\DayOfMonth; use Brick\DateTime\Tests\AbstractTestCase; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; /** * Unit tests for class DayOfMonth. */ class DayOfMonthTest extends AbstractTestCase { - /** - * @doesNotPerformAssertions - */ + #[DoesNotPerformAssertions] public function testCheckWithNullMonthOfYear(): void { DayOfMonth::check(31); diff --git a/tests/InstantTest.php b/tests/InstantTest.php index 2e65de72..1e3a0429 100644 --- a/tests/InstantTest.php +++ b/tests/InstantTest.php @@ -9,6 +9,7 @@ use Brick\DateTime\Duration; use Brick\DateTime\Instant; use Brick\DateTime\TimeZone; +use PHPUnit\Framework\Attributes\DataProvider; use function json_encode; @@ -22,13 +23,12 @@ class InstantTest extends AbstractTestCase { /** - * @dataProvider providerOf - * * @param int $seconds The duration in seconds. * @param int $nanoAdjustment The nanoseconds adjustment to the duration. * @param int $expectedSeconds The expected adjusted duration seconds. * @param int $expectedNanos The expected adjusted duration nanoseconds. */ + #[DataProvider('providerOf')] public function testOf(int $seconds, int $nanoAdjustment, int $expectedSeconds, int $expectedNanos): void { $duration = Instant::of($seconds, $nanoAdjustment); @@ -82,8 +82,6 @@ public function testMax(): void } /** - * @dataProvider providerPlus - * * @param int $second The base second. * @param int $nano The base nano-of-second. * @param int $plusSeconds The seconds of the duration to add. @@ -91,6 +89,7 @@ public function testMax(): void * @param int $expectedSecond The expected second of the result. * @param int $expectedNano The expected nano of the result. */ + #[DataProvider('providerPlus')] public function testPlus(int $second, int $nano, int $plusSeconds, int $plusNanos, int $expectedSecond, int $expectedNano): void { $result = Instant::of($second, $nano)->plus(Duration::ofSeconds($plusSeconds, $plusNanos)); @@ -98,8 +97,6 @@ public function testPlus(int $second, int $nano, int $plusSeconds, int $plusNano } /** - * @dataProvider providerPlus - * * @param int $second The base second. * @param int $nano The base nano-of-second. * @param int $plusSeconds The seconds of the duration to add. @@ -107,6 +104,7 @@ public function testPlus(int $second, int $nano, int $plusSeconds, int $plusNano * @param int $expectedSecond The expected second of the result. * @param int $expectedNano The expected nano of the result. */ + #[DataProvider('providerPlus')] public function testMinus(int $second, int $nano, int $plusSeconds, int $plusNanos, int $expectedSecond, int $expectedNano): void { $result = Instant::of($second, $nano)->minus(Duration::ofSeconds(-$plusSeconds, -$plusNanos)); @@ -125,13 +123,12 @@ public static function providerPlus(): array } /** - * @dataProvider providerPlusSeconds - * * @param int $second The base second. * @param int $nano The base nano-of-second. * @param int $plusSeconds The number of seconds to add. * @param int $expectedSecond The expected second of the result. */ + #[DataProvider('providerPlusSeconds')] public function testPlusSeconds(int $second, int $nano, int $plusSeconds, int $expectedSecond): void { $result = Instant::of($second, $nano)->plusSeconds($plusSeconds); @@ -139,13 +136,12 @@ public function testPlusSeconds(int $second, int $nano, int $plusSeconds, int $e } /** - * @dataProvider providerPlusSeconds - * * @param int $second The base second. * @param int $nano The base nano-of-second. * @param int $plusSeconds The number of seconds to add. * @param int $expectedSecond The expected second of the result. */ + #[DataProvider('providerPlusSeconds')] public function testMinusSeconds(int $second, int $nano, int $plusSeconds, int $expectedSecond): void { $result = Instant::of($second, $nano)->minusSeconds(-$plusSeconds); @@ -166,13 +162,12 @@ public static function providerPlusSeconds(): array } /** - * @dataProvider providerPlusMinutes - * * @param int $second The base second. * @param int $nano The base nano-of-second. * @param int $plusMinutes The number of minutes to add. * @param int $expectedSecond The expected second of the result. */ + #[DataProvider('providerPlusMinutes')] public function testPlusMinutes(int $second, int $nano, int $plusMinutes, int $expectedSecond): void { $result = Instant::of($second, $nano)->plusMinutes($plusMinutes); @@ -180,13 +175,12 @@ public function testPlusMinutes(int $second, int $nano, int $plusMinutes, int $e } /** - * @dataProvider providerPlusMinutes - * * @param int $second The base second. * @param int $nano The base nano-of-second. * @param int $plusMinutes The number of minutes to add. * @param int $expectedSecond The expected second of the result. */ + #[DataProvider('providerPlusMinutes')] public function testMinusMinutes(int $second, int $nano, int $plusMinutes, int $expectedSecond): void { $result = Instant::of($second, $nano)->minusMinutes(-$plusMinutes); @@ -207,13 +201,12 @@ public static function providerPlusMinutes(): array } /** - * @dataProvider providerPlusHours - * * @param int $second The base second. * @param int $nano The base nano-of-second. * @param int $plusHours The number of hours to add. * @param int $expectedSecond The expected second of the result. */ + #[DataProvider('providerPlusHours')] public function testPlusHours(int $second, int $nano, int $plusHours, int $expectedSecond): void { $result = Instant::of($second, $nano)->plusHours($plusHours); @@ -221,13 +214,12 @@ public function testPlusHours(int $second, int $nano, int $plusHours, int $expec } /** - * @dataProvider providerPlusHours - * * @param int $second The base second. * @param int $nano The base nano-of-second. * @param int $plusHours The number of hours to add. * @param int $expectedSecond The expected second of the result. */ + #[DataProvider('providerPlusHours')] public function testMinusHours(int $second, int $nano, int $plusHours, int $expectedSecond): void { $result = Instant::of($second, $nano)->minusHours(-$plusHours); @@ -248,13 +240,12 @@ public static function providerPlusHours(): array } /** - * @dataProvider providerPlusDays - * * @param int $second The base second. * @param int $nano The base nano-of-second. * @param int $plusDays The number of days to add. * @param int $expectedSecond The expected second of the result. */ + #[DataProvider('providerPlusDays')] public function testPlusDays(int $second, int $nano, int $plusDays, int $expectedSecond): void { $result = Instant::of($second, $nano)->plusDays($plusDays); @@ -262,13 +253,12 @@ public function testPlusDays(int $second, int $nano, int $plusDays, int $expecte } /** - * @dataProvider providerPlusDays - * * @param int $second The base second. * @param int $nano The base nano-of-second. * @param int $plusDays The number of days to add. * @param int $expectedSecond The expected second of the result. */ + #[DataProvider('providerPlusDays')] public function testMinusDays(int $second, int $nano, int $plusDays, int $expectedSecond): void { $result = Instant::of($second, $nano)->minusDays(-$plusDays); @@ -300,9 +290,7 @@ public function testWithNano(): void self::assertInstantIs(1234567890, 123456789, $instant->withNano(123456789)); } - /** - * @dataProvider providerWithInvalidNanoThrowsException - */ + #[DataProvider('providerWithInvalidNanoThrowsException')] public function testWithInvalidNanoThrowsException(int $nano): void { $instant = Instant::of(1234567890, 987654321); @@ -320,98 +308,91 @@ public static function providerWithInvalidNanoThrowsException(): array } /** - * @dataProvider providerCompareTo - * * @param int $s1 The epoch second of the 1st instant. * @param int $n1 The nanosecond adjustment of the 1st instant. * @param int $s2 The epoch second of the 2nd instant. * @param int $n2 The nanosecond adjustment of the 2nd instant. * @param int $cmp The expected comparison value. */ + #[DataProvider('providerCompareTo')] public function testCompareTo(int $s1, int $n1, int $s2, int $n2, int $cmp): void { self::assertSame($cmp, Instant::of($s1, $n1)->compareTo(Instant::of($s2, $n2))); } /** - * @dataProvider providerCompareTo - * * @param int $s1 The epoch second of the 1st instant. * @param int $n1 The nanosecond adjustment of the 1st instant. * @param int $s2 The epoch second of the 2nd instant. * @param int $n2 The nanosecond adjustment of the 2nd instant. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareTo')] public function testIsEqualTo(int $s1, int $n1, int $s2, int $n2, int $cmp): void { self::assertSame($cmp === 0, Instant::of($s1, $n1)->isEqualTo(Instant::of($s2, $n2))); } /** - * @dataProvider providerCompareTo - * * @param int $s1 The epoch second of the 1st instant. * @param int $n1 The nanosecond adjustment of the 1st instant. * @param int $s2 The epoch second of the 2nd instant. * @param int $n2 The nanosecond adjustment of the 2nd instant. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareTo')] public function testIsAfter(int $s1, int $n1, int $s2, int $n2, int $cmp): void { self::assertSame($cmp === 1, Instant::of($s1, $n1)->isAfter(Instant::of($s2, $n2))); } /** - * @dataProvider providerCompareTo - * * @param int $s1 The epoch second of the 1st instant. * @param int $n1 The nanosecond adjustment of the 1st instant. * @param int $s2 The epoch second of the 2nd instant. * @param int $n2 The nanosecond adjustment of the 2nd instant. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareTo')] public function testIsAfterOrEqualTo(int $s1, int $n1, int $s2, int $n2, int $cmp): void { self::assertSame($cmp >= 0, Instant::of($s1, $n1)->isAfterOrEqualTo(Instant::of($s2, $n2))); } /** - * @dataProvider providerCompareTo - * * @param int $s1 The epoch second of the 1st instant. * @param int $n1 The nanosecond adjustment of the 1st instant. * @param int $s2 The epoch second of the 2nd instant. * @param int $n2 The nanosecond adjustment of the 2nd instant. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareTo')] public function testIsBefore(int $s1, int $n1, int $s2, int $n2, int $cmp): void { self::assertSame($cmp === -1, Instant::of($s1, $n1)->isBefore(Instant::of($s2, $n2))); } /** - * @dataProvider providerCompareTo - * * @param int $s1 The epoch second of the 1st instant. * @param int $n1 The nanosecond adjustment of the 1st instant. * @param int $s2 The epoch second of the 2nd instant. * @param int $n2 The nanosecond adjustment of the 2nd instant. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareTo')] public function testIsBeforeOrEqualTo(int $s1, int $n1, int $s2, int $n2, int $cmp): void { self::assertSame($cmp <= 0, Instant::of($s1, $n1)->isBeforeOrEqualTo(Instant::of($s2, $n2))); } /** - * @dataProvider providerCompareTo - * * @param int $testSecond The second of the test instant. * @param int $testNano The nanosecond adjustment to the test instant. * @param int $nowSecond The second of the current time. * @param int $nowNano The nanosecond adjustment to the current time. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareTo')] public function testIsFuture(int $testSecond, int $testNano, int $nowSecond, int $nowNano, int $cmp): void { $clock = new FixedClock(Instant::of($nowSecond, $nowNano)); @@ -419,14 +400,13 @@ public function testIsFuture(int $testSecond, int $testNano, int $nowSecond, int } /** - * @dataProvider providerCompareTo - * * @param int $testSecond The second of the test instant. * @param int $testNano The nanosecond adjustment to the test instant. * @param int $nowSecond The second of the current time. * @param int $nowNano The nanosecond adjustment to the current time. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareTo')] public function testIsPast(int $testSecond, int $testNano, int $nowSecond, int $nowNano, int $cmp): void { $clock = new FixedClock(Instant::of($nowSecond, $nowNano)); @@ -521,12 +501,11 @@ public static function providerCompareTo(): array } /** - * @dataProvider providerIsBetweenInclusive - * * @param int $seconds The seconds value. * @param int $nanos The nano seconds value. * @param bool $isBetween Check the secs and nanos are between. */ + #[DataProvider('providerIsBetweenInclusive')] public function testIsBetweenInclusive(int $seconds, int $nanos, bool $isBetween): void { self::assertSame($isBetween, Instant::of($seconds, $nanos)->isBetweenInclusive( @@ -536,12 +515,11 @@ public function testIsBetweenInclusive(int $seconds, int $nanos, bool $isBetween } /** - * @dataProvider providerIsBetweenExclusive - * * @param int $seconds The seconds value. * @param int $nanos The nano seconds value. * @param bool $isBetween Check the secs and nanos are between. */ + #[DataProvider('providerIsBetweenExclusive')] public function testIsBetweenExclusive(int $seconds, int $nanos, bool $isBetween): void { self::assertSame($isBetween, Instant::of($seconds, $nanos)->isBetweenExclusive( @@ -584,9 +562,7 @@ public static function providerIsBetweenInclusive(): array ]; } - /** - * @dataProvider providerGetIntervalTo - */ + #[DataProvider('providerGetIntervalTo')] public function testGetIntervalTo(int $second1, int $nano1, int $second2, int $nano2, string $expectedInterval): void { $actualResult = Instant::of($second1, $nano1)->getIntervalTo(Instant::of($second2, $nano2)); @@ -606,12 +582,11 @@ public static function providerGetIntervalTo(): array } /** - * @dataProvider providerToDecimal - * * @param int $second The epoch second. * @param int $nano The nano adjustment. * @param string $expected The expected decimal output. */ + #[DataProvider('providerToDecimal')] public function testToDecimal(int $second, int $nano, string $expected): void { self::assertSame($expected, Instant::of($second, $nano)->toDecimal()); @@ -635,36 +610,33 @@ public static function providerToDecimal(): array } /** - * @dataProvider providerToString - * * @param int $epochSecond The epoch second to test. * @param int $nano The nano adjustment to the epoch second. * @param string $expectedString The expected string output. */ + #[DataProvider('providerToString')] public function testJsonSerialize(int $epochSecond, int $nano, string $expectedString): void { self::assertSame(json_encode($expectedString, JSON_THROW_ON_ERROR), json_encode(Instant::of($epochSecond, $nano), JSON_THROW_ON_ERROR)); } /** - * @dataProvider providerToString - * * @param int $epochSecond The epoch second to test. * @param int $nano The nano adjustment to the epoch second. * @param string $expectedString The expected string output. */ + #[DataProvider('providerToString')] public function testToISOString(int $epochSecond, int $nano, string $expectedString): void { self::assertSame($expectedString, Instant::of($epochSecond, $nano)->toISOString()); } /** - * @dataProvider providerToString - * * @param int $epochSecond The epoch second to test. * @param int $nano The nano adjustment to the epoch second. * @param string $expectedString The expected string output. */ + #[DataProvider('providerToString')] public function testToString(int $epochSecond, int $nano, string $expectedString): void { self::assertSame($expectedString, (string) Instant::of($epochSecond, $nano)); diff --git a/tests/IntervalTest.php b/tests/IntervalTest.php index 26f54909..9fc47241 100644 --- a/tests/IntervalTest.php +++ b/tests/IntervalTest.php @@ -7,6 +7,8 @@ use Brick\DateTime\DateTimeException; use Brick\DateTime\Instant; use Brick\DateTime\Interval; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; use function json_encode; @@ -39,9 +41,7 @@ public function testGetStartEnd(): void self::assertInstantIs(2000000009, 123456789, $interval->getEnd()); } - /** - * @depends testGetStartEnd - */ + #[Depends('testGetStartEnd')] public function testWithStart(): void { $interval = Interval::of( @@ -62,9 +62,7 @@ public function testWithStart(): void self::assertInstantIs(2000000001, 0, $newInterval->getEnd()); } - /** - * @depends testGetStartEnd - */ + #[Depends('testGetStartEnd')] public function testWithEnd(): void { $interval = Interval::of( @@ -97,7 +95,7 @@ public function testGetDuration(): void self::assertDurationIs(1, 999444556, $duration); } - /** @dataProvider providerContains */ + #[DataProvider('providerContains')] public function testContains(int $start, int $end, int $now, bool $expected, string $errorMessage): void { $interval = Interval::of(Instant::of($start), Instant::of($end)); @@ -132,7 +130,7 @@ public static function providerContains(): array ]; } - /** @dataProvider providerIntersectsWith */ + #[DataProvider('providerIntersectsWith')] public function testIntersectsWith(int $start1, int $end1, int $start2, int $end2, bool $expected): void { $interval1 = Interval::of(Instant::of($start1), Instant::of($end1)); @@ -171,7 +169,7 @@ public static function providerIntersectsWith(): array ]; } - /** @dataProvider providerGetIntersectionWith */ + #[DataProvider('providerGetIntersectionWith')] public function testGetIntersectionWith( int $start1, int $end1, @@ -229,7 +227,7 @@ public function testGetIntersectionWithInvalidParams(): void $interval1->getIntersectionWith($interval2); } - /** @dataProvider providerIsEqualTo */ + #[DataProvider('providerIsEqualTo')] public function testIsEqualTo(Interval $a, Interval $b, bool $expectedResult): void { self::assertSame($expectedResult, $a->isEqualTo($b)); @@ -262,7 +260,7 @@ public static function providerIsEqualTo(): array ]; } - /** @dataProvider providerToString */ + #[DataProvider('providerToString')] public function testJsonSerialize(int $epochSecondStart, int $epochSecondEnd, string $expectedString): void { $interval = Interval::of( @@ -273,7 +271,7 @@ public function testJsonSerialize(int $epochSecondStart, int $epochSecondEnd, st self::assertSame(json_encode($expectedString, JSON_THROW_ON_ERROR), json_encode($interval, JSON_THROW_ON_ERROR)); } - /** @dataProvider providerToString */ + #[DataProvider('providerToString')] public function testToISOString(int $epochSecondStart, int $epochSecondEnd, string $expectedString): void { $interval = Interval::of( @@ -284,7 +282,7 @@ public function testToISOString(int $epochSecondStart, int $epochSecondEnd, stri self::assertSame($expectedString, $interval->toISOString()); } - /** @dataProvider providerToString */ + #[DataProvider('providerToString')] public function testToString(int $epochSecondStart, int $epochSecondEnd, string $expectedString): void { $interval = Interval::of( diff --git a/tests/LocalDateRangeTest.php b/tests/LocalDateRangeTest.php index 8374d447..f9be4082 100644 --- a/tests/LocalDateRangeTest.php +++ b/tests/LocalDateRangeTest.php @@ -8,6 +8,7 @@ use Brick\DateTime\LocalDate; use Brick\DateTime\LocalDateRange; use Brick\DateTime\Parser\DateTimeParseException; +use PHPUnit\Framework\Attributes\DataProvider; use function array_map; use function iterator_count; @@ -40,8 +41,6 @@ public function testOfInvalidRangeThrowsException(): void } /** - * @dataProvider providerParse - * * @param string $text The text to parse. * @param int $y1 The expected start year. * @param int $m1 The expected start month. @@ -50,6 +49,7 @@ public function testOfInvalidRangeThrowsException(): void * @param int $m2 The expected end month. * @param int $d2 The expected end day. */ + #[DataProvider('providerParse')] public function testParse(string $text, int $y1, int $m1, int $d1, int $y2, int $m2, int $d2): void { self::assertLocalDateRangeIs($y1, $m1, $d1, $y2, $m2, $d2, LocalDateRange::parse($text)); @@ -65,10 +65,9 @@ public static function providerParse(): array } /** - * @dataProvider providerParseInvalidRangeThrowsException - * * @param string $text The invalid text to parse. */ + #[DataProvider('providerParseInvalidRangeThrowsException')] public function testParseInvalidRangeThrowsException(string $text): void { $this->expectException(DateTimeParseException::class); @@ -92,11 +91,10 @@ public static function providerParseInvalidRangeThrowsException(): array } /** - * @dataProvider providerIsEqualTo - * * @param string $testRange The string representation of the range to test. * @param bool $isEqual Whether this range is expected to be equal to our range. */ + #[DataProvider('providerIsEqualTo')] public function testIsEqualTo(string $testRange, bool $isEqual): void { self::assertSame($isEqual, LocalDateRange::of( @@ -118,9 +116,7 @@ public static function providerIsEqualTo(): array ]; } - /** - * @dataProvider providerContains - */ + #[DataProvider('providerContains')] public function testContains(string $range, string $date, bool $contains): void { self::assertSame($contains, LocalDateRange::parse($range)->contains(LocalDate::parse($date))); @@ -169,11 +165,10 @@ public function testIterator(): void } /** - * @dataProvider providerCount - * * @param string $range The date range string representation. * @param int $count The expected day count. */ + #[DataProvider('providerCount')] public function testCount(string $range, int $count): void { self::assertCount($count, LocalDateRange::parse($range)); @@ -191,7 +186,7 @@ public static function providerCount(): array ]; } - /** @dataProvider providerToString */ + #[DataProvider('providerToString')] public function testJsonSerialize( int $yearStart, int $monthStart, @@ -209,7 +204,7 @@ public function testJsonSerialize( self::assertSame(json_encode($expectedString, JSON_THROW_ON_ERROR), json_encode($dateRange, JSON_THROW_ON_ERROR)); } - /** @dataProvider providerToString */ + #[DataProvider('providerToString')] public function testToISOString( int $yearStart, int $monthStart, @@ -227,7 +222,7 @@ public function testToISOString( self::assertSame($expectedString, $dateRange->toISOString()); } - /** @dataProvider providerToString */ + #[DataProvider('providerToString')] public function testToString( int $yearStart, int $monthStart, @@ -254,12 +249,11 @@ public static function providerToString(): array } /** - * @dataProvider providerToNativeDatePeriod - * * @param string $range The date-time string that will be parse()d by LocalDateRange. * @param string $expectedStart The expected output from the native DateTime object. * @param string $expectedEnd The expected output from the native DateTime object. */ + #[DataProvider('providerToNativeDatePeriod')] public function testToNativeDatePeriod(string $range, string $expectedStart, string $expectedEnd): void { $range = LocalDateRange::parse($range); @@ -288,9 +282,7 @@ public static function providerToNativeDatePeriod(): array ]; } - /** - * @dataProvider providerIntersectsWith - */ + #[DataProvider('providerIntersectsWith')] public function testIntersectsWith(string $a, string $b, bool $expectedResult): void { $aRange = LocalDateRange::parse($a); @@ -315,9 +307,7 @@ public static function providerIntersectsWith(): array ]; } - /** - * @dataProvider providerGetIntersectionWith - */ + #[DataProvider('providerGetIntersectionWith')] public function testGetIntersectionWith(string $a, string $b, string $expectedIntersection): void { $aRange = LocalDateRange::parse($a); @@ -349,9 +339,7 @@ public function testGetIntersectionInvalidParams(): void $aRange->getIntersectionWith($bRange); } - /** - * @dataProvider providerWithStart - */ + #[DataProvider('providerWithStart')] public function testWithStart(string $originalRange, string $start, ?string $expectedRange): void { $originalRange = LocalDateRange::parse($originalRange); @@ -380,9 +368,7 @@ public static function providerWithStart(): array ]; } - /** - * @dataProvider providerWithEnd - */ + #[DataProvider('providerWithEnd')] public function testWithEnd(string $originalRange, string $end, ?string $expectedRange): void { $originalRange = LocalDateRange::parse($originalRange); @@ -410,9 +396,7 @@ public static function providerWithEnd(): array ]; } - /** - * @dataProvider providerToPeriod - */ + #[DataProvider('providerToPeriod')] public function testToPeriod(string $dateRange, string $expectedPeriod): void { $dateRange = LocalDateRange::parse($dateRange); diff --git a/tests/LocalDateTest.php b/tests/LocalDateTest.php index 4adf7503..b0c7e7f6 100644 --- a/tests/LocalDateTest.php +++ b/tests/LocalDateTest.php @@ -15,6 +15,7 @@ use Brick\DateTime\Year; use DateTime; use DateTimeImmutable; +use PHPUnit\Framework\Attributes\DataProvider; use function json_encode; @@ -33,12 +34,11 @@ public function testOf(): void } /** - * @dataProvider providerOfInvalidDateThrowsException - * * @param int $year The year of the invalid date. * @param int $month The month of the invalid date. * @param int $day The day of the invalid date. */ + #[DataProvider('providerOfInvalidDateThrowsException')] public function testOfInvalidDateThrowsException(int $year, int $month, int $day): void { $this->expectException(DateTimeException::class); @@ -60,11 +60,10 @@ public static function providerOfInvalidDateThrowsException(): array } /** - * @dataProvider providerOfInvalidYearDayThrowsException - * * @param int $year The year. * @param int $dayOfYear The day-of-year. */ + #[DataProvider('providerOfInvalidYearDayThrowsException')] public function testOfInvalidYearDayThrowsException(int $year, int $dayOfYear): void { $this->expectException(DateTimeException::class); @@ -83,13 +82,12 @@ public static function providerOfInvalidYearDayThrowsException(): array } /** - * @dataProvider providerEpochDay - * * @param int $epochDay The epoch day. * @param int $year The expected year. * @param int $month The expected month. * @param int $day The expected day. */ + #[DataProvider('providerEpochDay')] public function testOfEpochDay(int $epochDay, int $year, int $month, int $day): void { self::assertLocalDateIs($year, $month, $day, LocalDate::ofEpochDay($epochDay)); @@ -102,13 +100,12 @@ public function testOfEpochDayOutOfRangeThrowsException(): void } /** - * @dataProvider providerEpochDay - * * @param int $epochDay The expected epoch day. * @param int $year The year. * @param int $month The month. * @param int $day The day. */ + #[DataProvider('providerEpochDay')] public function testToEpochDay(int $epochDay, int $year, int $month, int $day): void { self::assertSame($epochDay, LocalDate::of($year, $month, $day)->toEpochDay()); @@ -142,14 +139,13 @@ public function testFromNativeDateTime(): void } /** - * @dataProvider providerNow - * * @param int $epochSecond The epoch second to set the clock to. * @param string $timeZone The time-zone to get the date in. * @param int $year The expected year. * @param int $month The expected month. * @param int $day The expected day. */ + #[DataProvider('providerNow')] public function testNow(int $epochSecond, string $timeZone, int $year, int $month, int $day): void { $clock = new FixedClock(Instant::of($epochSecond)); @@ -182,9 +178,7 @@ public function testMax(): void self::assertSame($max, LocalDate::max()); } - /** - * @dataProvider providerGetYearMonth - */ + #[DataProvider('providerGetYearMonth')] public function testGetYearMonth(int $year, int $month, int $day): void { self::assertYearMonthIs($year, $month, LocalDate::of($year, $month, $day)->getYearMonth()); @@ -200,11 +194,10 @@ public static function providerGetYearMonth(): array } /** - * @dataProvider providerDayOfWeek - * * @param string $localDate The local date to test, as a string. * @param DayOfWeek $dayOfWeek The expected day-of-week. */ + #[DataProvider('providerDayOfWeek')] public function testGetDayOfWeek(string $localDate, DayOfWeek $dayOfWeek): void { self::assertSame($dayOfWeek, LocalDate::parse($localDate)->getDayOfWeek()); @@ -253,26 +246,24 @@ public static function providerDayOfWeek(): array } /** - * @dataProvider providerDayOfYear - * * @param int $year The year. * @param int $month The expected month. * @param int $day The expected day. * @param int $dayOfYear The day-of-year. */ + #[DataProvider('providerDayOfYear')] public function testOfYearDay(int $year, int $month, int $day, int $dayOfYear): void { self::assertLocalDateIs($year, $month, $day, LocalDate::ofYearDay($year, $dayOfYear)); } /** - * @dataProvider providerDayOfYear - * * @param int $year The year to test. * @param int $month The month to test. * @param int $day The day-of-month to test. * @param int $dayOfYear The expected day-of-year number. */ + #[DataProvider('providerDayOfYear')] public function testGetDayOfYear(int $year, int $month, int $day, int $dayOfYear): void { self::assertSame($dayOfYear, LocalDate::of($year, $month, $day)->getDayOfYear()); @@ -474,9 +465,7 @@ public static function providerGetYearWeek(): array ]; } - /** - * @dataProvider providerGetYearWeek - */ + #[DataProvider('providerGetYearWeek')] public function testGetYearWeek(int $year, int $month, int $day, int $expectedYear, int $expectedWeek): void { $yearWeek = LocalDate::of($year, $month, $day)->getYearWeek(); @@ -484,14 +473,13 @@ public function testGetYearWeek(int $year, int $month, int $day, int $expectedYe } /** - * @dataProvider providerWithYear - * * @param int $year The base year. * @param int $month The base month. * @param int $day The base day-of-month. * @param int $newYear The new year. * @param int $expectedDay The expected day-of-month of the resulting date. */ + #[DataProvider('providerWithYear')] public function testWithYear(int $year, int $month, int $day, int $newYear, int $expectedDay): void { $localDate = LocalDate::of($year, $month, $day)->withYear($newYear); @@ -511,10 +499,9 @@ public static function providerWithYear(): array } /** - * @dataProvider providerWithInvalidYearThrowsException - * * @param int $invalidYear The year to test. */ + #[DataProvider('providerWithInvalidYearThrowsException')] public function testWithInvalidYearThrowsException(int $invalidYear): void { $this->expectException(DateTimeException::class); @@ -530,14 +517,13 @@ public static function providerWithInvalidYearThrowsException(): array } /** - * @dataProvider providerWithMonth - * * @param int $year The base year. * @param int $month The base month. * @param int $day The base day-of-month. * @param int $newMonth The new month. * @param int $expectedDay The expected day-of-month of the resulting date. */ + #[DataProvider('providerWithMonth')] public function testWithMonth(int $year, int $month, int $day, int $newMonth, int $expectedDay): void { $localDate = LocalDate::of($year, $month, $day)->withMonth($newMonth); @@ -565,10 +551,9 @@ public static function providerWithMonth(): array } /** - * @dataProvider providerWithInvalidYearThrowsException - * * @param int $invalidMonth The month to test. */ + #[DataProvider('providerWithInvalidYearThrowsException')] public function testWithInvalidMonthThrowsException(int $invalidMonth): void { $this->expectException(DateTimeException::class); @@ -584,13 +569,12 @@ public static function providerWithInvalidMonthThrowsException(): array } /** - * @dataProvider providerWithDay - * * @param int $year The base year. * @param int $month The base month. * @param int $day The base day-of-month. * @param int $newDay The new day-of-month. */ + #[DataProvider('providerWithDay')] public function testWithDay(int $year, int $month, int $day, int $newDay): void { $localDate = LocalDate::of($year, $month, $day)->withDay($newDay); @@ -608,13 +592,12 @@ public static function providerWithDay(): array } /** - * @dataProvider providerWithInvalidDayThrowsException - * * @param int $year The base year. * @param int $month The base month. * @param int $day The base day-of-month. * @param int $newDay The new day-of-month. */ + #[DataProvider('providerWithInvalidDayThrowsException')] public function testWithInvalidDayThrowsException(int $year, int $month, int $day, int $newDay): void { $this->expectException(DateTimeException::class); @@ -633,8 +616,6 @@ public static function providerWithInvalidDayThrowsException(): array } /** - * @dataProvider providerPeriod - * * @param int $y The year of the base date. * @param int $m The month of the base date. * @param int $d The day of the base date. @@ -645,6 +626,7 @@ public static function providerWithInvalidDayThrowsException(): array * @param int $em The expected month of the result date. * @param int $ed The expected day of the result date. */ + #[DataProvider('providerPeriod')] public function testPlusPeriod(int $y, int $m, int $d, int $py, int $pm, int $pd, int $ey, int $em, int $ed): void { $date = LocalDate::of($y, $m, $d); @@ -654,8 +636,6 @@ public function testPlusPeriod(int $y, int $m, int $d, int $py, int $pm, int $pd } /** - * @dataProvider providerPeriod - * * @param int $y The year of the base date. * @param int $m The month of the base date. * @param int $d The day of the base date. @@ -666,6 +646,7 @@ public function testPlusPeriod(int $y, int $m, int $d, int $py, int $pm, int $pd * @param int $em The expected month of the result date. * @param int $ed The expected day of the result date. */ + #[DataProvider('providerPeriod')] public function testMinusPeriod(int $y, int $m, int $d, int $py, int $pm, int $pd, int $ey, int $em, int $ed): void { $date = LocalDate::of($y, $m, $d); @@ -692,8 +673,6 @@ public static function providerPeriod(): array } /** - * @dataProvider providerPlusYears - * * @param int $y The base year. * @param int $m The base month. * @param int $d The base day. @@ -702,6 +681,7 @@ public static function providerPeriod(): array * @param int $em The expected resulting month. * @param int $ed The expected resulting day. */ + #[DataProvider('providerPlusYears')] public function testPlusYears(int $y, int $m, int $d, int $ay, int $ey, int $em, int $ed): void { self::assertLocalDateIs($ey, $em, $ed, LocalDate::of($y, $m, $d)->plusYears($ay)); @@ -719,8 +699,6 @@ public static function providerPlusYears(): array } /** - * @dataProvider providerPlusMonths - * * @param int $y The base year. * @param int $m The base month. * @param int $d The base day. @@ -729,6 +707,7 @@ public static function providerPlusYears(): array * @param int $em The expected resulting month. * @param int $ed The expected resulting day. */ + #[DataProvider('providerPlusMonths')] public function testPlusMonths(int $y, int $m, int $d, int $am, int $ey, int $em, int $ed): void { self::assertLocalDateIs($ey, $em, $ed, LocalDate::of($y, $m, $d)->plusMonths($am)); @@ -755,8 +734,6 @@ public static function providerPlusMonths(): array } /** - * @dataProvider providerPlusWeeks - * * @param int $y The base year. * @param int $m The base month. * @param int $d The base day. @@ -765,6 +742,7 @@ public static function providerPlusMonths(): array * @param int $em The expected resulting month. * @param int $ed The expected resulting day. */ + #[DataProvider('providerPlusWeeks')] public function testPlusWeeks(int $y, int $m, int $d, int $aw, int $ey, int $em, int $ed): void { self::assertLocalDateIs($ey, $em, $ed, LocalDate::of($y, $m, $d)->plusWeeks($aw)); @@ -784,8 +762,6 @@ public static function providerPlusWeeks(): array } /** - * @dataProvider providerPlusDays - * * @param int $y The base year. * @param int $m The base month. * @param int $d The base day. @@ -794,6 +770,7 @@ public static function providerPlusWeeks(): array * @param int $em The expected resulting month. * @param int $ed The expected resulting day. */ + #[DataProvider('providerPlusDays')] public function testPlusDays(int $y, int $m, int $d, int $ad, int $ey, int $em, int $ed): void { self::assertLocalDateIs($ey, $em, $ed, LocalDate::of($y, $m, $d)->plusDays($ad)); @@ -819,17 +796,13 @@ public static function providerPlusDays(): array ]; } - /** - * @dataProvider providerPlusWeekdays - */ + #[DataProvider('providerPlusWeekdays')] public function testPlusWeekdays(string $date, int $days, string $expectedDate): void { self::assertSame($expectedDate, (string) LocalDate::parse($date)->plusWeekdays($days)); } - /** - * @dataProvider providerPlusWeekdays - */ + #[DataProvider('providerPlusWeekdays')] public function testMinusWeekdays(string $date, int $days, string $expectedDate): void { self::assertSame($expectedDate, (string) LocalDate::parse($date)->minusWeekdays(-$days)); @@ -998,8 +971,6 @@ public static function providerPlusWeekdays(): array } /** - * @dataProvider providerMinusYears - * * @param int $y The base year. * @param int $m The base month. * @param int $d The base day. @@ -1008,6 +979,7 @@ public static function providerPlusWeekdays(): array * @param int $em The expected resulting month. * @param int $ed The expected resulting day. */ + #[DataProvider('providerMinusYears')] public function tesMinusYears(int $y, int $m, int $d, int $sy, int $ey, int $em, int $ed): void { self::assertLocalDateIs($ey, $em, $ed, LocalDate::of($y, $m, $d)->minusYears($sy)); @@ -1025,8 +997,6 @@ public static function providerMinusYears(): array } /** - * @dataProvider providerMinusMonths - * * @param int $y The base year. * @param int $m The base month. * @param int $d The base day. @@ -1035,6 +1005,7 @@ public static function providerMinusYears(): array * @param int $em The expected resulting month. * @param int $ed The expected resulting day. */ + #[DataProvider('providerMinusMonths')] public function testMinusMonths(int $y, int $m, int $d, int $sm, int $ey, int $em, int $ed): void { self::assertLocalDateIs($ey, $em, $ed, LocalDate::of($y, $m, $d)->minusMonths($sm)); @@ -1061,8 +1032,6 @@ public static function providerMinusMonths(): array } /** - * @dataProvider providerMinusWeeks - * * @param int $y The base year. * @param int $m The base month. * @param int $d The base day. @@ -1071,6 +1040,7 @@ public static function providerMinusMonths(): array * @param int $em The expected resulting month. * @param int $ed The expected resulting day. */ + #[DataProvider('providerMinusWeeks')] public function testMinusWeeks(int $y, int $m, int $d, int $sw, int $ey, int $em, int $ed): void { self::assertLocalDateIs($ey, $em, $ed, LocalDate::of($y, $m, $d)->minusWeeks($sw)); @@ -1090,8 +1060,6 @@ public static function providerMinusWeeks(): array } /** - * @dataProvider providerMinusDays - * * @param int $y The base year. * @param int $m The base month. * @param int $d The base day. @@ -1100,6 +1068,7 @@ public static function providerMinusWeeks(): array * @param int $em The expected resulting month. * @param int $ed The expected resulting day. */ + #[DataProvider('providerMinusDays')] public function testMinusDays(int $y, int $m, int $d, int $sd, int $ey, int $em, int $ed): void { self::assertLocalDateIs($ey, $em, $ed, LocalDate::of($y, $m, $d)->minusDays($sd)); @@ -1120,8 +1089,6 @@ public static function providerMinusDays(): array } /** - * @dataProvider providerUntil - * * @param int $y1 The year of the 1st date. * @param int $m1 The month of the 1st date. * @param int $d1 The day of the 1st date. @@ -1132,6 +1099,7 @@ public static function providerMinusDays(): array * @param int $m The expected number of months in the period. * @param int $d The expected number of days in the period. */ + #[DataProvider('providerUntil')] public function testUntil(int $y1, int $m1, int $d1, int $y2, int $m2, int $d2, int $y, int $m, int $d): void { $date1 = LocalDate::of($y1, $m1, $d1); @@ -1236,9 +1204,7 @@ public static function providerUntil(): array ]; } - /** - * @dataProvider providerDaysUntil - */ + #[DataProvider('providerDaysUntil')] public function testDaysUntil(string $date1, string $date2, int $expectedDays): void { $date1 = LocalDate::parse($date1); @@ -1265,26 +1231,24 @@ public function testAtTime(): void } /** - * @dataProvider providerIsLeapYear - * * @param int $y The year of the date to test. * @param int $m The month of the date to test (should not matter). * @param int $d The day of the date to test (should not matter). * @param bool $isLeap Whether the year is a leap year. */ + #[DataProvider('providerIsLeapYear')] public function testIsLeapYear(int $y, int $m, int $d, bool $isLeap): void { self::assertSame($isLeap, LocalDate::of($y, $m, $d)->isLeapYear()); } /** - * @dataProvider providerIsLeapYear - * * @param int $y The year of the date to test. * @param int $m The month of the date to test (should not matter). * @param int $d The day of the date to test (should not matter). * @param bool $isLeap Whether the year is a leap year. */ + #[DataProvider('providerIsLeapYear')] public function testGetLengthOfYear(int $y, int $m, int $d, bool $isLeap): void { self::assertSame($isLeap ? 366 : 365, LocalDate::of($y, $m, $d)->getLengthOfYear()); @@ -1306,13 +1270,12 @@ public static function providerIsLeapYear(): array } /** - * @dataProvider providerGetLengthOfMonth - * * @param int $y The year of the date to test. * @param int $m The month of the date to test. * @param int $d The day of the date to test (should not matter). * @param int $length The length of the month. */ + #[DataProvider('providerGetLengthOfMonth')] public function testGetLengthOfMonth(int $y, int $m, int $d, int $length): void { self::assertSame($length, LocalDate::of($y, $m, $d)->getLengthOfMonth()); @@ -1338,12 +1301,11 @@ public static function providerGetLengthOfMonth(): array } /** - * @dataProvider providerCompareTo - * * @param string $date1 The first date. * @param string $date2 The second date. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareTo')] public function testCompareTo(string $date1, string $date2, int $cmp): void { $date1 = LocalDate::parse($date1); @@ -1373,39 +1335,36 @@ public static function providerCompareTo(): array } /** - * @dataProvider providerToString - * * @param int $year The year. * @param int $month The month. * @param int $day The day-of-month. * @param string $expected The expected result string. */ + #[DataProvider('providerToString')] public function testJsonSerialize(int $year, int $month, int $day, string $expected): void { self::assertSame(json_encode($expected, JSON_THROW_ON_ERROR), json_encode(LocalDate::of($year, $month, $day), JSON_THROW_ON_ERROR)); } /** - * @dataProvider providerToString - * * @param int $year The year. * @param int $month The month. * @param int $day The day-of-month. * @param string $expected The expected result string. */ + #[DataProvider('providerToString')] public function testToISOString(int $year, int $month, int $day, string $expected): void { self::assertSame($expected, LocalDate::of($year, $month, $day)->toISOString()); } /** - * @dataProvider providerToString - * * @param int $year The year. * @param int $month The month. * @param int $day The day-of-month. * @param string $expected The expected result string. */ + #[DataProvider('providerToString')] public function testToString(int $year, int $month, int $day, string $expected): void { self::assertSame($expected, (string) LocalDate::of($year, $month, $day)); @@ -1456,11 +1415,10 @@ public function testMaxOfZeroElementsThrowsException(): void } /** - * @dataProvider providerToNativeDateTime - * * @param string $dateTime The date-time string that will be parse()d by LocalDate. * @param string $expected The expected output from the native DateTime object. */ + #[DataProvider('providerToNativeDateTime')] public function testToNativeDateTime(string $dateTime, string $expected): void { $localDate = LocalDate::parse($dateTime); @@ -1471,11 +1429,10 @@ public function testToNativeDateTime(string $dateTime, string $expected): void } /** - * @dataProvider providerToNativeDateTime - * * @param string $dateTime The date-time string that will be parse()d by LocalDate. * @param string $expected The expected output from the native DateTime object. */ + #[DataProvider('providerToNativeDateTime')] public function testToNativeDateTimeImmutable(string $dateTime, string $expected): void { $localDate = LocalDate::parse($dateTime); diff --git a/tests/LocalDateTimeTest.php b/tests/LocalDateTimeTest.php index 19c6a9a5..1d1dae87 100644 --- a/tests/LocalDateTimeTest.php +++ b/tests/LocalDateTimeTest.php @@ -19,6 +19,7 @@ use Brick\DateTime\TimeZoneOffset; use DateTime; use DateTimeImmutable; +use PHPUnit\Framework\Attributes\DataProvider; use function json_encode; @@ -44,8 +45,6 @@ public function testFromNativeDateTime(): void } /** - * @dataProvider providerNow - * * @param int $second The second to set the clock to. * @param int $nano The nanosecond adjustment to the clock. * @param int $offset The time-zone offset to get the time at. @@ -57,6 +56,7 @@ public function testFromNativeDateTime(): void * @param int $s The expected second. * @param int $n The expected nano. */ + #[DataProvider('providerNow')] public function testNow(int $second, int $nano, int $offset, int $y, int $m, int $d, int $h, int $i, int $s, int $n): void { $clock = new FixedClock(Instant::of($second, $nano)); @@ -75,8 +75,6 @@ public static function providerNow(): array } /** - * @dataProvider providerParse - * * @param string $t The text to parse. * @param int $y The expected year. * @param int $m The expected month. @@ -86,6 +84,7 @@ public static function providerNow(): array * @param int $s The expected second. * @param int $n The expected nano-of-second. */ + #[DataProvider('providerParse')] public function testParse(string $t, int $y, int $m, int $d, int $h, int $i, int $s, int $n): void { self::assertLocalDateTimeIs($y, $m, $d, $h, $i, $s, $n, LocalDateTime::parse($t)); @@ -101,9 +100,7 @@ public static function providerParse(): array ]; } - /** - * @dataProvider providerParseInvalidStringThrowsException - */ + #[DataProvider('providerParseInvalidStringThrowsException')] public function testParseInvalidStringThrowsException(string $text): void { $this->expectException(DateTimeParseException::class); @@ -137,9 +134,7 @@ public static function providerParseInvalidStringThrowsException(): array ]; } - /** - * @dataProvider providerParseInvalidDateTimeThrowsException - */ + #[DataProvider('providerParseInvalidDateTimeThrowsException')] public function testParseInvalidDateTimeThrowsException(string $text): void { $this->expectException(DateTimeException::class); @@ -199,13 +194,12 @@ public function testMaxOfZeroElementsThrowsException(): void } /** - * @dataProvider providerGetDayOfWeek - * * @param int $year The year to test. * @param int $month The month to test. * @param int $day The day-of-month to test. * @param DayOfWeek $dayOfWeek The expected day-of-week. */ + #[DataProvider('providerGetDayOfWeek')] public function testGetDayOfWeek(int $year, int $month, int $day, DayOfWeek $dayOfWeek): void { $dateTime = LocalDateTime::of($year, $month, $day, 15, 30, 45); @@ -233,13 +227,12 @@ public static function providerGetDayOfWeek(): array } /** - * @dataProvider providerGetDayOfYear - * * @param int $year The year to test. * @param int $month The month to test. * @param int $day The day-of-month to test. * @param int $dayOfYear The expected day-of-year number. */ + #[DataProvider('providerGetDayOfYear')] public function testGetDayOfYear(int $year, int $month, int $day, int $dayOfYear): void { $dateTime = LocalDate::of($year, $month, $day)->atTime(LocalTime::midnight()); @@ -258,12 +251,11 @@ public static function providerGetDayOfYear(): array } /** - * @dataProvider providerWithDate - * * @param int $y The new year. * @param int $m The new month. * @param int $d The new day. */ + #[DataProvider('providerWithDate')] public function testWithDate(int $y, int $m, int $d): void { $dateTime = LocalDate::of(2001, 2, 3)->atTime(LocalTime::of(4, 5, 6, 789)); @@ -280,13 +272,12 @@ public static function providerWithDate(): array } /** - * @dataProvider providerWithTime - * * @param int $h The new hour. * @param int $m The new minute. * @param int $s The new second. * @param int $n The new nano. */ + #[DataProvider('providerWithTime')] public function testWithTime(int $h, int $m, int $s, int $n): void { $dateTime = LocalDate::of(2001, 2, 3)->atTime(LocalTime::of(4, 5, 6, 789)); @@ -303,14 +294,13 @@ public static function providerWithTime(): array } /** - * @dataProvider providerWithYear - * * @param int $year The base year. * @param int $month The base month. * @param int $day The base day-of-month. * @param int $newYear The new year. * @param int $expectedDay The expected day-of-month of the resulting date. */ + #[DataProvider('providerWithYear')] public function testWithYear(int $year, int $month, int $day, int $newYear, int $expectedDay): void { $date = LocalDate::of($year, $month, $day); @@ -332,10 +322,9 @@ public static function providerWithYear(): array } /** - * @dataProvider providerWithInvalidYearThrowsException - * * @param int $invalidYear The year to test. */ + #[DataProvider('providerWithInvalidYearThrowsException')] public function testWithInvalidYearThrowsException(int $invalidYear): void { $this->expectException(DateTimeException::class); @@ -351,14 +340,13 @@ public static function providerWithInvalidYearThrowsException(): array } /** - * @dataProvider providerWithMonth - * * @param int $year The base year. * @param int $month The base month. * @param int $day The base day-of-month. * @param int $newMonth The new month. * @param int $expectedDay The expected day-of-month of the resulting date. */ + #[DataProvider('providerWithMonth')] public function testWithMonth(int $year, int $month, int $day, int $newMonth, int $expectedDay): void { $date = LocalDate::of($year, $month, $day); @@ -388,10 +376,9 @@ public static function providerWithMonth(): array } /** - * @dataProvider providerWithInvalidYearThrowsException - * * @param int $invalidMonth The month to test. */ + #[DataProvider('providerWithInvalidYearThrowsException')] public function testWithInvalidMonthThrowsException(int $invalidMonth): void { $this->expectException(DateTimeException::class); @@ -407,13 +394,12 @@ public static function providerWithInvalidMonthThrowsException(): array } /** - * @dataProvider providerWithDay - * * @param int $year The base year. * @param int $month The base month. * @param int $day The base day-of-month. * @param int $newDay The new day-of-month. */ + #[DataProvider('providerWithDay')] public function testWithDay(int $year, int $month, int $day, int $newDay): void { $date = LocalDate::of($year, $month, $day); @@ -433,13 +419,12 @@ public static function providerWithDay(): array } /** - * @dataProvider providerWithInvalidDayThrowsException - * * @param int $year The base year. * @param int $month The base month. * @param int $day The base day-of-month. * @param int $newDay The new day-of-month. */ + #[DataProvider('providerWithInvalidDayThrowsException')] public function testWithInvalidDayThrowsException(int $year, int $month, int $day, int $newDay): void { $this->expectException(DateTimeException::class); @@ -458,10 +443,9 @@ public static function providerWithInvalidDayThrowsException(): array } /** - * @dataProvider providerWithHour - * * @param int $hour The new hour. */ + #[DataProvider('providerWithHour')] public function testWithHour(int $hour): void { $localDateTime = LocalDate::of(2001, 2, 3)->atTime(LocalTime::of(12, 34, 56, 123456789)); @@ -476,9 +460,7 @@ public static function providerWithHour(): array ]; } - /** - * @dataProvider providerWithInvalidHourThrowsException - */ + #[DataProvider('providerWithInvalidHourThrowsException')] public function testWithInvalidHourThrowsException(int $invalidHour): void { $this->expectException(DateTimeException::class); @@ -494,10 +476,9 @@ public static function providerWithInvalidHourThrowsException(): array } /** - * @dataProvider providerWithMinute - * * @param int $minute The new minute. */ + #[DataProvider('providerWithMinute')] public function testWithMinute(int $minute): void { $localDateTime = LocalDate::of(2001, 2, 3)->atTime(LocalTime::of(12, 34, 56, 123456789)); @@ -512,9 +493,7 @@ public static function providerWithMinute(): array ]; } - /** - * @dataProvider providerWithInvalidMinuteThrowsException - */ + #[DataProvider('providerWithInvalidMinuteThrowsException')] public function testWithInvalidMinuteThrowsException(int $invalidMinute): void { $this->expectException(DateTimeException::class); @@ -530,10 +509,9 @@ public static function providerWithInvalidMinuteThrowsException(): array } /** - * @dataProvider providerWithSecond - * * @param int $second The new second. */ + #[DataProvider('providerWithSecond')] public function testWithSecond(int $second): void { $localDateTime = LocalDate::of(2001, 2, 3)->atTime(LocalTime::of(12, 34, 56, 123456789)); @@ -548,9 +526,7 @@ public static function providerWithSecond(): array ]; } - /** - * @dataProvider providerWithInvalidSecondThrowsException - */ + #[DataProvider('providerWithInvalidSecondThrowsException')] public function testWithInvalidSecondThrowsException(int $invalidSecond): void { $this->expectException(DateTimeException::class); @@ -566,10 +542,9 @@ public static function providerWithInvalidSecondThrowsException(): array } /** - * @dataProvider providerWithNano - * * @param int $nano The new nano. */ + #[DataProvider('providerWithNano')] public function testWithNano(int $nano): void { $localDateTime = LocalDate::of(2001, 2, 3)->atTime(LocalTime::of(12, 34, 56, 123456789)); @@ -584,9 +559,7 @@ public static function providerWithNano(): array ]; } - /** - * @dataProvider providerWithInvalidNanoThrowsException - */ + #[DataProvider('providerWithInvalidNanoThrowsException')] public function testWithInvalidNanoThrowsException(int $invalidNano): void { $this->expectException(DateTimeException::class); @@ -602,8 +575,6 @@ public static function providerWithInvalidNanoThrowsException(): array } /** - * @dataProvider providerPeriod - * * @param int $y The year of the base date. * @param int $m The month of the base date. * @param int $d The day of the base date. @@ -614,6 +585,7 @@ public static function providerWithInvalidNanoThrowsException(): array * @param int $em The expected month of the result date. * @param int $ed The expected day of the result date. */ + #[DataProvider('providerPeriod')] public function testPlusPeriod(int $y, int $m, int $d, int $py, int $pm, int $pd, int $ey, int $em, int $ed): void { $dateTime = LocalDate::of($y, $m, $d)->atTime(LocalTime::of(12, 34, 56, 123456789)); @@ -623,8 +595,6 @@ public function testPlusPeriod(int $y, int $m, int $d, int $py, int $pm, int $pd } /** - * @dataProvider providerPeriod - * * @param int $y The year of the base date. * @param int $m The month of the base date. * @param int $d The day of the base date. @@ -635,6 +605,7 @@ public function testPlusPeriod(int $y, int $m, int $d, int $py, int $pm, int $pd * @param int $em The expected month of the result date. * @param int $ed The expected day of the result date. */ + #[DataProvider('providerPeriod')] public function testMinusPeriod(int $y, int $m, int $d, int $py, int $pm, int $pd, int $ey, int $em, int $ed): void { $dateTime = LocalDate::of($y, $m, $d)->atTime(LocalTime::of(12, 34, 56, 123456789)); @@ -661,8 +632,6 @@ public static function providerPeriod(): array } /** - * @dataProvider providerDuration - * * @param int $ds The seconds of the duration. * @param int $dn The nano adjustment of the duration. * @param int $y The expected year. @@ -673,6 +642,7 @@ public static function providerPeriod(): array * @param int $s The expected second. * @param int $n The expected nano. */ + #[DataProvider('providerDuration')] public function testPlusDuration(int $ds, int $dn, int $y, int $m, int $d, int $h, int $i, int $s, int $n): void { $localDateTime = LocalDate::of(2001, 2, 3)->atTime(LocalTime::of(4, 5, 6, 123456789)); @@ -681,8 +651,6 @@ public function testPlusDuration(int $ds, int $dn, int $y, int $m, int $d, int $ } /** - * @dataProvider providerDuration - * * @param int $ds The seconds of the duration. * @param int $dn The nano adjustment of the duration. * @param int $y The expected year. @@ -693,6 +661,7 @@ public function testPlusDuration(int $ds, int $dn, int $y, int $m, int $d, int $ * @param int $s The expected second. * @param int $n The expected nano. */ + #[DataProvider('providerDuration')] public function testMinusDuration(int $ds, int $dn, int $y, int $m, int $d, int $h, int $i, int $s, int $n): void { $localDateTime = LocalDate::of(2001, 2, 3)->atTime(LocalTime::of(4, 5, 6, 123456789)); @@ -712,12 +681,11 @@ public static function providerDuration(): array } /** - * @dataProvider providerPlusYears - * * @param string $dateTime The base date-time string. * @param int $years The number of years to add. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerPlusYears')] public function testPlusYears(string $dateTime, int $years, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->plusYears($years); @@ -734,12 +702,11 @@ public static function providerPlusYears(): array } /** - * @dataProvider providerPlusMonths - * * @param string $dateTime The base date-time string. * @param int $months The number of months to add. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerPlusMonths')] public function testPlusMonths(string $dateTime, int $months, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->plusMonths($months); @@ -756,12 +723,11 @@ public static function providerPlusMonths(): array } /** - * @dataProvider providerPlusWeeks - * * @param string $dateTime The base date-time string. * @param int $weeks The number of weeks to add. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerPlusWeeks')] public function testPlusWeeks(string $dateTime, int $weeks, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->plusWeeks($weeks); @@ -778,12 +744,11 @@ public static function providerPlusWeeks(): array } /** - * @dataProvider providerPlusDays - * * @param string $dateTime The base date-time string. * @param int $days The number of days to add. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerPlusDays')] public function testPlusDays(string $dateTime, int $days, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->plusDays($days); @@ -800,12 +765,11 @@ public static function providerPlusDays(): array } /** - * @dataProvider providerPlusHours - * * @param string $dateTime The base date-time string. * @param int $hours The number of hours to add. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerPlusHours')] public function testPlusHours(string $dateTime, int $hours, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->plusHours($hours); @@ -822,12 +786,11 @@ public static function providerPlusHours(): array } /** - * @dataProvider providerPlusMinutes - * * @param string $dateTime The base date-time string. * @param int $minutes The number of minutes to add. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerPlusMinutes')] public function testPlusMinutes(string $dateTime, int $minutes, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->plusMinutes($minutes); @@ -844,12 +807,11 @@ public static function providerPlusMinutes(): array } /** - * @dataProvider providerPlusSeconds - * * @param string $dateTime The base date-time string. * @param int $seconds The number of seconds to add. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerPlusSeconds')] public function testPlusSeconds(string $dateTime, int $seconds, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->plusSeconds($seconds); @@ -866,12 +828,11 @@ public static function providerPlusSeconds(): array } /** - * @dataProvider providerPlusNanos - * * @param string $dateTime The base date-time string. * @param int $nanosToAdd The nanoseconds to add. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerPlusNanos')] public function testPlusNanos(string $dateTime, int $nanosToAdd, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->plusNanos($nanosToAdd); @@ -889,12 +850,11 @@ public static function providerPlusNanos(): array } /** - * @dataProvider providerMinusYears - * * @param string $dateTime The base date-time string. * @param int $years The number of years to subtract. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerMinusYears')] public function testMinusYears(string $dateTime, int $years, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->minusYears($years); @@ -911,12 +871,11 @@ public static function providerMinusYears(): array } /** - * @dataProvider providerMinusMonths - * * @param string $dateTime The base date-time string. * @param int $months The number of months to subtract. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerMinusMonths')] public function testMinusMonths(string $dateTime, int $months, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->minusMonths($months); @@ -933,12 +892,11 @@ public static function providerMinusMonths(): array } /** - * @dataProvider providerMinusWeeks - * * @param string $dateTime The base date-time string. * @param int $weeks The number of weeks to subtract. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerMinusWeeks')] public function testMinusWeeks(string $dateTime, int $weeks, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->minusWeeks($weeks); @@ -955,12 +913,11 @@ public static function providerMinusWeeks(): array } /** - * @dataProvider providerMinusDays - * * @param string $dateTime The base date-time string. * @param int $days The number of days to subtract. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerMinusDays')] public function testMinusDays(string $dateTime, int $days, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->minusDays($days); @@ -977,12 +934,11 @@ public static function providerMinusDays(): array } /** - * @dataProvider providerMinusHours - * * @param string $dateTime The base date-time string. * @param int $hours The number of hours to subtract. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerMinusHours')] public function testMinusHours(string $dateTime, int $hours, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->minusHours($hours); @@ -999,12 +955,11 @@ public static function providerMinusHours(): array } /** - * @dataProvider providerMinusMinutes - * * @param string $dateTime The base date-time string. * @param int $minutes The number of minutes to subtract. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerMinusMinutes')] public function testMinusMinutes(string $dateTime, int $minutes, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->minusMinutes($minutes); @@ -1021,12 +976,11 @@ public static function providerMinusMinutes(): array } /** - * @dataProvider providerMinusSeconds - * * @param string $dateTime The base date-time string. * @param int $seconds The number of seconds to subtract. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerMinusSeconds')] public function testMinusSeconds(string $dateTime, int $seconds, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->minusSeconds($seconds); @@ -1043,12 +997,11 @@ public static function providerMinusSeconds(): array } /** - * @dataProvider providerMinusNanos - * * @param string $dateTime The base date-time string. * @param int $nanosToSubtract The nanoseconds to subtract. * @param string $expectedDateTime The expected resulting date-time string. */ + #[DataProvider('providerMinusNanos')] public function testMinusNanos(string $dateTime, int $nanosToSubtract, string $expectedDateTime): void { $actualDateTime = LocalDateTime::parse($dateTime)->minusNanos($nanosToSubtract); @@ -1066,13 +1019,12 @@ public static function providerMinusNanos(): array } /** - * @dataProvider providerAtTimeZone - * * @param string $dateTime The date-time. * @param string $timeZone The time-zone. * @param int $epochSeconds The expected epoch second of the resulting instant. * @param int $nanos The expected nano-of-second of the resulting instant. */ + #[DataProvider('providerAtTimeZone')] public function testAtTimeZone(string $dateTime, string $timeZone, int $epochSeconds, int $nanos): void { $localDateTime = LocalDateTime::parse($dateTime)->atTimeZone(TimeZone::parse($timeZone)); @@ -1090,12 +1042,11 @@ public static function providerAtTimeZone(): array } /** - * @dataProvider providerCompareTo - * * @param string $dateTime1 The base date-time. * @param string $dateTime2 The date-time to compare to. * @param int $result The expected result. */ + #[DataProvider('providerCompareTo')] public function testCompareTo(string $dateTime1, string $dateTime2, int $result): void { $dateTime1 = LocalDateTime::parse($dateTime1); @@ -1131,9 +1082,7 @@ public static function providerCompareTo(): array ]; } - /** - * @dataProvider providerForPastFuture - */ + #[DataProvider('providerForPastFuture')] public function testIsFuture(int $clockTimestamp, string $localDateTime, string $offset, bool $isFuture): void { $clock = new FixedClock(Instant::of($clockTimestamp)); @@ -1142,9 +1091,7 @@ public function testIsFuture(int $clockTimestamp, string $localDateTime, string self::assertSame($isFuture, $localDateTime->isFuture($timeZone, $clock)); } - /** - * @dataProvider providerForPastFuture - */ + #[DataProvider('providerForPastFuture')] public function testIsPast(int $clockTimestamp, string $localDateTime, string $offset, bool $isFuture): void { $clock = new FixedClock(Instant::of($clockTimestamp)); @@ -1164,11 +1111,10 @@ public static function providerForPastFuture(): array } /** - * @dataProvider providerToNativeDateTime - * * @param string $dateTime The date-time string that will be parse()d by LocalDateTime. * @param string $expected The expected output from the native DateTime object. */ + #[DataProvider('providerToNativeDateTime')] public function testToNativeDateTime(string $dateTime, string $expected): void { $localDateTime = LocalDateTime::parse($dateTime); @@ -1179,11 +1125,10 @@ public function testToNativeDateTime(string $dateTime, string $expected): void } /** - * @dataProvider providerToNativeDateTime - * * @param string $dateTime The date-time string that will be parse()d by LocalDateTime. * @param string $expected The expected output from the native DateTime object. */ + #[DataProvider('providerToNativeDateTime')] public function testToNativeDateTimeImmutable(string $dateTime, string $expected): void { $localDateTime = LocalDateTime::parse($dateTime); @@ -1207,8 +1152,6 @@ public static function providerToNativeDateTime(): array } /** - * @dataProvider providerToString - * * @param int $year The year. * @param int $month The month. * @param int $day The day-of-month. @@ -1218,14 +1161,13 @@ public static function providerToNativeDateTime(): array * @param int $nano The nano-of-second. * @param string $expected The expected result string. */ + #[DataProvider('providerToString')] public function testJsonSerialize(int $year, int $month, int $day, int $hour, int $minute, int $second, int $nano, string $expected): void { self::assertSame(json_encode($expected, JSON_THROW_ON_ERROR), json_encode(LocalDateTime::of($year, $month, $day, $hour, $minute, $second, $nano), JSON_THROW_ON_ERROR)); } /** - * @dataProvider providerToString - * * @param int $year The year. * @param int $month The month. * @param int $day The day-of-month. @@ -1235,14 +1177,13 @@ public function testJsonSerialize(int $year, int $month, int $day, int $hour, in * @param int $nano The nano-of-second. * @param string $expected The expected result string. */ + #[DataProvider('providerToString')] public function testToISOString(int $year, int $month, int $day, int $hour, int $minute, int $second, int $nano, string $expected): void { self::assertSame($expected, LocalDateTime::of($year, $month, $day, $hour, $minute, $second, $nano)->toISOString()); } /** - * @dataProvider providerToString - * * @param int $year The year. * @param int $month The month. * @param int $day The day-of-month. @@ -1252,6 +1193,7 @@ public function testToISOString(int $year, int $month, int $day, int $hour, int * @param int $nano The nano-of-second. * @param string $expected The expected result string. */ + #[DataProvider('providerToString')] public function testToString(int $year, int $month, int $day, int $hour, int $minute, int $second, int $nano, string $expected): void { self::assertSame($expected, (string) LocalDateTime::of($year, $month, $day, $hour, $minute, $second, $nano)); diff --git a/tests/LocalTimeTest.php b/tests/LocalTimeTest.php index 395b8ec3..2d5f71d5 100644 --- a/tests/LocalTimeTest.php +++ b/tests/LocalTimeTest.php @@ -14,6 +14,7 @@ use Brick\DateTime\TimeZoneOffset; use DateTime; use DateTimeImmutable; +use PHPUnit\Framework\Attributes\DataProvider; use function json_encode; @@ -29,9 +30,7 @@ public function testOf(): void self::assertLocalTimeIs(12, 34, 56, 123456789, LocalTime::of(12, 34, 56, 123456789)); } - /** - * @dataProvider providerOfInvalidTimeThrowsException - */ + #[DataProvider('providerOfInvalidTimeThrowsException')] public function testOfInvalidTimeThrowsException(int $hour, int $minute, int $second): void { $this->expectException(DateTimeException::class); @@ -51,13 +50,12 @@ public static function providerOfInvalidTimeThrowsException(): array } /** - * @dataProvider providerOfSecondOfDay - * * @param int $secondOfDay The second-of-day to test. * @param int $hour The expected resulting hour. * @param int $minute The expected resulting minute. * @param int $second The expected resulting second. */ + #[DataProvider('providerOfSecondOfDay')] public function testOfSecondOfDay(int $secondOfDay, int $hour, int $minute, int $second): void { $localTime = LocalTime::ofSecondOfDay($secondOfDay, 123); @@ -85,9 +83,7 @@ public static function providerOfSecondOfDay(): array ]; } - /** - * @dataProvider providerOfInvalidSecondOfDayThrowsException - */ + #[DataProvider('providerOfInvalidSecondOfDayThrowsException')] public function testOfInvalidSecondOfDayThrowsException(int $secondOfDay, int $nanoOfSecond): void { $this->expectException(DateTimeException::class); @@ -104,9 +100,7 @@ public static function providerOfInvalidSecondOfDayThrowsException(): array ]; } - /** - * @dataProvider providerParse - */ + #[DataProvider('providerParse')] public function testParse(string $text, int $hour, int $minute, int $second, int $nano): void { $time = LocalTime::parse($text); @@ -127,9 +121,7 @@ public static function providerParse(): array ]; } - /** - * @dataProvider providerParseInvalidStringThrowsException - */ + #[DataProvider('providerParseInvalidStringThrowsException')] public function testParseInvalidStringThrowsException(string $text): void { $this->expectException(DateTimeParseException::class); @@ -161,8 +153,6 @@ public function testFromNativeDateTime(): void } /** - * @dataProvider providerNow - * * @param int $second The second to set the clock to. * @param int $nano The nanosecond adjustment to the clock. * @param int $offset The time-zone offset to get the time at. @@ -171,6 +161,7 @@ public function testFromNativeDateTime(): void * @param int $s The expected second. * @param int $n The expected nano. */ + #[DataProvider('providerNow')] public function testNow(int $second, int $nano, int $offset, int $h, int $m, int $s, int $n): void { $clock = new FixedClock(Instant::of($second, $nano)); @@ -221,10 +212,9 @@ public function testMax(): void } /** - * @dataProvider providerWithHour - * * @param int $hour The new hour. */ + #[DataProvider('providerWithHour')] public function testWithHour(int $hour): void { self::assertLocalTimeIs($hour, 34, 56, 789, LocalTime::of(12, 34, 56, 789)->withHour($hour)); @@ -238,9 +228,7 @@ public static function providerWithHour(): array ]; } - /** - * @dataProvider providerWithInvalidHourThrowsException - */ + #[DataProvider('providerWithInvalidHourThrowsException')] public function testWithInvalidHourThrowsException(int $invalidHour): void { $this->expectException(DateTimeException::class); @@ -256,10 +244,9 @@ public static function providerWithInvalidHourThrowsException(): array } /** - * @dataProvider providerWithMinute - * * @param int $minute The new minute. */ + #[DataProvider('providerWithMinute')] public function testWithMinute(int $minute): void { self::assertLocalTimeIs(12, $minute, 56, 789, LocalTime::of(12, 34, 56, 789)->withMinute($minute)); @@ -273,9 +260,7 @@ public static function providerWithMinute(): array ]; } - /** - * @dataProvider providerWithInvalidMinuteThrowsException - */ + #[DataProvider('providerWithInvalidMinuteThrowsException')] public function testWithInvalidMinuteThrowsException(int $invalidMinute): void { $this->expectException(DateTimeException::class); @@ -291,10 +276,9 @@ public static function providerWithInvalidMinuteThrowsException(): array } /** - * @dataProvider providerWithSecond - * * @param int $second The new second. */ + #[DataProvider('providerWithSecond')] public function testWithSecond(int $second): void { self::assertLocalTimeIs(12, 34, $second, 789, LocalTime::of(12, 34, 56, 789)->withSecond($second)); @@ -308,9 +292,7 @@ public static function providerWithSecond(): array ]; } - /** - * @dataProvider providerWithInvalidSecondThrowsException - */ + #[DataProvider('providerWithInvalidSecondThrowsException')] public function testWithInvalidSecondThrowsException(int $invalidSecond): void { $this->expectException(DateTimeException::class); @@ -326,10 +308,9 @@ public static function providerWithInvalidSecondThrowsException(): array } /** - * @dataProvider providerWithNano - * * @param int $nano The new nano. */ + #[DataProvider('providerWithNano')] public function testWithNano(int $nano): void { self::assertLocalTimeIs(12, 34, 56, $nano, LocalTime::of(12, 34, 56, 789)->withNano($nano)); @@ -343,9 +324,7 @@ public static function providerWithNano(): array ]; } - /** - * @dataProvider providerWithInvalidNanoThrowsException - */ + #[DataProvider('providerWithInvalidNanoThrowsException')] public function testWithInvalidNanoThrowsException(int $invalidNano): void { $this->expectException(DateTimeException::class); @@ -361,8 +340,6 @@ public static function providerWithInvalidNanoThrowsException(): array } /** - * @dataProvider providerDuration - * * @param int $h The base hour. * @param int $m The base minute. * @param int $s The base second. @@ -374,6 +351,7 @@ public static function providerWithInvalidNanoThrowsException(): array * @param int $es The expected second of the result time. * @param int $en The expected nano of the result time. */ + #[DataProvider('providerDuration')] public function testPlusDuration(int $h, int $m, int $s, int $n, int $ds, int $dn, int $eh, int $em, int $es, int $en): void { $localTime = LocalTime::of($h, $m, $s, $n); @@ -382,8 +360,6 @@ public function testPlusDuration(int $h, int $m, int $s, int $n, int $ds, int $d } /** - * @dataProvider providerDuration - * * @param int $h The base hour. * @param int $m The base minute. * @param int $s The base second. @@ -395,6 +371,7 @@ public function testPlusDuration(int $h, int $m, int $s, int $n, int $ds, int $d * @param int $es The expected second of the result time. * @param int $en The expected nano of the result time. */ + #[DataProvider('providerDuration')] public function testMinusDuration(int $h, int $m, int $s, int $n, int $ds, int $dn, int $eh, int $em, int $es, int $en): void { $localTime = LocalTime::of($h, $m, $s, $n); @@ -413,12 +390,11 @@ public static function providerDuration(): array } /** - * @dataProvider providerPlusHours - * * @param int $h The base hour. * @param int $d The number of hours to add. * @param int $eh The expected result hour. */ + #[DataProvider('providerPlusHours')] public function testPlusHours(int $h, int $d, int $eh): void { $result = LocalTime::of($h, 34, 56, 789)->plusHours($d); @@ -426,12 +402,11 @@ public function testPlusHours(int $h, int $d, int $eh): void } /** - * @dataProvider providerPlusHours - * * @param int $h The base hour. * @param int $d The number of hours to add. * @param int $eh The expected result hour. */ + #[DataProvider('providerPlusHours')] public function testMinusHours(int $h, int $d, int $eh): void { $result = LocalTime::of($h, 34, 56, 789)->minusHours(-$d); @@ -472,14 +447,13 @@ public static function providerPlusHours(): array } /** - * @dataProvider providerPlusMinutes - * * @param int $h The base hour. * @param int $m The base minute. * @param int $d The number of minutes to add. * @param int $eh The expected result hour. * @param int $em The expected result minute. */ + #[DataProvider('providerPlusMinutes')] public function testPlusMinutes(int $h, int $m, int $d, int $eh, int $em): void { $result = LocalTime::of($h, $m, 56, 789)->plusMinutes($d); @@ -487,14 +461,13 @@ public function testPlusMinutes(int $h, int $m, int $d, int $eh, int $em): void } /** - * @dataProvider providerPlusMinutes - * * @param int $h The base hour. * @param int $m The base minute. * @param int $d The number of minutes to add. * @param int $eh The expected result hour. * @param int $em The expected result minute. */ + #[DataProvider('providerPlusMinutes')] public function testMinusMinutes(int $h, int $m, int $d, int $eh, int $em): void { $result = LocalTime::of($h, $m, 56, 789)->minusMinutes(-$d); @@ -553,8 +526,6 @@ public static function providerPlusMinutes(): array } /** - * @dataProvider providerPlusSeconds - * * @param int $h The base hour. * @param int $m The base minute. * @param int $s The base second. @@ -563,6 +534,7 @@ public static function providerPlusMinutes(): array * @param int $em The expected result minute. * @param int $es The expected result second. */ + #[DataProvider('providerPlusSeconds')] public function testPlusSeconds(int $h, int $m, int $s, int $d, int $eh, int $em, int $es): void { $result = LocalTime::of($h, $m, $s, 123456789)->plusSeconds($d); @@ -570,8 +542,6 @@ public function testPlusSeconds(int $h, int $m, int $s, int $d, int $eh, int $em } /** - * @dataProvider providerPlusSeconds - * * @param int $h The base hour. * @param int $m The base minute. * @param int $s The base second. @@ -580,6 +550,7 @@ public function testPlusSeconds(int $h, int $m, int $s, int $d, int $eh, int $em * @param int $em The expected result minute. * @param int $es The expected result second. */ + #[DataProvider('providerPlusSeconds')] public function testMinusSeconds(int $h, int $m, int $s, int $d, int $eh, int $em, int $es): void { $result = LocalTime::of($h, $m, $s, 123456789)->minusSeconds(-$d); @@ -650,8 +621,6 @@ public static function providerPlusSeconds(): array } /** - * @dataProvider providerPlusNanos - * * @param int $h The base hour. * @param int $m The base minute. * @param int $s The base second. @@ -662,6 +631,7 @@ public static function providerPlusSeconds(): array * @param int $es The expected result second. * @param int $en The expected result nanosecond. */ + #[DataProvider('providerPlusNanos')] public function testPlusNanos(int $h, int $m, int $s, int $n, int $d, int $eh, int $em, int $es, int $en): void { $result = LocalTime::of($h, $m, $s, $n)->plusNanos($d); @@ -669,8 +639,6 @@ public function testPlusNanos(int $h, int $m, int $s, int $n, int $d, int $eh, i } /** - * @dataProvider providerPlusNanos - * * @param int $h The base hour. * @param int $m The base minute. * @param int $s The base second. @@ -681,6 +649,7 @@ public function testPlusNanos(int $h, int $m, int $s, int $n, int $d, int $eh, i * @param int $es The expected result second. * @param int $en The expected result nanosecond. */ + #[DataProvider('providerPlusNanos')] public function testMinusNanos(int $h, int $m, int $s, int $n, int $d, int $eh, int $em, int $es, int $en): void { $result = LocalTime::of($h, $m, $s, $n)->minusNanos(-$d); @@ -715,8 +684,6 @@ public static function providerPlusNanos(): array } /** - * @dataProvider providerCompareTo - * * @param int $h1 The hour of the 1st time. * @param int $m1 The minute of the 1st time. * @param int $s1 The second of the 1st time. @@ -727,6 +694,7 @@ public static function providerPlusNanos(): array * @param int $n2 The nano of the 2nd time. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareTo')] public function testCompareTo(int $h1, int $m1, int $s1, int $n1, int $h2, int $m2, int $s2, int $n2, int $cmp): void { $t1 = LocalTime::of($h1, $m1, $s1, $n1); @@ -1010,9 +978,7 @@ public function testAtDate(): void self::assertLocalDateTimeIs(2014, 11, 30, 12, 34, 56, 789, $time->atDate($date)); } - /** - * @dataProvider providerToSecondOfDay - */ + #[DataProvider('providerToSecondOfDay')] public function testToSecondOfDay(int $hour, int $minute, int $second, int $result): void { $time = LocalTime::of($hour, $minute, $second); @@ -1034,42 +1000,39 @@ public static function providerToSecondOfDay(): array } /** - * @dataProvider providerToString - * * @param int $h The hour. * @param int $m The minute. * @param int $s The second. * @param int $n The nanosecond. * @param string $r The expected result. */ + #[DataProvider('providerToString')] public function testJsonSerialize(int $h, int $m, int $s, int $n, string $r): void { self::assertSame(json_encode($r, JSON_THROW_ON_ERROR), json_encode(LocalTime::of($h, $m, $s, $n), JSON_THROW_ON_ERROR)); } /** - * @dataProvider providerToString - * * @param int $h The hour. * @param int $m The minute. * @param int $s The second. * @param int $n The nanosecond. * @param string $r The expected result. */ + #[DataProvider('providerToString')] public function testToISOString(int $h, int $m, int $s, int $n, string $r): void { self::assertSame($r, LocalTime::of($h, $m, $s, $n)->toISOString()); } /** - * @dataProvider providerToString - * * @param int $h The hour. * @param int $m The minute. * @param int $s The second. * @param int $n The nanosecond. * @param string $r The expected result. */ + #[DataProvider('providerToString')] public function testToString(int $h, int $m, int $s, int $n, string $r): void { self::assertSame($r, (string) LocalTime::of($h, $m, $s, $n)); @@ -1114,11 +1077,10 @@ public function testMaxOfZeroElementsThrowsException(): void } /** - * @dataProvider providerToNativeDateTime - * * @param string $dateTime The date-time string that will be parse()d by LocalTime. * @param string $expected The expected output from the native DateTime object. */ + #[DataProvider('providerToNativeDateTime')] public function testToNativeDateTime(string $dateTime, string $expected): void { $localTime = LocalTime::parse($dateTime); @@ -1129,11 +1091,10 @@ public function testToNativeDateTime(string $dateTime, string $expected): void } /** - * @dataProvider providerToNativeDateTime - * * @param string $dateTime The date-time string that will be parse()d by LocalTime. * @param string $expected The expected output from the native DateTime object. */ + #[DataProvider('providerToNativeDateTime')] public function testToNativeDateTimeImmutable(string $dateTime, string $expected): void { $localTime = LocalTime::parse($dateTime); diff --git a/tests/MonthDayTest.php b/tests/MonthDayTest.php index ca888303..d4b085d1 100644 --- a/tests/MonthDayTest.php +++ b/tests/MonthDayTest.php @@ -10,6 +10,7 @@ use Brick\DateTime\MonthDay; use Brick\DateTime\Parser\DateTimeParseException; use Brick\DateTime\TimeZone; +use PHPUnit\Framework\Attributes\DataProvider; use function json_encode; @@ -20,9 +21,7 @@ */ class MonthDayTest extends AbstractTestCase { - /** - * @dataProvider providerOf - */ + #[DataProvider('providerOf')] public function testOf(int $month, int $day): void { self::assertMonthDayIs($month, $day, MonthDay::of($month, $day)); @@ -47,9 +46,7 @@ public static function providerOf(): array ]; } - /** - * @dataProvider providerOfThrowsExceptionOnInvalidMonthDay - */ + #[DataProvider('providerOfThrowsExceptionOnInvalidMonthDay')] public function testOfThrowsExceptionOnInvalidMonthDay(int $month, int $day): void { $this->expectException(DateTimeException::class); @@ -78,12 +75,11 @@ public static function providerOfThrowsExceptionOnInvalidMonthDay(): array } /** - * @dataProvider providerParse - * * @param string $text The text to parse. * @param int $month The expected month. * @param int $day The expected day. */ + #[DataProvider('providerParse')] public function testParse(string $text, int $month, int $day): void { self::assertMonthDayIs($month, $day, MonthDay::parse($text)); @@ -98,9 +94,7 @@ public static function providerParse(): array ]; } - /** - * @dataProvider providerParseInvalidStringThrowsException - */ + #[DataProvider('providerParseInvalidStringThrowsException')] public function testParseInvalidStringThrowsException(string $text): void { $this->expectException(DateTimeParseException::class); @@ -125,9 +119,7 @@ public static function providerParseInvalidStringThrowsException(): array ]; } - /** - * @dataProvider providerParseInvalidDateThrowsException - */ + #[DataProvider('providerParseInvalidDateThrowsException')] public function testParseInvalidDateThrowsException(string $text): void { $this->expectException(DateTimeException::class); @@ -145,13 +137,12 @@ public static function providerParseInvalidDateThrowsException(): array } /** - * @dataProvider providerNow - * * @param int $epochSecond The epoch second. * @param string $timeZone The time-zone. * @param int $month The expected month. * @param int $day The expected day. */ + #[DataProvider('providerNow')] public function testNow(int $epochSecond, string $timeZone, int $month, int $day): void { $clock = new FixedClock(Instant::of($epochSecond)); @@ -169,56 +160,52 @@ public static function providerNow(): array } /** - * @dataProvider providerCompareTo - * * @param int $m1 The month of the base month-day. * @param int $d1 The day of the base month-day. * @param int $m2 The month of the month-day to compare to. * @param int $d2 The day of the month-day to compare to. * @param int $result The expected result. */ + #[DataProvider('providerCompareTo')] public function testCompareTo(int $m1, int $d1, int $m2, int $d2, int $result): void { self::assertSame($result, MonthDay::of($m1, $d1)->compareTo(MonthDay::of($m2, $d2))); } /** - * @dataProvider providerCompareTo - * * @param int $m1 The month of the base month-day. * @param int $d1 The day of the base month-day. * @param int $m2 The month of the month-day to compare to. * @param int $d2 The day of the month-day to compare to. * @param int $result The expected result. */ + #[DataProvider('providerCompareTo')] public function testIsEqualTo(int $m1, int $d1, int $m2, int $d2, int $result): void { self::assertSame($result === 0, MonthDay::of($m1, $d1)->isEqualTo(MonthDay::of($m2, $d2))); } /** - * @dataProvider providerCompareTo - * * @param int $m1 The month of the base month-day. * @param int $d1 The day of the base month-day. * @param int $m2 The month of the month-day to compare to. * @param int $d2 The day of the month-day to compare to. * @param int $result The expected result. */ + #[DataProvider('providerCompareTo')] public function testIsBefore(int $m1, int $d1, int $m2, int $d2, int $result): void { self::assertSame($result === -1, MonthDay::of($m1, $d1)->isBefore(MonthDay::of($m2, $d2))); } /** - * @dataProvider providerCompareTo - * * @param int $m1 The month of the base month-day. * @param int $d1 The day of the base month-day. * @param int $m2 The month of the month-day to compare to. * @param int $d2 The day of the month-day to compare to. * @param int $result The expected result. */ + #[DataProvider('providerCompareTo')] public function testIsAfter(int $m1, int $d1, int $m2, int $d2, int $result): void { self::assertSame($result === 1, MonthDay::of($m1, $d1)->isAfter(MonthDay::of($m2, $d2))); @@ -247,13 +234,12 @@ public static function providerCompareTo(): array } /** - * @dataProvider providerIsValidYear - * * @param int $month The month of the month-day to test. * @param int $day The day of the month-day to test. * @param int $year The year to test against. * @param bool $isValid The expected result. */ + #[DataProvider('providerIsValidYear')] public function testIsValidYear(int $month, int $day, int $year, bool $isValid): void { self::assertSame($isValid, MonthDay::of($month, $day)->isValidYear($year)); @@ -283,13 +269,12 @@ public static function providerIsValidYear(): array } /** - * @dataProvider providerWithMonth - * * @param int $month The month of the base month-day to test. * @param int $day The day of base the month-day to test. * @param int $newMonth The new month to apply. * @param int $expectedDay The expected day of the resulting month-day. */ + #[DataProvider('providerWithMonth')] public function testWithMonth(int $month, int $day, int $newMonth, int $expectedDay): void { $monthDay = MonthDay::of($month, $day); @@ -322,12 +307,11 @@ public static function providerWithMonth(): array } /** - * @dataProvider providerWithInvalidMonthThrowsException - * * @param int $month The month of the base month-day to test. * @param int $day The day of base the month-day to test. * @param int $newMonth The new month to apply. */ + #[DataProvider('providerWithInvalidMonthThrowsException')] public function testWithInvalidMonthThrowsException(int $month, int $day, int $newMonth): void { $this->expectException(DateTimeException::class); @@ -354,12 +338,11 @@ public function testWithDayWithSameDay(): void } /** - * @dataProvider providerWithDay - * * @param int $month The month of the base month-day to test. * @param int $day The day of base the month-day to test. * @param int $newDay The new day to apply. */ + #[DataProvider('providerWithDay')] public function testWithDay(int $month, int $day, int $newDay): void { $monthDay = MonthDay::of($month, $day); @@ -382,12 +365,11 @@ public static function providerWithDay(): array } /** - * @dataProvider providerWithInvalidDayThrowsException - * * @param int $month The month of the base month-day to test. * @param int $day The day of base the month-day to test. * @param int $newDay The new day to apply. */ + #[DataProvider('providerWithInvalidDayThrowsException')] public function testWithInvalidDayThrowsException(int $month, int $day, int $newDay): void { $this->expectException(DateTimeException::class); @@ -425,13 +407,12 @@ public static function providerWithInvalidDayThrowsException(): array } /** - * @dataProvider providerAtYear - * * @param int $month The month of the base month-day. * @param int $day The day of the base month-day. * @param int $year The year to combine with the month-day. * @param int $expectedDay The expected day of the resulting date. */ + #[DataProvider('providerAtYear')] public function testAtYear(int $month, int $day, int $year, int $expectedDay): void { self::assertLocalDateIs($year, $month, $expectedDay, MonthDay::of($month, $day)->atYear($year)); @@ -449,9 +430,7 @@ public static function providerAtYear(): array ]; } - /** - * @dataProvider providerAtInvalidYearThrowsException - */ + #[DataProvider('providerAtInvalidYearThrowsException')] public function testAtInvalidYearThrowsException(int $year): void { $this->expectException(DateTimeException::class); @@ -467,36 +446,33 @@ public static function providerAtInvalidYearThrowsException(): array } /** - * @dataProvider providerToString - * * @param int $month The month of the month-day to test. * @param int $day The day of the month-day to test. * @param string $string The expected result string. */ + #[DataProvider('providerToString')] public function testJsonSerialize(int $month, int $day, string $string): void { self::assertSame(json_encode($string, JSON_THROW_ON_ERROR), json_encode(MonthDay::of($month, $day), JSON_THROW_ON_ERROR)); } /** - * @dataProvider providerToString - * * @param int $month The month of the month-day to test. * @param int $day The day of the month-day to test. * @param string $string The expected result string. */ + #[DataProvider('providerToString')] public function testToISOString(int $month, int $day, string $string): void { self::assertSame($string, MonthDay::of($month, $day)->toISOString()); } /** - * @dataProvider providerToString - * * @param int $month The month of the month-day to test. * @param int $day The day of the month-day to test. * @param string $string The expected result string. */ + #[DataProvider('providerToString')] public function testToString(int $month, int $day, string $string): void { self::assertSame($string, (string) MonthDay::of($month, $day)); diff --git a/tests/MonthTest.php b/tests/MonthTest.php index e09dc4d1..2e9683c6 100644 --- a/tests/MonthTest.php +++ b/tests/MonthTest.php @@ -7,6 +7,7 @@ use Brick\DateTime\DateTimeException; use Brick\DateTime\Month; use Generator; +use PHPUnit\Framework\Attributes\DataProvider; use function json_encode; @@ -18,11 +19,10 @@ class MonthTest extends AbstractTestCase { /** - * @dataProvider providerValues - * * @param int $expectedValue The expected value of the constant. * @param Month $month The month instance. */ + #[DataProvider('providerValues')] public function testValues(int $expectedValue, Month $month): void { self::assertSame($expectedValue, $month->value); @@ -53,9 +53,7 @@ public function testOf(): void self::assertSame(Month::AUGUST, Month::of(Month::AUGUST)); } - /** - * @dataProvider providerOfInvalidMonthThrowsException - */ + #[DataProvider('providerOfInvalidMonthThrowsException')] public function testOfInvalidMonthThrowsException(int $invalidMonth): void { $this->expectException(DateTimeException::class); @@ -101,11 +99,10 @@ public function testIsEqualTo(): void } /** - * @dataProvider minLengthProvider - * * @param int $month The month value. * @param int $minLength The expected min length. */ + #[DataProvider('minLengthProvider')] public function testGetMinLength(int $month, int $minLength): void { self::assertSame($minLength, Month::from($month)->getMinLength()); @@ -130,11 +127,10 @@ public static function minLengthProvider(): array } /** - * @dataProvider maxLengthProvider - * * @param int $month The month value. * @param int $minLength The expected min length. */ + #[DataProvider('maxLengthProvider')] public function testGetMaxLength(int $month, int $minLength): void { self::assertSame($minLength, Month::from($month)->getMaxLength()); @@ -159,12 +155,11 @@ public static function maxLengthProvider(): array } /** - * @dataProvider providerFirstDayOfYear - * * @param int $month The month value, from 1 to 12. * @param bool $leapYear Whether to test on a leap year. * @param int $firstDayOfYear The expected first day of year. */ + #[DataProvider('providerFirstDayOfYear')] public function testFirstDayOfYear(int $month, bool $leapYear, int $firstDayOfYear): void { self::assertSame($firstDayOfYear, Month::from($month)->getFirstDayOfYear($leapYear)); @@ -202,12 +197,11 @@ public static function providerFirstDayOfYear(): array } /** - * @dataProvider providerGetLength - * * @param Month $month The month to test. * @param bool $leapYear Whether to test on a leap year. * @param int $expectedLength The expected month length. */ + #[DataProvider('providerGetLength')] public function testGetLength(Month $month, bool $leapYear, int $expectedLength): void { self::assertSame($expectedLength, $month->getLength($leapYear)); @@ -255,24 +249,22 @@ public function testPlusMinusEntireYears(): void } /** - * @dataProvider providerPlus - * * @param Month $month The base month. * @param int $plusMonths The number of months to add. * @param Month $expectedMonth The expected. */ + #[DataProvider('providerPlus')] public function testPlus(Month $month, int $plusMonths, Month $expectedMonth): void { self::assertSame($expectedMonth, $month->plus($plusMonths)); } /** - * @dataProvider providerPlus - * * @param Month $month The base month. * @param int $plusMonths The number of months to add. * @param Month $expectedMonth The expected month. */ + #[DataProvider('providerPlus')] public function testMinus(Month $month, int $plusMonths, Month $expectedMonth): void { self::assertSame($expectedMonth, $month->minus(-$plusMonths)); @@ -297,22 +289,20 @@ public static function providerPlus(): Generator } /** - * @dataProvider providerToString - * * @param Month $month The month. * @param string $expectedName The expected month name. */ + #[DataProvider('providerToString')] public function testJsonSerialize(Month $month, string $expectedName): void { self::assertSame(json_encode($expectedName, JSON_THROW_ON_ERROR), json_encode($month, JSON_THROW_ON_ERROR)); } /** - * @dataProvider providerToString - * * @param Month $month The month. * @param string $expectedName The expected month name. */ + #[DataProvider('providerToString')] public function testToString(Month $month, string $expectedName): void { self::assertSame($expectedName, $month->toString()); diff --git a/tests/PeriodTest.php b/tests/PeriodTest.php index 0074491f..9c684805 100644 --- a/tests/PeriodTest.php +++ b/tests/PeriodTest.php @@ -11,6 +11,7 @@ use DateInterval; use DateTimeImmutable; use Generator; +use PHPUnit\Framework\Attributes\DataProvider; use function json_encode; @@ -55,13 +56,12 @@ public function testZero(): void } /** - * @dataProvider providerParse - * * @param string $text The text to parse. * @param int $years The expected years in the period. * @param int $months The expected months in the period. * @param int $days The expected days in the period. */ + #[DataProvider('providerParse')] public function testParse(string $text, int $years, int $months, int $days): void { self::assertPeriodIs($years, $months, $days, Period::parse($text)); @@ -87,9 +87,7 @@ public static function providerParse(): array ]; } - /** - * @dataProvider providerParseInvalidStringThrowsException - */ + #[DataProvider('providerParseInvalidStringThrowsException')] public function testParseInvalidStringThrowsException(string $text): void { $this->expectException(DateTimeParseException::class); @@ -114,9 +112,7 @@ public static function providerParseInvalidStringThrowsException(): array ]; } - /** - * @dataProvider providerFromNativeDateInterval - */ + #[DataProvider('providerFromNativeDateInterval')] public function testFromNativeDateInterval(DateInterval $dateInterval, int $years, int $months, int $days): void { $period = Period::fromNativeDateInterval($dateInterval); @@ -160,9 +156,7 @@ public static function providerFromNativeDateInterval(): Generator } } - /** - * @dataProvider providerFromInvalidNativeDateInterval - */ + #[DataProvider('providerFromInvalidNativeDateInterval')] public function testFromInvalidNativeDateInterval(string $dateTime1, string $dateTime2, string $expectedMessage): void { $dateTime1 = new DateTimeImmutable($dateTime1); @@ -290,14 +284,13 @@ public function testZeroNegatedReturnsThis(): void } /** - * @dataProvider providerNormalized - * * @param int $y The years of the period to normalize. * @param int $m The months of the period to normalize. * @param int $d The days of the period to normalize. * @param int $ny The years of the normalized period. * @param int $nm The months of the normalized period. */ + #[DataProvider('providerNormalized')] public function testNormalized(int $y, int $m, int $d, int $ny, int $nm): void { self::assertPeriodIs($ny, $nm, $d, Period::of($y, $m, $d)->normalized()); @@ -318,13 +311,12 @@ public static function providerNormalized(): array } /** - * @dataProvider providerIsZero - * * @param int $years The number of years in the period. * @param int $months The number of months in the period. * @param int $days The number of days in the period. * @param bool $isZero The expected return value. */ + #[DataProvider('providerIsZero')] public function testIsZero(int $years, int $months, int $days, bool $isZero): void { self::assertSame($isZero, Period::of($years, $months, $days)->isZero()); @@ -341,8 +333,6 @@ public static function providerIsZero(): array } /** - * @dataProvider providerIsEqualTo - * * @param int $y1 The number of years in the 1st period. * @param int $m1 The number of months in the 1st period. * @param int $d1 The number of days in the 1st period. @@ -351,6 +341,7 @@ public static function providerIsZero(): array * @param int $d2 The number of days in the 2nd period. * @param bool $isEqual The expected return value. */ + #[DataProvider('providerIsEqualTo')] public function testIsEqualTo(int $y1, int $m1, int $d1, int $y2, int $m2, int $d2, bool $isEqual): void { $p1 = Period::of($y1, $m1, $d1); @@ -377,9 +368,7 @@ public static function providerIsEqualTo(): array ]; } - /** - * @dataProvider providerToNativeDateInterval - */ + #[DataProvider('providerToNativeDateInterval')] public function testToNativeDateInterval(int $years, int $months, int $days): void { $period = Period::of($years, $months, $days); @@ -399,39 +388,36 @@ public static function providerToNativeDateInterval(): array } /** - * @dataProvider providerToString - * * @param int $years The number of years in the period. * @param int $months The number of months in the period. * @param int $days The number of days in the period. * @param string $expected The expected string output. */ + #[DataProvider('providerToString')] public function testJsonSerialize(int $years, int $months, int $days, string $expected): void { self::assertSame(json_encode($expected, JSON_THROW_ON_ERROR), json_encode(Period::of($years, $months, $days), JSON_THROW_ON_ERROR)); } /** - * @dataProvider providerToString - * * @param int $years The number of years in the period. * @param int $months The number of months in the period. * @param int $days The number of days in the period. * @param string $expected The expected string output. */ + #[DataProvider('providerToString')] public function testToISOString(int $years, int $months, int $days, string $expected): void { self::assertSame($expected, Period::of($years, $months, $days)->toISOString()); } /** - * @dataProvider providerToString - * * @param int $years The number of years in the period. * @param int $months The number of months in the period. * @param int $days The number of days in the period. * @param string $expected The expected string output. */ + #[DataProvider('providerToString')] public function testToString(int $years, int $months, int $days, string $expected): void { self::assertSame($expected, (string) Period::of($years, $months, $days)); diff --git a/tests/StopwatchTest.php b/tests/StopwatchTest.php index beda46dc..8ea2b9bc 100644 --- a/tests/StopwatchTest.php +++ b/tests/StopwatchTest.php @@ -7,6 +7,7 @@ use Brick\DateTime\Clock\FixedClock; use Brick\DateTime\Instant; use Brick\DateTime\Stopwatch; +use PHPUnit\Framework\Attributes\Depends; /** * Unit tests for class Period. @@ -40,9 +41,7 @@ public function testNew(): Stopwatch return $stopwatch; } - /** - * @depends testNew - */ + #[Depends('testNew')] public function testStart(Stopwatch $stopwatch): Stopwatch { self::setClockTime(1000, 1); @@ -56,9 +55,7 @@ public function testStart(Stopwatch $stopwatch): Stopwatch return $stopwatch; } - /** - * @depends testStart - */ + #[Depends('testStart')] public function testElapsedTimeWhileRunning(Stopwatch $stopwatch): Stopwatch { self::setClockTime(2000, 0); @@ -80,9 +77,7 @@ public function testStopWithNullStartTime(): void self::assertDurationIs(0, 0, $stopwatch->getElapsedTime()); } - /** - * @depends testElapsedTimeWhileRunning - */ + #[Depends('testElapsedTimeWhileRunning')] public function testStop(Stopwatch $stopwatch): Stopwatch { self::setClockTime(3000, 2); @@ -96,9 +91,7 @@ public function testStop(Stopwatch $stopwatch): Stopwatch return $stopwatch; } - /** - * @depends testStop - */ + #[Depends('testStop')] public function testFrozenAfterStop(Stopwatch $stopwatch): Stopwatch { self::setClockTime(4000, 9); @@ -110,9 +103,7 @@ public function testFrozenAfterStop(Stopwatch $stopwatch): Stopwatch return $stopwatch; } - /** - * @depends testFrozenAfterStop - */ + #[Depends('testFrozenAfterStop')] public function testRestart(Stopwatch $stopwatch): Stopwatch { self::setClockTime(5000, 9); @@ -126,9 +117,7 @@ public function testRestart(Stopwatch $stopwatch): Stopwatch return $stopwatch; } - /** - * @depends testRestart - */ + #[Depends('testRestart')] public function testElapsedTimeWhileRunningAfterRestart(Stopwatch $stopwatch): Stopwatch { self::setClockTime(5001, 10); @@ -140,9 +129,7 @@ public function testElapsedTimeWhileRunningAfterRestart(Stopwatch $stopwatch): S return $stopwatch; } - /** - * @depends testElapsedTimeWhileRunningAfterRestart - */ + #[Depends('testElapsedTimeWhileRunningAfterRestart')] public function testStopAgain(Stopwatch $stopwatch): Stopwatch { self::setClockTime(5002, 20); @@ -156,9 +143,7 @@ public function testStopAgain(Stopwatch $stopwatch): Stopwatch return $stopwatch; } - /** - * @depends testStopAgain - */ + #[Depends('testStopAgain')] public function testFrozenAfterSecondStop(Stopwatch $stopwatch): void { self::setClockTime(6000, 999); diff --git a/tests/TimeZoneOffsetTest.php b/tests/TimeZoneOffsetTest.php index d0021396..ad8fb385 100644 --- a/tests/TimeZoneOffsetTest.php +++ b/tests/TimeZoneOffsetTest.php @@ -9,6 +9,7 @@ use Brick\DateTime\Parser\DateTimeParseException; use Brick\DateTime\TimeZoneOffset; use DateTimeImmutable; +use PHPUnit\Framework\Attributes\DataProvider; use const PHP_VERSION_ID; @@ -18,12 +19,11 @@ class TimeZoneOffsetTest extends AbstractTestCase { /** - * @dataProvider providerOf - * * @param int $hours The hours part of the offset. * @param int $minutes The minutes part of the offset. * @param int $totalSeconds The expected total number of seconds. */ + #[DataProvider('providerOf')] public function testOf(int $hours, int $minutes, int $seconds, int $totalSeconds): void { self::assertTimeZoneOffsetIs($totalSeconds, TimeZoneOffset::of($hours, $minutes, $seconds)); @@ -53,9 +53,7 @@ public static function providerOf(): iterable } } - /** - * @dataProvider providerOfInvalidValuesThrowsException - */ + #[DataProvider('providerOfInvalidValuesThrowsException')] public function testOfInvalidValuesThrowsException(int $hours, int $minutes, int $seconds): void { $this->expectException(DateTimeException::class); @@ -81,9 +79,7 @@ public static function providerOfInvalidValuesThrowsException(): iterable } } - /** - * @dataProvider providerTotalSeconds - */ + #[DataProvider('providerTotalSeconds')] public function testOfTotalSeconds(int $totalSeconds): void { self::assertTimeZoneOffsetIs($totalSeconds, TimeZoneOffset::ofTotalSeconds($totalSeconds)); @@ -111,9 +107,7 @@ public static function providerTotalSeconds(): iterable } } - /** - * @dataProvider providerOfInvalidTotalSecondsThrowsException - */ + #[DataProvider('providerOfInvalidTotalSecondsThrowsException')] public function testOfInvalidTotalSecondsThrowsException(int $totalSeconds): void { $this->expectException(DateTimeException::class); @@ -146,11 +140,10 @@ public function testUtc(): void } /** - * @dataProvider providerParse - * * @param string $text The text to parse. * @param int $totalSeconds The expected total offset seconds. */ + #[DataProvider('providerParse')] public function testParse(string $text, int $totalSeconds): void { self::assertTimeZoneOffsetIs($totalSeconds, TimeZoneOffset::parse($text)); @@ -177,9 +170,7 @@ public static function providerParse(): iterable } } - /** - * @dataProvider providerParseInvalidStringThrowsException - */ + #[DataProvider('providerParseInvalidStringThrowsException')] public function testParseInvalidStringThrowsException(string $text): void { $this->expectException(DateTimeParseException::class); @@ -200,9 +191,7 @@ public static function providerParseInvalidStringThrowsException(): array ]; } - /** - * @dataProvider providerParseInvalidValueThrowsException - */ + #[DataProvider('providerParseInvalidValueThrowsException')] public function testParseInvalidValueThrowsException(string $text): void { $this->expectException(DateTimeException::class); @@ -229,22 +218,20 @@ public static function providerParseInvalidValueThrowsException(): iterable } /** - * @dataProvider providerGetId - * * @param int $totalSeconds The total offset seconds. * @param string $expectedId The expected id. */ + #[DataProvider('providerGetId')] public function testGetId(int $totalSeconds, string $expectedId): void { self::assertSame($expectedId, TimeZoneOffset::ofTotalSeconds($totalSeconds)->getId()); } /** - * @dataProvider providerGetId - * * @param int $totalSeconds The total offset seconds. * @param string $string The expected string. */ + #[DataProvider('providerGetId')] public function testToString(int $totalSeconds, string $string): void { self::assertSame($string, (string) TimeZoneOffset::ofTotalSeconds($totalSeconds)); @@ -289,11 +276,10 @@ public function testGetOffset(): void } /** - * @dataProvider providerToNativeDateTimeZone - * * @param int $totalSeconds The total offset seconds. * @param string $string The expected string. */ + #[DataProvider('providerToNativeDateTimeZone')] public function testToNativeDateTimeZone(int $totalSeconds, string $string): void { $dateTimeZone = TimeZoneOffset::ofTotalSeconds($totalSeconds)->toNativeDateTimeZone(); diff --git a/tests/TimeZoneRegionTest.php b/tests/TimeZoneRegionTest.php index fefc4fd3..ce6219e6 100644 --- a/tests/TimeZoneRegionTest.php +++ b/tests/TimeZoneRegionTest.php @@ -9,6 +9,7 @@ use Brick\DateTime\Parser\DateTimeParseException; use Brick\DateTime\TimeZoneRegion; use DateTimeZone; +use PHPUnit\Framework\Attributes\DataProvider; use function count; @@ -22,9 +23,7 @@ public function testOf(): void self::assertSame('Europe/London', TimeZoneRegion::of('Europe/London')->getId()); } - /** - * @dataProvider providerOfInvalidRegionThrowsException - */ + #[DataProvider('providerOfInvalidRegionThrowsException')] public function testOfInvalidRegionThrowsException(string $region): void { $this->expectException(DateTimeException::class); @@ -48,9 +47,7 @@ public function testParse(): void self::assertSame('Europe/London', TimeZoneRegion::parse('Europe/London')->getId()); } - /** - * @dataProvider providerParseInvalidStringThrowsException - */ + #[DataProvider('providerParseInvalidStringThrowsException')] public function testParseInvalidStringThrowsException(string $text): void { $this->expectException(DateTimeParseException::class); @@ -65,9 +62,7 @@ public static function providerParseInvalidStringThrowsException(): array ]; } - /** - * @dataProvider providerGetAllTimeZones - */ + #[DataProvider('providerGetAllTimeZones')] public function testGetAllTimeZones(bool $includeObsolete): void { $identifiers = TimeZoneRegion::getAllIdentifiers($includeObsolete); @@ -106,9 +101,7 @@ public static function providerGetAllTimeZones(): array ]; } - /** - * @dataProvider providerGetTimeZonesForCountry - */ + #[DataProvider('providerGetTimeZonesForCountry')] public function testGetTimeZonesForCountry(string $countryCode, string ...$expectedIdentifiers): void { $identifiers = TimeZoneRegion::getIdentifiersForCountry($countryCode); @@ -132,12 +125,11 @@ public static function providerGetTimeZonesForCountry(): array } /** - * @dataProvider providerGetOffset - * * @param string $region The time-zone region. * @param int $epochSecond The instant to test. * @param int $expectedOffset The expected offset in seconds. */ + #[DataProvider('providerGetOffset')] public function testGetOffset(string $region, int $epochSecond, int $expectedOffset): void { $actualOffset = TimeZoneRegion::of($region)->getOffset(Instant::of($epochSecond)); diff --git a/tests/TimeZoneTest.php b/tests/TimeZoneTest.php index a2e04dbb..227aead4 100644 --- a/tests/TimeZoneTest.php +++ b/tests/TimeZoneTest.php @@ -9,6 +9,7 @@ use Brick\DateTime\TimeZoneOffset; use Brick\DateTime\TimeZoneRegion; use DateTimeZone; +use PHPUnit\Framework\Attributes\DataProvider; use const PHP_VERSION_ID; @@ -18,12 +19,11 @@ class TimeZoneTest extends AbstractTestCase { /** - * @dataProvider providerParse - * * @param string $text The text to parse. * @param string $class The expected class name. * @param string $id The expected id. */ + #[DataProvider('providerParse')] public function testParse(string $text, string $class, string $id): void { $timeZone = TimeZone::parse($text); @@ -48,9 +48,7 @@ public static function providerParse(): iterable } } - /** - * @dataProvider providerParseInvalidStringThrowsException - */ + #[DataProvider('providerParseInvalidStringThrowsException')] public function testParseInvalidStringThrowsException(string $text): void { $this->expectException(DateTimeParseException::class); @@ -81,10 +79,9 @@ public function testIsEqualTo(): void } /** - * @dataProvider providerFromNativeDateTimeZone - * * @param string $tz The time-zone name. */ + #[DataProvider('providerFromNativeDateTimeZone')] public function testFromNativeDateTimeZone(string $tz): void { $dateTimeZone = new DateTimeZone($tz); diff --git a/tests/Utility/MathTest.php b/tests/Utility/MathTest.php index c18e1175..4262740d 100644 --- a/tests/Utility/MathTest.php +++ b/tests/Utility/MathTest.php @@ -5,6 +5,7 @@ namespace Brick\DateTime\Tests\Utility; use Brick\DateTime\Utility\Math; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -13,12 +14,11 @@ class MathTest extends TestCase { /** - * @dataProvider providerFloorDiv - * * @param int $a The dividend. * @param int $b The divisor. * @param int $expected The expected floor division result. */ + #[DataProvider('providerFloorDiv')] public function testFloorDiv(int $a, int $b, int $expected): void { self::assertSame($expected, Math::floorDiv($a, $b)); @@ -35,12 +35,11 @@ public static function providerFloorDiv(): array } /** - * @dataProvider providerFloorMod - * * @param int $a The dividend. * @param int $b The divisor. * @param int $expected The expected floor modulus result. */ + #[DataProvider('providerFloorMod')] public function testFloorMod(int $a, int $b, int $expected): void { self::assertSame($expected, Math::floorMod($a, $b)); diff --git a/tests/YearMonthRangeTest.php b/tests/YearMonthRangeTest.php index 18c26d4e..f61ea4a8 100644 --- a/tests/YearMonthRangeTest.php +++ b/tests/YearMonthRangeTest.php @@ -8,6 +8,7 @@ use Brick\DateTime\Parser\DateTimeParseException; use Brick\DateTime\YearMonth; use Brick\DateTime\YearMonthRange; +use PHPUnit\Framework\Attributes\DataProvider; use function json_encode; @@ -37,14 +38,13 @@ public function testOfInvalidRangeThrowsException(): void } /** - * @dataProvider providerParse - * * @param string $text The text to parse. * @param int $y1 The expected start year. * @param int $m1 The expected start month. * @param int $y2 The expected end year. * @param int $m2 The expected end month. */ + #[DataProvider('providerParse')] public function testParse(string $text, int $y1, int $m1, int $y2, int $m2): void { self::assertYearMonthRangeIs($y1, $m1, $y2, $m2, YearMonthRange::parse($text)); @@ -59,10 +59,9 @@ public static function providerParse(): array } /** - * @dataProvider providerParseInvalidRangeThrowsException - * * @param string $text The invalid text to parse. */ + #[DataProvider('providerParseInvalidRangeThrowsException')] public function testParseInvalidRangeThrowsException(string $text): void { $this->expectException(DateTimeParseException::class); @@ -83,11 +82,10 @@ public static function providerParseInvalidRangeThrowsException(): array } /** - * @dataProvider providerIsEqualTo - * * @param string $testRange The string representation of the range to test. * @param bool $isEqual Whether this range is expected to be equal to our range. */ + #[DataProvider('providerIsEqualTo')] public function testIsEqualTo(string $testRange, bool $isEqual): void { self::assertSame($isEqual, YearMonthRange::of( @@ -107,9 +105,7 @@ public static function providerIsEqualTo(): array ]; } - /** - * @dataProvider providerContains - */ + #[DataProvider('providerContains')] public function testContains(string $range, string $yearMonth, bool $contains): void { self::assertSame($contains, YearMonthRange::parse($range)->contains(YearMonth::parse($yearMonth))); @@ -159,11 +155,10 @@ public function testIterator(): void } /** - * @dataProvider providerCount - * * @param string $range The year-month range string representation. * @param int $count The expected day count. */ + #[DataProvider('providerCount')] public function testCount(string $range, int $count): void { self::assertCount($count, YearMonthRange::parse($range)); @@ -180,9 +175,7 @@ public static function providerCount(): array ]; } - /** - * @dataProvider providerToLocalDateRange - */ + #[DataProvider('providerToLocalDateRange')] public function testToLocalDateRange(string $yearMonthRange, string $expectedRange): void { self::assertSame($expectedRange, (string) YearMonthRange::parse($yearMonthRange)->toLocalDateRange()); @@ -199,7 +192,7 @@ public static function providerToLocalDateRange(): array ]; } - /** @dataProvider providerToString */ + #[DataProvider('providerToString')] public function testJsonSerialize(int $yearStart, int $monthStart, int $yearEnd, int $monthEnd, string $expectedString): void { $yearMonthRange = YearMonthRange::of( @@ -210,7 +203,7 @@ public function testJsonSerialize(int $yearStart, int $monthStart, int $yearEnd, self::assertSame(json_encode($expectedString, JSON_THROW_ON_ERROR), json_encode($yearMonthRange, JSON_THROW_ON_ERROR)); } - /** @dataProvider providerToString */ + #[DataProvider('providerToString')] public function testToISOString(int $yearStart, int $monthStart, int $yearEnd, int $monthEnd, string $expectedString): void { $yearMonthRange = YearMonthRange::of( @@ -221,7 +214,7 @@ public function testToISOString(int $yearStart, int $monthStart, int $yearEnd, i self::assertSame($expectedString, $yearMonthRange->toISOString()); } - /** @dataProvider providerToString */ + #[DataProvider('providerToString')] public function testToString(int $yearStart, int $monthStart, int $yearEnd, int $monthEnd, string $expectedString): void { $yearMonthRange = YearMonthRange::of( diff --git a/tests/YearMonthTest.php b/tests/YearMonthTest.php index eb93a9ff..83548969 100644 --- a/tests/YearMonthTest.php +++ b/tests/YearMonthTest.php @@ -10,6 +10,7 @@ use Brick\DateTime\Month; use Brick\DateTime\TimeZone; use Brick\DateTime\YearMonth; +use PHPUnit\Framework\Attributes\DataProvider; use function json_encode; @@ -27,12 +28,11 @@ public function testOf(): void } /** - * @dataProvider providerParse - * * @param string $text The text to parse. * @param int $year The expected year. * @param int $month The expected month. */ + #[DataProvider('providerParse')] public function testParse(string $text, int $year, int $month): void { self::assertYearMonthIs($year, $month, YearMonth::parse($text)); @@ -50,10 +50,9 @@ public static function providerParse(): array } /** - * @dataProvider providerParseInvalidStringThrowsException - * * @param string $text The text to parse. */ + #[DataProvider('providerParseInvalidStringThrowsException')] public function testParseInvalidStringThrowsException(string $text): void { $this->expectException(DateTimeException::class); @@ -73,10 +72,9 @@ public static function providerParseInvalidStringThrowsException(): array } /** - * @dataProvider providerParseInvalidYearMonthThrowsException - * * @param string $text The text to parse. */ + #[DataProvider('providerParseInvalidYearMonthThrowsException')] public function testParseInvalidYearMonthThrowsException(string $text): void { $this->expectException(DateTimeException::class); @@ -92,13 +90,12 @@ public static function providerParseInvalidYearMonthThrowsException(): array } /** - * @dataProvider providerNow - * * @param int $epochSecond The epoch second. * @param string $timeZone The time-zone. * @param int $year The expected year. * @param int $month The expected month. */ + #[DataProvider('providerNow')] public function testNow(int $epochSecond, string $timeZone, int $year, int $month): void { $clock = new FixedClock(Instant::of($epochSecond)); @@ -116,12 +113,11 @@ public static function providerNow(): array } /** - * @dataProvider providerIsLeapYear - * * @param int $year The year to test. * @param int $month The month to test. * @param bool $isLeap The expected result. */ + #[DataProvider('providerIsLeapYear')] public function testIsLeapYear(int $year, int $month, bool $isLeap): void { self::assertSame($isLeap, YearMonth::of($year, $month)->isLeapYear()); @@ -140,12 +136,11 @@ public static function providerIsLeapYear(): array } /** - * @dataProvider providerGetLengthOfMonth - * * @param int $year The year. * @param int $month The month. * @param int $length The expected length of month. */ + #[DataProvider('providerGetLengthOfMonth')] public function testGetLengthOfMonth(int $year, int $month, int $length): void { self::assertSame($length, YearMonth::of($year, $month)->getLengthOfMonth()); @@ -182,12 +177,11 @@ public static function providerGetLengthOfMonth(): array } /** - * @dataProvider providerGetLengthOfYear - * * @param int $year The year. * @param int $month The month. * @param int $length The expected length of year. */ + #[DataProvider('providerGetLengthOfYear')] public function testGetLengthOfYear(int $year, int $month, int $length): void { self::assertSame($length, YearMonth::of($year, $month)->getLengthOfYear()); @@ -203,84 +197,78 @@ public static function providerGetLengthOfYear(): array } /** - * @dataProvider providerCompareTo - * * @param int $y1 The year of the base year-month. * @param int $m1 The month of the base year-month. * @param int $y2 The year of the year-month to compare to. * @param int $m2 The month of the year-month to compare to. * @param int $result The expected result. */ + #[DataProvider('providerCompareTo')] public function testCompareTo(int $y1, int $m1, int $y2, int $m2, int $result): void { self::assertSame($result, YearMonth::of($y1, $m1)->compareTo(YearMonth::of($y2, $m2))); } /** - * @dataProvider providerCompareTo - * * @param int $y1 The year of the base year-month. * @param int $m1 The month of the base year-month. * @param int $y2 The year of the year-month to compare to. * @param int $m2 The month of the year-month to compare to. * @param int $result The comparison result. */ + #[DataProvider('providerCompareTo')] public function testIsEqualTo(int $y1, int $m1, int $y2, int $m2, int $result): void { self::assertSame($result === 0, YearMonth::of($y1, $m1)->isEqualTo(YearMonth::of($y2, $m2))); } /** - * @dataProvider providerCompareTo - * * @param int $y1 The year of the base year-month. * @param int $m1 The month of the base year-month. * @param int $y2 The year of the year-month to compare to. * @param int $m2 The month of the year-month to compare to. * @param int $result The comparison result. */ + #[DataProvider('providerCompareTo')] public function testIsBefore(int $y1, int $m1, int $y2, int $m2, int $result): void { self::assertSame($result === -1, YearMonth::of($y1, $m1)->isBefore(YearMonth::of($y2, $m2))); } /** - * @dataProvider providerCompareTo - * * @param int $y1 The year of the base year-month. * @param int $m1 The month of the base year-month. * @param int $y2 The year of the year-month to compare to. * @param int $m2 The month of the year-month to compare to. * @param int $result The comparison result. */ + #[DataProvider('providerCompareTo')] public function testIsBeforeOrEqualTo(int $y1, int $m1, int $y2, int $m2, int $result): void { self::assertSame($result <= 0, YearMonth::of($y1, $m1)->isBeforeOrEqualTo(YearMonth::of($y2, $m2))); } /** - * @dataProvider providerCompareTo - * * @param int $y1 The year of the base year-month. * @param int $m1 The month of the base year-month. * @param int $y2 The year of the year-month to compare to. * @param int $m2 The month of the year-month to compare to. * @param int $result The comparison result. */ + #[DataProvider('providerCompareTo')] public function testIsAfter(int $y1, int $m1, int $y2, int $m2, int $result): void { self::assertSame($result === 1, YearMonth::of($y1, $m1)->isAfter(YearMonth::of($y2, $m2))); } /** - * @dataProvider providerCompareTo - * * @param int $y1 The year of the base year-month. * @param int $m1 The month of the base year-month. * @param int $y2 The year of the year-month to compare to. * @param int $m2 The month of the year-month to compare to. * @param int $result The comparison result. */ + #[DataProvider('providerCompareTo')] public function testIsAfterOrEqualTo(int $y1, int $m1, int $y2, int $m2, int $result): void { self::assertSame($result >= 0, YearMonth::of($y1, $m1)->isAfterOrEqualTo(YearMonth::of($y2, $m2))); @@ -335,9 +323,7 @@ public function testGetFirstDay(): void self::assertLocalDateIs(2023, 10, 1, YearMonth::of(2023, 10)->getFirstDay()); } - /** - * @dataProvider providerGetLastDay - */ + #[DataProvider('providerGetLastDay')] public function testGetLastDay(int $year, int $month, int $day): void { self::assertLocalDateIs($year, $month, $day, YearMonth::of($year, $month)->getLastDay()); @@ -359,9 +345,7 @@ public function testAtDay(): void self::assertLocalDateIs(2001, 2, 3, YearMonth::of(2001, 02)->atDay(3)); } - /** - * @dataProvider providerPlusYears - */ + #[DataProvider('providerPlusYears')] public function testPlusYears(int $year, int $month, int $plusYears, int $expectedYear, int $expectedMonth): void { $yearMonth = YearMonth::of($year, $month); @@ -382,9 +366,7 @@ public static function providerPlusYears(): array ]; } - /** - * @dataProvider providerMinusYears - */ + #[DataProvider('providerMinusYears')] public function testMinusYears(int $year, int $month, int $plusYears, int $expectedYear, int $expectedMonth): void { $yearMonth = YearMonth::of($year, $month); @@ -399,9 +381,7 @@ public static function providerMinusYears(): array ]; } - /** - * @dataProvider providerPlusMonths - */ + #[DataProvider('providerPlusMonths')] public function testPlusMonths(int $year, int $month, int $plusMonths, int $expectedYear, int $expectedMonth): void { $yearMonth = YearMonth::of($year, $month); @@ -423,9 +403,7 @@ public static function providerPlusMonths(): array ]; } - /** - * @dataProvider providerMinusMonths - */ + #[DataProvider('providerMinusMonths')] public function testMinusMonths(int $year, int $month, int $plusMonths, int $expectedYear, int $expectedMonth): void { $yearMonth = YearMonth::of($year, $month); @@ -447,9 +425,7 @@ public static function providerMinusMonths(): array ]; } - /** - * @dataProvider providerToLocalDateRange - */ + #[DataProvider('providerToLocalDateRange')] public function testToLocalDateRange(int $year, int $month, string $expectedRange): void { self::assertSame($expectedRange, (string) YearMonth::of($year, $month)->toLocalDateRange()); @@ -465,29 +441,24 @@ public static function providerToLocalDateRange(): array ]; } - /** - * @dataProvider providerToString - */ + #[DataProvider('providerToString')] public function testJsonSerialize(int $year, int $month, string $expectedString): void { self::assertSame(json_encode($expectedString, JSON_THROW_ON_ERROR), json_encode(YearMonth::of($year, $month), JSON_THROW_ON_ERROR)); } - /** - * @dataProvider providerToString - */ + #[DataProvider('providerToString')] public function testToISOString(int $year, int $month, string $expectedString): void { self::assertSame($expectedString, YearMonth::of($year, $month)->toISOString()); } /** - * @dataProvider providerToString - * * @param int $year The year. * @param int $month The month. * @param string $expected The expected result string. */ + #[DataProvider('providerToString')] public function testToString(int $year, int $month, string $expected): void { self::assertSame($expected, (string) YearMonth::of($year, $month)); diff --git a/tests/YearTest.php b/tests/YearTest.php index 5265ec03..e6890d88 100644 --- a/tests/YearTest.php +++ b/tests/YearTest.php @@ -11,6 +11,7 @@ use Brick\DateTime\MonthDay; use Brick\DateTime\TimeZone; use Brick\DateTime\Year; +use PHPUnit\Framework\Attributes\DataProvider; use function json_encode; @@ -28,18 +29,14 @@ public function testOf(): void self::assertYearIs(1987, Year::of(1987)); } - /** - * @dataProvider providerOfInvalidYearThrowsException - */ + #[DataProvider('providerOfInvalidYearThrowsException')] public function testOfInvalidYearThrowsException(int $invalidYear): void { $this->expectException(DateTimeException::class); Year::of($invalidYear); } - /** - * @dataProvider providerParse - */ + #[DataProvider('providerParse')] public function testParse(string $string, int $expectedYear): void { self::assertYearIs($expectedYear, Year::parse($string)); @@ -55,9 +52,7 @@ public static function providerParse(): array ]; } - /** - * @dataProvider providerParseInvalidYearThrowsException - */ + #[DataProvider('providerParseInvalidYearThrowsException')] public function testParseInvalidYearThrowsException(string $invalidValue): void { $this->expectException(DateTimeException::class); @@ -88,12 +83,11 @@ public static function providerOfInvalidYearThrowsException(): array } /** - * @dataProvider providerNow - * * @param int $epochSecond The epoch second to set the clock time to. * @param string $timeZone The time-zone to get the current year in. * @param int $expectedYear The expected year. */ + #[DataProvider('providerNow')] public function testNow(int $epochSecond, string $timeZone, int $expectedYear): void { $clock = new FixedClock(Instant::of($epochSecond)); @@ -113,11 +107,10 @@ public static function providerNow(): array } /** - * @dataProvider providerIsLeap - * * @param int $year The year to test. * @param bool $isLeap Whether the year is a leap year. */ + #[DataProvider('providerIsLeap')] public function testIsLeap(int $year, bool $isLeap): void { self::assertSame($isLeap, Year::of($year)->isLeap()); @@ -185,13 +178,12 @@ public static function providerIsLeap(): array } /** - * @dataProvider providerIsValidMonthDay - * * @param int $year The base year. * @param int $month The month of the month-day to test. * @param int $day The day-of-month of the month-day to test. * @param bool $isValid Whether the month-day is expected to be valid. */ + #[DataProvider('providerIsValidMonthDay')] public function testIsValidMonthDay(int $year, int $month, int $day, bool $isValid): void { self::assertSame($isValid, Year::of($year)->isValidMonthDay(MonthDay::of($month, $day))); @@ -213,11 +205,10 @@ public static function providerIsValidMonthDay(): array } /** - * @dataProvider providerGetLength - * * @param int $year The year to test. * @param int $length The expected length of year in days. */ + #[DataProvider('providerGetLength')] public function testGetLength(int $year, int $length): void { self::assertSame($length, Year::of($year)->getLength()); @@ -284,9 +275,7 @@ public static function providerGetLength(): array ]; } - /** - * @dataProvider providerPlus - */ + #[DataProvider('providerPlus')] public function testPlus(int $year, int $plusYears, int $expectedYear): void { self::assertYearIs($expectedYear, Year::of($year)->plus($plusYears)); @@ -301,9 +290,7 @@ public static function providerPlus(): array ]; } - /** - * @dataProvider providerMinus - */ + #[DataProvider('providerMinus')] public function testMinus(int $year, int $minusYears, int $expectedYear): void { self::assertYearIs($expectedYear, Year::of($year)->minus($minusYears)); @@ -319,48 +306,44 @@ public static function providerMinus(): array } /** - * @dataProvider providerCompareTo - * * @param int $year1 The base year. * @param int $year2 The year to compare to. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareTo')] public function testCompareTo(int $year1, int $year2, int $cmp): void { self::assertSame($cmp, Year::of($year1)->compareTo(Year::of($year2))); } /** - * @dataProvider providerCompareTo - * * @param int $year1 The base year. * @param int $year2 The year to compare to. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareTo')] public function testIsEqualTo(int $year1, int $year2, int $cmp): void { self::assertSame($cmp === 0, Year::of($year1)->isEqualTo(Year::of($year2))); } /** - * @dataProvider providerCompareTo - * * @param int $year1 The base year. * @param int $year2 The year to compare to. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareTo')] public function testIsAfter(int $year1, int $year2, int $cmp): void { self::assertSame($cmp === 1, Year::of($year1)->isAfter(Year::of($year2))); } /** - * @dataProvider providerCompareTo - * * @param int $year1 The base year. * @param int $year2 The year to compare to. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareTo')] public function testIsBefore(int $year1, int $year2, int $cmp): void { self::assertSame($cmp === -1, Year::of($year1)->isBefore(Year::of($year2))); @@ -398,13 +381,12 @@ public static function providerCompareTo(): array } /** - * @dataProvider providerAtDay - * * @param int $year The base year. * @param int $dayOfYear The day-of-year to apply. * @param int $month The expected month of the resulting date. * @param int $day The expected day-of-month of the resulting date. */ + #[DataProvider('providerAtDay')] public function testAtDay(int $year, int $dayOfYear, int $month, int $day): void { self::assertLocalDateIs($year, $month, $day, Year::of($year)->atDay($dayOfYear)); @@ -436,9 +418,7 @@ public function testAtMonth(): void self::assertYearMonthIs(2014, 7, Year::of(2014)->atMonth(Month::JULY)); } - /** - * @dataProvider providerAtInvalidMonthThrowsException - */ + #[DataProvider('providerAtInvalidMonthThrowsException')] public function testAtInvalidMonthThrowsException(int $invalidMonth): void { $this->expectException(DateTimeException::class); @@ -455,13 +435,12 @@ public static function providerAtInvalidMonthThrowsException(): array } /** - * @dataProvider providerAtMonthDay - * * @param int $year The base year. * @param int $month The month-of-year of the month-day to apply. * @param int $day The day-of-month of the month-day to apply. * @param int $expectedDay The expected day of the resulting date. */ + #[DataProvider('providerAtMonthDay')] public function testAtMonthDay(int $year, int $month, int $day, int $expectedDay): void { $monthDay = MonthDay::of($month, $day); @@ -481,9 +460,7 @@ public static function providerAtMonthDay(): array ]; } - /** - * @dataProvider providerToLocalDateRange - */ + #[DataProvider('providerToLocalDateRange')] public function testToLocalDateRange(int $year, string $expectedRange): void { self::assertSame($expectedRange, (string) Year::of($year)->toLocalDateRange()); @@ -498,19 +475,19 @@ public static function providerToLocalDateRange(): array ]; } - /** @dataProvider providerToString */ + #[DataProvider('providerToString')] public function testJsonSerialize(int $year, string $expectedString): void { self::assertSame(json_encode($expectedString, JSON_THROW_ON_ERROR), json_encode(Year::of($year), JSON_THROW_ON_ERROR)); } - /** @dataProvider providerToString */ + #[DataProvider('providerToString')] public function testToISOString(int $year, string $expectedString): void { self::assertSame($expectedString, Year::of($year)->toISOString()); } - /** @dataProvider providerToString */ + #[DataProvider('providerToString')] public function testToString(int $year, string $expectedString): void { self::assertSame($expectedString, (string) Year::of($year)); diff --git a/tests/YearWeekTest.php b/tests/YearWeekTest.php index e19fc408..cf3935be 100644 --- a/tests/YearWeekTest.php +++ b/tests/YearWeekTest.php @@ -12,6 +12,7 @@ use Brick\DateTime\LocalDateRange; use Brick\DateTime\TimeZone; use Brick\DateTime\YearWeek; +use PHPUnit\Framework\Attributes\DataProvider; use function json_encode; @@ -22,9 +23,7 @@ */ class YearWeekTest extends AbstractTestCase { - /** - * @dataProvider provider53WeekYear - */ + #[DataProvider('provider53WeekYear')] public function testIs53WeekYear(int $year): void { $yearWeek = YearWeek::of($year, 1); @@ -108,9 +107,7 @@ public static function provider53WeekYear(): array ]; } - /** - * @dataProvider providerAtDay - */ + #[DataProvider('providerAtDay')] public function testAtDay(int $weekBasedYear, int $weekOfWeekBasedYear, DayOfWeek $dayOfWeek, int $year, int $month, int $dayOfMonth): void { $yearWeek = YearWeek::of($weekBasedYear, $weekOfWeekBasedYear); @@ -208,9 +205,7 @@ public static function providerWithYear(): array ]; } - /** - * @dataProvider providerWithYear - */ + #[DataProvider('providerWithYear')] public function testWithYear(int $year, int $week, int $withYear, int $expectedYear, int $expectedWeek): void { $yearWeek = YearWeek::of($year, $week)->withYear($withYear); @@ -226,9 +221,7 @@ public static function providerWithWeek(): array ]; } - /** - * @dataProvider providerWithWeek - */ + #[DataProvider('providerWithWeek')] public function testWithWeek(int $year, int $week, int $withWeek, int $expectedYear, int $expectedWeek): void { $yearWeek = YearWeek::of($year, $week)->withWeek($withWeek); @@ -251,18 +244,14 @@ public static function providerPlusYears(): array ]; } - /** - * @dataProvider providerPlusYears - */ + #[DataProvider('providerPlusYears')] public function testPlusYears(int $year, int $week, int $delta, int $expectedYear, int $expectedWeek): void { $yearWeek = YearWeek::of($year, $week)->plusYears($delta); self::assertYearWeekIs($expectedYear, $expectedWeek, $yearWeek); } - /** - * @dataProvider providerPlusYears - */ + #[DataProvider('providerPlusYears')] public function testMinusYears(int $year, int $week, int $delta, int $expectedYear, int $expectedWeek): void { $yearWeek = YearWeek::of($year, $week)->minusYears(-$delta); @@ -288,18 +277,14 @@ public static function providerPlusWeeks(): array ]; } - /** - * @dataProvider providerPlusWeeks - */ + #[DataProvider('providerPlusWeeks')] public function testPlusWeeks(int $year, int $week, int $delta, int $expectedYear, int $expectedWeek): void { $yearWeek = YearWeek::of($year, $week)->plusWeeks($delta); self::assertYearWeekIs($expectedYear, $expectedWeek, $yearWeek); } - /** - * @dataProvider providerPlusWeeks - */ + #[DataProvider('providerPlusWeeks')] public function testMinusWeeks(int $year, int $week, int $delta, int $expectedYear, int $expectedWeek): void { $yearWeek = YearWeek::of($year, $week)->minusWeeks(-$delta); @@ -323,36 +308,28 @@ public static function providerToString(): array ]; } - /** - * @dataProvider providerToString - */ + #[DataProvider('providerToString')] public function testJsonSerialize(int $year, int $week, string $expected): void { $yearWeek = YearWeek::of($year, $week); self::assertSame(json_encode($expected, JSON_THROW_ON_ERROR), json_encode($yearWeek, JSON_THROW_ON_ERROR)); } - /** - * @dataProvider providerToString - */ + #[DataProvider('providerToString')] public function testToISOString(int $year, int $week, string $expected): void { $yearWeek = YearWeek::of($year, $week); self::assertSame($expected, $yearWeek->toISOString()); } - /** - * @dataProvider providerToString - */ + #[DataProvider('providerToString')] public function testToString(int $year, int $week, string $expected): void { $yearWeek = YearWeek::of($year, $week); self::assertSame($expected, (string) $yearWeek); } - /** - * @dataProvider providerParse - */ + #[DataProvider('providerParse')] public function testParse(string $string, int $expectedYear, int $expectedWeek): void { $yearWeek = YearWeek::parse($string); @@ -371,9 +348,7 @@ public static function providerParse(): array ]; } - /** - * @dataProvider providerParseInvalidYearWeekThrowsException - */ + #[DataProvider('providerParseInvalidYearWeekThrowsException')] public function testParseInvalidYearWeekThrowsException(string $invalidValue, ?string $error = null): void { $this->expectException(DateTimeException::class); @@ -403,13 +378,12 @@ public function testNow(): void } /** - * @dataProvider providerGetFirstLastDay - * * @param int $year The year. * @param int $week The week-of-year. * @param string $firstDay The expected first day of the week. * @param string $lastDay The expected last day of the week. */ + #[DataProvider('providerGetFirstLastDay')] public function testGetFirstLastDay(int $year, int $week, string $firstDay, string $lastDay): void { $yearWeek = YearWeek::of($year, $week); @@ -418,9 +392,7 @@ public function testGetFirstLastDay(int $year, int $week, string $firstDay, stri self::assertIs(LocalDate::class, $lastDay, $yearWeek->getLastDay()); } - /** - * @dataProvider providerGetFirstLastDay - */ + #[DataProvider('providerGetFirstLastDay')] public function testToLocalDateRange(int $year, int $week, string $firstDay, string $lastDay): void { $yearWeek = YearWeek::of($year, $week); diff --git a/tests/ZonedDateTimeTest.php b/tests/ZonedDateTimeTest.php index 835e38ba..bead3577 100644 --- a/tests/ZonedDateTimeTest.php +++ b/tests/ZonedDateTimeTest.php @@ -20,7 +20,9 @@ use DateTime; use DateTimeImmutable; use DateTimeZone; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use function json_encode; use const JSON_THROW_ON_ERROR; @@ -32,8 +34,6 @@ class ZonedDateTimeTest extends AbstractTestCase { /** - * @dataProvider providerOf - * * @param string $localDateTime The local date-time as a string. * @param string $timeZone The time-zone as a string. * @param string $offset The expected time-zone offset of the result zoned date-time. @@ -41,6 +41,7 @@ class ZonedDateTimeTest extends AbstractTestCase * @param int $epochSecond The expected epoch-second the result zoned date-time resolves to. * @param int $nanoOfSecond The expected nano-of-second of the result zoned date-time. */ + #[DataProvider('providerOf')] public function testOf(string $localDateTime, string $timeZone, string $offset, int $shift, int $epochSecond, int $nanoOfSecond): void { $localDateTime = LocalDateTime::parse($localDateTime); @@ -328,9 +329,7 @@ public static function providerOf(): array ]; } - /** - * @dataProvider providerOfInstant - */ + #[DataProvider('providerOfInstant')] public function testOfInstant(string $formattedDatetime, string $timeZone): void { $instant = Instant::of(1000000000); @@ -349,14 +348,13 @@ public static function providerOfInstant(): array } /** - * @dataProvider providerParse - * * @param string $text The string to parse. * @param string $date The expected date string. * @param string $time The expected time string. * @param string $offset The expected time-zone offset. * @param string $zone The expected time-zone, should be the same as offset when no region is specified. */ + #[DataProvider('providerParse')] public function testParse(string $text, string $date, string $time, string $offset, string $zone): void { $zonedDateTime = ZonedDateTime::parse($text); @@ -387,9 +385,7 @@ public static function providerParse(): iterable } } - /** - * @dataProvider providerParseInvalidStringThrowsException - */ + #[DataProvider('providerParseInvalidStringThrowsException')] public function testParseInvalidStringThrowsException(string $text): void { $this->expectException(DateTimeParseException::class); @@ -422,11 +418,8 @@ public static function providerParseInvalidStringThrowsException(): array ]; } - /** - * @dataProvider providerParseSecondsOffsetThrowsException - * - * @requires PHP < 8.1.7 - */ + #[RequiresPhp('< 8.1.7')] + #[DataProvider('providerParseSecondsOffsetThrowsException')] public function testParseSecondsOffsetThrowsException(string $text): void { $this->expectException(DateTimeException::class); @@ -440,9 +433,7 @@ public static function providerParseSecondsOffsetThrowsException(): array ]; } - /** - * @dataProvider providerFromNativeDateTime - */ + #[DataProvider('providerFromNativeDateTime')] public function testFromNativeDateTime(string $dateTimeString, string $timeZone, string $expected): void { $dateTime = new DateTime($dateTimeString, new DateTimeZone($timeZone)); @@ -478,12 +469,11 @@ public function testChangeTimeZone(): void } /** - * @dataProvider providerCompareTo - * * @param string $z1 The first zoned date-time. * @param string $z2 The second zoned date-time. * @param int $cmp The comparison value. */ + #[DataProvider('providerCompareTo')] public function testCompareTo(string $z1, string $z2, int $cmp): void { $z1 = ZonedDateTime::parse($z1); @@ -751,9 +741,7 @@ public function testIsBetweenExclusive(): void self::assertFalse($fromZonedDateTime->isBetweenExclusive($fromZonedDateTime, $toZonedDateTime)); } - /** - * @dataProvider providerForPastFuture - */ + #[DataProvider('providerForPastFuture')] public function testIsFuture(int $clockTimestamp, string $zonedDateTime, bool $isFuture): void { $clock = new FixedClock(Instant::of($clockTimestamp)); @@ -761,9 +749,7 @@ public function testIsFuture(int $clockTimestamp, string $zonedDateTime, bool $i self::assertSame($isFuture, $zonedDateTime->isFuture($clock)); } - /** - * @dataProvider providerForPastFuture - */ + #[DataProvider('providerForPastFuture')] public function testIsPast(int $clockTimestamp, string $zonedDateTime, bool $isFuture): void { $clock = new FixedClock(Instant::of($clockTimestamp)); @@ -782,11 +768,10 @@ public static function providerForPastFuture(): array } /** - * @dataProvider providerToNativeDateTime - * * @param string $dateTime The date-time string that will be parse()d by ZonedDateTime. * @param string $expected The expected output from the native DateTime object. */ + #[DataProvider('providerToNativeDateTime')] public function testToNativeDateTime(string $dateTime, string $expected): void { $zonedDateTime = ZonedDateTime::parse($dateTime); @@ -797,11 +782,10 @@ public function testToNativeDateTime(string $dateTime, string $expected): void } /** - * @dataProvider providerToNativeDateTime - * * @param string $dateTime The date-time string that will be parse()d by ZonedDateTime. * @param string $expected The expected output from the native DateTime object. */ + #[DataProvider('providerToNativeDateTime')] public function testToNativeDateTimeImmutable(string $dateTime, string $expected): void { $zonedDateTime = ZonedDateTime::parse($dateTime); @@ -825,7 +809,7 @@ public static function providerToNativeDateTime(): array ]; } - /** @dataProvider providerToString */ + #[DataProvider('providerToString')] public function testJsonSerialize(string $localDateTime, string $timeZone, string $expectedString): void { $localDateTime = LocalDateTime::parse($localDateTime); @@ -834,7 +818,7 @@ public function testJsonSerialize(string $localDateTime, string $timeZone, strin self::assertSame(json_encode($expectedString, JSON_THROW_ON_ERROR), json_encode($zonedDateTime, JSON_THROW_ON_ERROR)); } - /** @dataProvider providerToString */ + #[DataProvider('providerToString')] public function testToISOString(string $localDateTime, string $timeZone, string $expectedString): void { $localDateTime = LocalDateTime::parse($localDateTime); @@ -843,7 +827,7 @@ public function testToISOString(string $localDateTime, string $timeZone, string self::assertSame($expectedString, $zonedDateTime->toISOString()); } - /** @dataProvider providerToString */ + #[DataProvider('providerToString')] public function testToString(string $localDateTime, string $timeZone, string $expectedString): void { $localDateTime = LocalDateTime::parse($localDateTime); @@ -860,9 +844,7 @@ public static function providerToString(): array ]; } - /** - * @dataProvider providerGetDurationTo - */ + #[DataProvider('providerGetDurationTo')] public function testGetDurationTo(string $firstDate, string $secondDate, int $expectedSeconds, int $expectedNanos): void { $actualResult = ZonedDateTime::parse($firstDate)->getDurationTo(ZonedDateTime::parse($secondDate)); @@ -883,9 +865,7 @@ public static function providerGetDurationTo(): array ]; } - /** - * @dataProvider providerGetIntervalTo - */ + #[DataProvider('providerGetIntervalTo')] public function testGetIntervalTo(string $firstDate, string $secondDate, string $expectedInterval): void { $actualResult = ZonedDateTime::parse($firstDate)->getIntervalTo(ZonedDateTime::parse($secondDate)); diff --git a/tools/rector/rector.php b/tools/rector/rector.php index 57026586..e922e4d8 100644 --- a/tools/rector/rector.php +++ b/tools/rector/rector.php @@ -4,6 +4,7 @@ use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector; use Rector\Config\RectorConfig; +use Rector\PHPUnit\Set\PHPUnitSetList; $root = dirname(__DIR__, 2); @@ -21,4 +22,7 @@ SimplifyUselessVariableRector::class, ]) ->withPhpSets() + ->withSets([ + PHPUnitSetList::PHPUNIT_100, + ]) ->withImportNames(importNames: false, removeUnusedImports: true);