Skip to content

Commit

Permalink
PHPUnit 10 attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Mar 26, 2024
1 parent dbc3696 commit c1de207
Show file tree
Hide file tree
Showing 25 changed files with 405 additions and 859 deletions.
4 changes: 2 additions & 2 deletions tests/Clock/OffsetClockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
use Brick\DateTime\Duration;
use Brick\DateTime\Instant;
use Brick\DateTime\Tests\AbstractTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Unit tests for class OffsetClock.
*/
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));
Expand Down
4 changes: 2 additions & 2 deletions tests/Clock/ScaleClockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
use Brick\DateTime\Duration;
use Brick\DateTime\Instant;
use Brick\DateTime\Tests\AbstractTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Unit tests for class ScaleClock.
*/
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);
Expand Down
31 changes: 10 additions & 21 deletions tests/DayOfWeekTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Brick\DateTime\Instant;
use Brick\DateTime\TimeZone;
use Generator;
use PHPUnit\Framework\Attributes\DataProvider;

use function json_encode;

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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));
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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));
Expand All @@ -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());
Expand Down
Loading

0 comments on commit c1de207

Please sign in to comment.