diff --git a/composer.json b/composer.json index a3361b92..95feefcf 100644 --- a/composer.json +++ b/composer.json @@ -62,6 +62,9 @@ "stan": "@phpstan", "stan-baseline": "tools/phpstan --generate-baseline", "stan-setup": "phive install", + "rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"~2.3.1\" && mv composer.backup composer.json", + "rector-check": "vendor/bin/rector process --dry-run", + "rector-fix": "vendor/bin/rector process", "test": "phpunit" } } diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..601800a9 --- /dev/null +++ b/rector.php @@ -0,0 +1,70 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + + ->withCache( + cacheClass: FileCacheStorage::class, + cacheDirectory: $cacheDir, + ) + + ->withPhpSets() + ->withAttributesSets() + + ->withSets([ + SetList::CODE_QUALITY, + SetList::CODING_STYLE, + SetList::DEAD_CODE, + SetList::EARLY_RETURN, + SetList::INSTANCEOF, + SetList::TYPE_DECLARATION, + ]) + + ->withSkip([ + ClassPropertyAssignToConstructorPromotionRector::class, + CatchExceptionNameMatchingTypeRector::class, + ClosureToArrowFunctionRector::class, + RemoveUselessReturnTagRector::class, + ReturnTypeFromStrictFluentReturnRector::class, + NewlineAfterStatementRector::class, + StringClassNameToClassConstantRector::class, + ReturnTypeFromStrictTypedCallRector::class, + ParamTypeByMethodCallTypeRector::class, + AddFunctionVoidReturnTypeWhereNoReturnRector::class, +// StringableForToStringRector::class, +// CompactToVariablesRector::class, +// SplitDoubleAssignRector::class, +// ChangeOrIfContinueToMultiContinueRector::class, +// ExplicitBoolCompareRector::class, +// NewlineBeforeNewAssignSetRector::class, +// SimplifyEmptyCheckOnEmptyArrayRector::class, +// DisallowedEmptyRuleFixerRector::class, + ]); diff --git a/src/Chronos.php b/src/Chronos.php index eb1a4894..d1e7d2da 100644 --- a/src/Chronos.php +++ b/src/Chronos.php @@ -155,29 +155,21 @@ class Chronos extends DateTimeImmutable implements Stringable * * There is a single test now for all date/time classes provided by Chronos. * This aims to emulate stubbing out 'now' which is a single global fact. - * - * @var \Cake\Chronos\Chronos|null */ protected static ?Chronos $testNow = null; /** * Format to use for __toString method when type juggling occurs. - * - * @var string */ protected static string $toStringFormat = self::DEFAULT_TO_STRING_FORMAT; /** * Days of weekend - * - * @var array */ protected static array $weekendDays = [Chronos::SATURDAY, Chronos::SUNDAY]; /** * Names of days of the week. - * - * @var array */ protected static array $days = [ Chronos::MONDAY => 'Monday', @@ -191,37 +183,27 @@ class Chronos extends DateTimeImmutable implements Stringable /** * First day of week - * - * @var int */ protected static int $weekStartsAt = Chronos::MONDAY; /** * Last day of week - * - * @var int */ protected static int $weekEndsAt = Chronos::SUNDAY; /** * Instance of the diff formatting object. - * - * @var \Cake\Chronos\DifferenceFormatterInterface|null */ protected static ?DifferenceFormatterInterface $diffFormatter = null; /** * Regex for relative period. - * - * @var string */ // phpcs:disable Generic.Files.LineLength.TooLong protected static string $relativePattern = '/this|next|last|tomorrow|yesterday|midnight|today|[+-]|first|last|ago/i'; /** * Errors from last time createFromFormat() was called. - * - * @var array|false */ protected static array|false $lastErrors = false; @@ -239,7 +221,7 @@ public function __construct( DateTimeZone|string|null $timezone = null, ) { if (is_int($time) || (is_string($time) && ctype_digit($time))) { - parent::__construct("@{$time}"); + parent::__construct('@' . $time); return; } @@ -256,7 +238,7 @@ public function __construct( } $testNow = static::getTestNow(); - if ($testNow === null) { + if (!$testNow instanceof Chronos) { parent::__construct($time ?? 'now', $timezone); return; @@ -324,7 +306,7 @@ public static function getTestNow(): ?Chronos */ public static function hasTestNow(): bool { - return static::$testNow !== null; + return static::$testNow instanceof Chronos; } /** @@ -368,11 +350,7 @@ public static function withTestNow(Chronos|string|null $testNow, callable $callb private static function isTimeExpression(?string $time): bool { // Just a time - if (is_string($time) && preg_match('/^[0-2]?[0-9]:[0-5][0-9](?::[0-5][0-9](?:\.[0-9]{1,6})?)?$/', $time)) { - return true; - } - - return false; + return is_string($time) && preg_match('/^[0-2]?\d:[0-5]\d(?::[0-5]\d(?:\.\d{1,6})?)?$/', $time); } /** @@ -388,7 +366,7 @@ public static function hasRelativeKeywords(?string $time): bool return true; } // skip common format with a '-' in it - if ($time && preg_match('/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}/', $time) !== 1) { + if ($time && preg_match('/\d{4}-\d{1,2}-\d{1,2}/', $time) !== 1) { return preg_match(static::$relativePattern, $time) > 0; } @@ -466,8 +444,8 @@ public static function setWeekEndsAt(int $day): void */ public static function diffFormatter(?DifferenceFormatterInterface $formatter = null): DifferenceFormatterInterface { - if ($formatter === null) { - if (static::$diffFormatter === null) { + if (!$formatter instanceof DifferenceFormatterInterface) { + if (!static::$diffFormatter instanceof DifferenceFormatterInterface) { static::$diffFormatter = new DifferenceFormatter(); } @@ -603,19 +581,19 @@ public static function create( DateTimeZone|string|null $timezone = null, ): static { $now = static::now(); - $year = $year ?? (int)$now->format('Y'); - $month = $month ?? $now->format('m'); - $day = $day ?? $now->format('d'); + $year ??= (int)$now->format('Y'); + $month ??= $now->format('m'); + $day ??= $now->format('d'); if ($hour === null) { $hour = $now->format('H'); - $minute = $minute ?? $now->format('i'); - $second = $second ?? $now->format('s'); - $microsecond = $microsecond ?? $now->format('u'); + $minute ??= $now->format('i'); + $second ??= $now->format('s'); + $microsecond ??= $now->format('u'); } else { - $minute = $minute ?? 0; - $second = $second ?? 0; - $microsecond = $microsecond ?? 0; + $minute ??= 0; + $second ??= 0; + $microsecond ??= 0; } $instance = static::createFromFormat( @@ -906,7 +884,7 @@ protected static function rolloverTime(?int &$value, int $max): ?int } $rollover = intdiv($value, $max); - $value = $value % $max; + $value %= $max; return $rollover; } @@ -1363,7 +1341,7 @@ public function subMonthsWithOverflow(int $value): static */ public function addDays(int $value): static { - return $this->modify("$value days"); + return $this->modify($value . ' days'); } /** @@ -1409,7 +1387,7 @@ public function subWeekdays(int $value): static */ public function addWeeks(int $value): static { - return $this->modify("$value week"); + return $this->modify($value . ' week'); } /** @@ -1432,7 +1410,7 @@ public function subWeeks(int $value): static */ public function addHours(int $value): static { - return $this->modify("$value hour"); + return $this->modify($value . ' hour'); } /** @@ -1455,7 +1433,7 @@ public function subHours(int $value): static */ public function addMinutes(int $value): static { - return $this->modify("$value minute"); + return $this->modify($value . ' minute'); } /** @@ -1478,7 +1456,7 @@ public function subMinutes(int $value): static */ public function addSeconds(int $value): static { - return $this->modify("$value second"); + return $this->modify($value . ' second'); } /** @@ -1567,7 +1545,7 @@ public function startOfDecade(): static { $year = $this->year - $this->year % Chronos::YEARS_PER_DECADE; - return $this->modify("first day of january $year, midnight"); + return $this->modify(sprintf('first day of january %d, midnight', $year)); } /** @@ -1579,7 +1557,7 @@ public function endOfDecade(): static { $year = $this->year - $this->year % Chronos::YEARS_PER_DECADE + Chronos::YEARS_PER_DECADE - 1; - return $this->modify("last day of december $year, 23:59:59"); + return $this->modify(sprintf('last day of december %d, 23:59:59', $year)); } /** @@ -1593,7 +1571,7 @@ public function startOfCentury(): static ->year($this->year - 1 - ($this->year - 1) % Chronos::YEARS_PER_CENTURY + 1) ->year; - return $this->modify("first day of january $year, midnight"); + return $this->modify(sprintf('first day of january %d, midnight', $year)); } /** @@ -1612,7 +1590,7 @@ public function endOfCentury(): static ->year($y) ->year; - return $this->modify("last day of december $year, 23:59:59"); + return $this->modify(sprintf('last day of december %d, 23:59:59', $year)); } /** @@ -1663,7 +1641,7 @@ public function next(?int $dayOfWeek = null): static $day = static::$days[$dayOfWeek]; - return $this->modify("next $day, midnight"); + return $this->modify(sprintf('next %s, midnight', $day)); } /** @@ -1684,7 +1662,7 @@ public function previous(?int $dayOfWeek = null): static $day = static::$days[$dayOfWeek]; - return $this->modify("last $day, midnight"); + return $this->modify(sprintf('last %s, midnight', $day)); } /** @@ -1784,7 +1762,7 @@ public function firstOfMonth(?int $dayOfWeek = null): static { $day = $dayOfWeek === null ? 'day' : static::$days[$dayOfWeek]; - return $this->modify("first $day of this month, midnight"); + return $this->modify(sprintf('first %s of this month, midnight', $day)); } /** @@ -1801,7 +1779,7 @@ public function lastOfMonth(?int $dayOfWeek = null): static { $day = $dayOfWeek === null ? 'day' : static::$days[$dayOfWeek]; - return $this->modify("last $day of this month, midnight"); + return $this->modify(sprintf('last %s of this month, midnight', $day)); } /** @@ -1826,7 +1804,7 @@ public function nthOfMonth(int $nth, int $dayOfWeek): static|false { $dateTime = $this->firstOfMonth(); $check = $dateTime->format('Y-m'); - $dateTime = $dateTime->modify("+$nth " . static::$days[$dayOfWeek]); + $dateTime = $dateTime->modify(sprintf('+%d ', $nth) . static::$days[$dayOfWeek]); return $dateTime->format('Y-m') === $check ? $dateTime : false; } @@ -1888,7 +1866,7 @@ public function nthOfQuarter(int $nth, int $dayOfWeek): static|false $dateTime = $this->day(1)->month($this->quarter * Chronos::MONTHS_PER_QUARTER); $lastMonth = $dateTime->month; $year = $dateTime->year; - $dateTime = $dateTime->firstOfQuarter()->modify("+$nth" . static::$days[$dayOfWeek]); + $dateTime = $dateTime->firstOfQuarter()->modify('+' . $nth . static::$days[$dayOfWeek]); return $lastMonth < $dateTime->month || $year !== $dateTime->year ? false : $dateTime; } @@ -1907,7 +1885,7 @@ public function firstOfYear(?int $dayOfWeek = null): static { $day = $dayOfWeek === null ? 'day' : static::$days[$dayOfWeek]; - return $this->modify("first $day of january, midnight"); + return $this->modify(sprintf('first %s of january, midnight', $day)); } /** @@ -1924,7 +1902,7 @@ public function lastOfYear(?int $dayOfWeek = null): static { $day = $dayOfWeek === null ? 'day' : static::$days[$dayOfWeek]; - return $this->modify("last $day of december, midnight"); + return $this->modify(sprintf('last %s of december, midnight', $day)); } /** @@ -1946,7 +1924,7 @@ public function lastOfYear(?int $dayOfWeek = null): static */ public function nthOfYear(int $nth, int $dayOfWeek): static|false { - $dateTime = $this->firstOfYear()->modify("+$nth " . static::$days[$dayOfWeek]); + $dateTime = $this->firstOfYear()->modify(sprintf('+%d ', $nth) . static::$days[$dayOfWeek]); return $this->year === $dateTime->year ? $dateTime : false; } @@ -2103,7 +2081,7 @@ public function farthest(DateTimeInterface $first, DateTimeInterface $second, Da */ public function min(?DateTimeInterface $other = null): static { - $other = $other ?? static::now($this->tz); + $other ??= static::now($this->tz); $winner = $this->lessThan($other) ? $this : $other; if ($winner instanceof static) { return $winner; @@ -2123,7 +2101,7 @@ public function min(?DateTimeInterface $other = null): static */ public function max(?DateTimeInterface $other = null): static { - $other = $other ?? static::now($this->tz); + $other ??= static::now($this->tz); $winner = $this->greaterThan($other) ? $this : $other; if ($winner instanceof static) { return $winner; @@ -2676,7 +2654,7 @@ public function diffInHoursFiltered( */ public function diffInWeekdays(?DateTimeInterface $other = null, bool $absolute = true, int $options = 0): int { - return $this->diffInDaysFiltered(function (Chronos $date) { + return $this->diffInDaysFiltered(function (Chronos $date): bool { return $date->isWeekday(); }, $other, $absolute, $options); } @@ -2691,7 +2669,7 @@ public function diffInWeekdays(?DateTimeInterface $other = null, bool $absolute */ public function diffInWeekendDays(?DateTimeInterface $other = null, bool $absolute = true, int $options = 0): int { - return $this->diffInDaysFiltered(function (Chronos $date) { + return $this->diffInDaysFiltered(function (Chronos $date): bool { return $date->isWeekend(); }, $other, $absolute, $options); } @@ -2868,49 +2846,22 @@ public function __get(string $name): string|float|int|bool|DateTimeZone 'timestamp' => 'U', ]; - switch (true) { - case isset($formats[$name]): - return (int)$this->format($formats[$name]); - - case $name === 'dayOfWeekName': - return $this->format('l'); - - case $name === 'weekOfMonth': - return (int)ceil($this->day / Chronos::DAYS_PER_WEEK); - - case $name === 'age': - return $this->diffInYears(); - - case $name === 'quarter': - return (int)ceil($this->month / 3); - - case $name === 'half': - return $this->month <= 6 ? 1 : 2; - - case $name === 'offset': - return $this->getOffset(); - - case $name === 'offsetHours': - return $this->getOffset() / Chronos::SECONDS_PER_MINUTE / Chronos::MINUTES_PER_HOUR; - - case $name === 'dst': - return $this->format('I') === '1'; - - case $name === 'local': - return $this->offset === $this->setTimezone(date_default_timezone_get())->offset; - - case $name === 'utc': - return $this->offset === 0; - - case $name === 'timezone' || $name === 'tz': - return $this->getTimezone(); - - case $name === 'timezoneName' || $name === 'tzName': - return $this->getTimezone()->getName(); - - default: - throw new InvalidArgumentException(sprintf('Unknown getter `%s`', $name)); - } + return match (true) { + isset($formats[$name]) => (int)$this->format($formats[$name]), + $name === 'dayOfWeekName' => $this->format('l'), + $name === 'weekOfMonth' => (int)ceil($this->day / Chronos::DAYS_PER_WEEK), + $name === 'age' => $this->diffInYears(), + $name === 'quarter' => (int)ceil($this->month / 3), + $name === 'half' => $this->month <= 6 ? 1 : 2, + $name === 'offset' => $this->getOffset(), + $name === 'offsetHours' => $this->getOffset() / Chronos::SECONDS_PER_MINUTE / Chronos::MINUTES_PER_HOUR, + $name === 'dst' => $this->format('I') === '1', + $name === 'local' => $this->offset === $this->setTimezone(date_default_timezone_get())->offset, + $name === 'utc' => $this->offset === 0, + $name === 'timezone' || $name === 'tz' => $this->getTimezone(), + $name === 'timezoneName' || $name === 'tzName' => $this->getTimezone()->getName(), + default => throw new InvalidArgumentException(sprintf('Unknown getter `%s`', $name)), + }; } /** @@ -2923,7 +2874,7 @@ public function __isset(string $name): bool { try { $this->__get($name); - } catch (InvalidArgumentException $e) { + } catch (InvalidArgumentException) { return false; } @@ -2937,15 +2888,12 @@ public function __isset(string $name): bool */ public function __debugInfo(): array { - /** @var \DateTimeZone $timezone */ $timezone = $this->getTimezone(); - $properties = [ + return [ 'hasFixedNow' => static::hasTestNow(), 'time' => $this->format('Y-m-d H:i:s.u'), 'timezone' => $timezone->getName(), ]; - - return $properties; } } diff --git a/src/ChronosDate.php b/src/ChronosDate.php index 3745171a..b51d911a 100644 --- a/src/ChronosDate.php +++ b/src/ChronosDate.php @@ -57,15 +57,11 @@ class ChronosDate implements Stringable /** * Format to use for __toString method when type juggling occurs. - * - * @var string */ protected static string $toStringFormat = self::DEFAULT_TO_STRING_FORMAT; /** * Names of days of the week. - * - * @var array */ protected static array $days = [ Chronos::MONDAY => 'Monday', @@ -79,21 +75,14 @@ class ChronosDate implements Stringable /** * Instance of the diff formatting object. - * - * @var \Cake\Chronos\DifferenceFormatterInterface|null */ protected static ?DifferenceFormatterInterface $diffFormatter = null; /** * Errors from last time createFromFormat() was called. - * - * @var array|false */ protected static array|false $lastErrors = false; - /** - * @var \DateTimeImmutable - */ protected DateTimeImmutable $native; /** @@ -137,7 +126,7 @@ protected function createNative( $timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone); $testNow = Chronos::getTestNow(); - if ($testNow === null) { + if (!$testNow instanceof Chronos) { $time = new DateTimeImmutable($time, $timezone); return new DateTimeImmutable($time->format('Y-m-d 00:00:00')); @@ -290,8 +279,8 @@ public static function createFromArray(array $values): static */ public static function diffFormatter(?DifferenceFormatterInterface $formatter = null): DifferenceFormatterInterface { - if ($formatter === null) { - if (static::$diffFormatter === null) { + if (!$formatter instanceof DifferenceFormatterInterface) { + if (!static::$diffFormatter instanceof DifferenceFormatterInterface) { static::$diffFormatter = new DifferenceFormatter(); } @@ -624,7 +613,7 @@ public function subMonthsWithOverflow(int $value): static */ public function addDays(int $value): static { - return $this->modify("$value days"); + return $this->modify($value . ' days'); } /** @@ -670,7 +659,7 @@ public function subWeekdays(int $value): static */ public function addWeeks(int $value): static { - return $this->modify("$value week"); + return $this->modify($value . ' week'); } /** @@ -733,7 +722,7 @@ public function startOfDecade(): static { $year = $this->year - $this->year % Chronos::YEARS_PER_DECADE; - return $this->modify("first day of january $year"); + return $this->modify('first day of january ' . $year); } /** @@ -745,7 +734,7 @@ public function endOfDecade(): static { $year = $this->year - $this->year % Chronos::YEARS_PER_DECADE + Chronos::YEARS_PER_DECADE - 1; - return $this->modify("last day of december $year"); + return $this->modify('last day of december ' . $year); } /** @@ -759,7 +748,7 @@ public function startOfCentury(): static ->year($this->year - 1 - ($this->year - 1) % Chronos::YEARS_PER_CENTURY + 1) ->year; - return $this->modify("first day of january $year"); + return $this->modify('first day of january ' . $year); } /** @@ -778,7 +767,7 @@ public function endOfCentury(): static ->year($y) ->year; - return $this->modify("last day of december $year"); + return $this->modify('last day of december ' . $year); } /** @@ -790,7 +779,7 @@ public function startOfWeek(): static { $dateTime = $this; if ($dateTime->dayOfWeek !== Chronos::getWeekStartsAt()) { - $dateTime = $dateTime->previous(Chronos::getWeekStartsAt()); + return $dateTime->previous(Chronos::getWeekStartsAt()); } return $dateTime; @@ -805,7 +794,7 @@ public function endOfWeek(): static { $dateTime = $this; if ($dateTime->dayOfWeek !== Chronos::getWeekEndsAt()) { - $dateTime = $dateTime->next(Chronos::getWeekEndsAt()); + return $dateTime->next(Chronos::getWeekEndsAt()); } return $dateTime; @@ -829,7 +818,7 @@ public function next(?int $dayOfWeek = null): static $day = static::$days[$dayOfWeek]; - return $this->modify("next $day"); + return $this->modify('next ' . $day); } /** @@ -850,7 +839,7 @@ public function previous(?int $dayOfWeek = null): static $day = static::$days[$dayOfWeek]; - return $this->modify("last $day"); + return $this->modify('last ' . $day); } /** @@ -867,7 +856,7 @@ public function firstOfMonth(?int $dayOfWeek = null): static { $day = $dayOfWeek === null ? 'day' : static::$days[$dayOfWeek]; - return $this->modify("first $day of this month"); + return $this->modify(sprintf('first %s of this month', $day)); } /** @@ -884,7 +873,7 @@ public function lastOfMonth(?int $dayOfWeek = null): static { $day = $dayOfWeek === null ? 'day' : static::$days[$dayOfWeek]; - return $this->modify("last $day of this month"); + return $this->modify(sprintf('last %s of this month', $day)); } /** @@ -909,7 +898,7 @@ public function nthOfMonth(int $nth, int $dayOfWeek): static|false { $dateTime = $this->firstOfMonth(); $check = $dateTime->format('Y-m'); - $dateTime = $dateTime->modify("+$nth " . static::$days[$dayOfWeek]); + $dateTime = $dateTime->modify(sprintf('+%d ', $nth) . static::$days[$dayOfWeek]); return $dateTime->format('Y-m') === $check ? $dateTime : false; } @@ -971,7 +960,7 @@ public function nthOfQuarter(int $nth, int $dayOfWeek): static|false $dateTime = $this->day(1)->month($this->quarter * Chronos::MONTHS_PER_QUARTER); $lastMonth = $dateTime->month; $year = $dateTime->year; - $dateTime = $dateTime->firstOfQuarter()->modify("+$nth" . static::$days[$dayOfWeek]); + $dateTime = $dateTime->firstOfQuarter()->modify('+' . $nth . static::$days[$dayOfWeek]); return $lastMonth < $dateTime->month || $year !== $dateTime->year ? false : $dateTime; } @@ -990,7 +979,7 @@ public function firstOfYear(?int $dayOfWeek = null): static { $day = $dayOfWeek === null ? 'day' : static::$days[$dayOfWeek]; - return $this->modify("first $day of january"); + return $this->modify(sprintf('first %s of january', $day)); } /** @@ -1007,7 +996,7 @@ public function lastOfYear(?int $dayOfWeek = null): static { $day = $dayOfWeek === null ? 'day' : static::$days[$dayOfWeek]; - return $this->modify("last $day of december"); + return $this->modify(sprintf('last %s of december', $day)); } /** @@ -1029,7 +1018,7 @@ public function lastOfYear(?int $dayOfWeek = null): static */ public function nthOfYear(int $nth, int $dayOfWeek): static|false { - $dateTime = $this->firstOfYear()->modify("+$nth " . static::$days[$dayOfWeek]); + $dateTime = $this->firstOfYear()->modify(sprintf('+%d ', $nth) . static::$days[$dayOfWeek]); return $this->year === $dateTime->year ? $dateTime : false; } @@ -1580,7 +1569,7 @@ public function diffInDaysFiltered( */ public function diffInWeekdays(?ChronosDate $other = null, bool $absolute = true, int $options = 0): int { - return $this->diffInDaysFiltered(function (ChronosDate $date) { + return $this->diffInDaysFiltered(function (ChronosDate $date): bool { return $date->isWeekday(); }, $other, $absolute, $options); } @@ -1595,7 +1584,7 @@ public function diffInWeekdays(?ChronosDate $other = null, bool $absolute = true */ public function diffInWeekendDays(?ChronosDate $other = null, bool $absolute = true, int $options = 0): int { - return $this->diffInDaysFiltered(function (ChronosDate $date) { + return $this->diffInDaysFiltered(function (ChronosDate $date): bool { return $date->isWeekend(); }, $other, $absolute, $options); } @@ -1688,28 +1677,15 @@ public function __get(string $name): string|float|int|bool 'daysInMonth' => 't', ]; - switch (true) { - case isset($formats[$name]): - return (int)$this->format($formats[$name]); - - case $name === 'dayOfWeekName': - return $this->format('l'); - - case $name === 'weekOfMonth': - return (int)ceil($this->day / Chronos::DAYS_PER_WEEK); - - case $name === 'age': - return $this->diffInYears(); - - case $name === 'quarter': - return (int)ceil($this->month / 3); - - case $name === 'half': - return $this->month <= 6 ? 1 : 2; - - default: - throw new InvalidArgumentException(sprintf('Unknown getter `%s`', $name)); - } + return match (true) { + isset($formats[$name]) => (int)$this->format($formats[$name]), + $name === 'dayOfWeekName' => $this->format('l'), + $name === 'weekOfMonth' => (int)ceil($this->day / Chronos::DAYS_PER_WEEK), + $name === 'age' => $this->diffInYears(), + $name === 'quarter' => (int)ceil($this->month / 3), + $name === 'half' => $this->month <= 6 ? 1 : 2, + default => throw new InvalidArgumentException(sprintf('Unknown getter `%s`', $name)), + }; } /** @@ -1722,7 +1698,7 @@ public function __isset(string $name): bool { try { $this->__get($name); - } catch (InvalidArgumentException $e) { + } catch (InvalidArgumentException) { return false; } @@ -1736,11 +1712,9 @@ public function __isset(string $name): bool */ public function __debugInfo(): array { - $properties = [ + return [ 'hasFixedNow' => Chronos::hasTestNow(), 'date' => $this->format('Y-m-d'), ]; - - return $properties; } } diff --git a/src/ChronosInterval.php b/src/ChronosInterval.php index d212c1b3..3a7bee3d 100644 --- a/src/ChronosInterval.php +++ b/src/ChronosInterval.php @@ -38,8 +38,6 @@ class ChronosInterval implements Stringable { /** * The wrapped DateInterval instance. - * - * @var \DateInterval */ protected DateInterval $interval; @@ -127,7 +125,7 @@ public static function createFromDateString(string $datetime): static { $interval = DateInterval::createFromDateString($datetime); if ($interval === false) { - throw new InvalidArgumentException("Unable to parse interval string: {$datetime}"); + throw new InvalidArgumentException('Unable to parse interval string: ' . $datetime); } return new static($interval); diff --git a/src/ChronosTime.php b/src/ChronosTime.php index 5413c429..f0669786 100644 --- a/src/ChronosTime.php +++ b/src/ChronosTime.php @@ -59,14 +59,9 @@ class ChronosTime implements Stringable /** * Format to use for __toString method. - * - * @var string */ protected static string $toStringFormat = self::DEFAULT_TO_STRING_FORMAT; - /** - * @var int - */ protected int $ticks; /** diff --git a/src/ClockFactory.php b/src/ClockFactory.php index 402eb580..9c4c148e 100644 --- a/src/ClockFactory.php +++ b/src/ClockFactory.php @@ -33,7 +33,7 @@ */ class ClockFactory implements ClockInterface { - private DateTimeZone|string|null $timezone; + private readonly DateTimeZone|string|null $timezone; /** * Constructor. diff --git a/src/DifferenceFormatter.php b/src/DifferenceFormatter.php index 3a568c79..211dcf5a 100644 --- a/src/DifferenceFormatter.php +++ b/src/DifferenceFormatter.php @@ -28,8 +28,6 @@ class DifferenceFormatter implements DifferenceFormatterInterface { /** * The text translator object - * - * @var \Cake\Chronos\Translator */ protected Translator $translate; diff --git a/src/Translator.php b/src/Translator.php index 37568ae2..e15aca53 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -22,8 +22,6 @@ class Translator { /** * Translation strings. - * - * @var array */ public static array $strings = [ 'year' => '1 year', diff --git a/tests/Benchmark/ConstructBench.php b/tests/Benchmark/ConstructBench.php index faaddfe3..84c71e79 100644 --- a/tests/Benchmark/ConstructBench.php +++ b/tests/Benchmark/ConstructBench.php @@ -15,6 +15,7 @@ use Cake\Chronos\Chronos; use Cake\Chronos\ChronosDate; +use Generator; /** * @BeforeMethods({"init"}) @@ -22,20 +23,20 @@ */ class ConstructBench { - private $savedTz; + private ?string $savedTz = null; - public function init() + public function init(): void { $this->savedTz = date_default_timezone_get(); date_default_timezone_set('America/Toronto'); } - public function shutdown() + public function shutdown(): void { date_default_timezone_set($this->savedTz); } - public function provideClasses() + public function provideClasses(): Generator { yield 'chronos' => ['class' => Chronos::class]; yield 'date' => ['class' => ChronosDate::class]; @@ -46,7 +47,7 @@ public function provideClasses() * @Iterations(5) * @ParamProviders({"provideClasses"}) */ - public function benchNow($params) + public function benchNow(array $params): void { $class = $params['class']; $class::now(); @@ -57,7 +58,7 @@ public function benchNow($params) * @Iterations(5) * @ParamProviders({"provideClasses"}) */ - public function benchNowTimezone($params) + public function benchNowTimezone(array $params): void { $class = $params['class']; $class::now('Europe/London'); @@ -68,7 +69,7 @@ public function benchNowTimezone($params) * @Iterations(5) * @ParamProviders({"provideClasses"}) */ - public function benchRelative($params) + public function benchRelative(array $params): void { $class = $params['class']; $class::parse('+2 days'); @@ -79,7 +80,7 @@ public function benchRelative($params) * @Iterations(5) * @ParamProviders({"provideClasses"}) */ - public function benchRelativeTimezone($params) + public function benchRelativeTimezone(array $params): void { $class = $params['class']; $class::parse('+2 days', 'Europe/London'); @@ -90,7 +91,7 @@ public function benchRelativeTimezone($params) * @Iterations(5) * @ParamProviders({"provideClasses"}) */ - public function benchFixed($params) + public function benchFixed(array $params): void { $class = $params['class']; $class::parse('2001-01-01 01:02:03.123456'); @@ -101,7 +102,7 @@ public function benchFixed($params) * @Iterations(5) * @ParamProviders({"provideClasses"}) */ - public function benchFixedTimezone($params) + public function benchFixedTimezone(array $params): void { $class = $params['class']; $class::parse('2001-01-01 01:02:03.123456', 'Europe/London'); @@ -112,7 +113,7 @@ public function benchFixedTimezone($params) * @Iterations(5) * @ParamProviders({"provideClasses"}) */ - public function benchCreate($params) + public function benchCreate(array $params): void { $class = $params['class']; $class::create(2001, 01, 01, 01, 02, 03); @@ -123,7 +124,7 @@ public function benchCreate($params) * @Iterations(5) * @ParamProviders({"provideClasses"}) */ - public function benchCreateTimezone($params) + public function benchCreateTimezone(array $params): void { $class = $params['class']; $class::create(2001, 01, 01, 01, 02, 03, 'Europe/London'); @@ -134,7 +135,7 @@ public function benchCreateTimezone($params) * @Iterations(5) * @ParamProviders({"provideClasses"}) */ - public function benchFromFormat($params) + public function benchFromFormat(array $params): void { $class = $params['class']; $class::createFromFormat('Y-m-d H:i:s.u', '2001-01-01 01:02:03.123456'); @@ -145,7 +146,7 @@ public function benchFromFormat($params) * @Iterations(5) * @ParamProviders({"provideClasses"}) */ - public function benchFromFormatTimezone($params) + public function benchFromFormatTimezone(array $params): void { $class = $params['class']; $class::createFromFormat('Y-m-d H:i:s.u', '2001-01-01 01:02:03.123456', 'Europe/London'); @@ -156,7 +157,7 @@ public function benchFromFormatTimezone($params) * @Iterations(5) * @ParamProviders({"provideClasses"}) */ - public function benchFromTimestamp($params) + public function benchFromTimestamp(array $params): void { $class = $params['class']; $class::createFromTimestamp(1454284800); @@ -167,7 +168,7 @@ public function benchFromTimestamp($params) * @Iterations(5) * @ParamProviders({"provideClasses"}) */ - public function benchFromTimestampUTC($params) + public function benchFromTimestampUTC(array $params): void { $class = $params['class']; $class::createFromTimestamp(1454284800); diff --git a/tests/Benchmark/DiffBench.php b/tests/Benchmark/DiffBench.php index c693ac48..40a9a5a7 100644 --- a/tests/Benchmark/DiffBench.php +++ b/tests/Benchmark/DiffBench.php @@ -21,7 +21,11 @@ */ class DiffBench { - public function init() + public $from; + + public $to; + + public function init(): void { $this->from = new Chronos('2019-01-01 00:00:00'); $this->to = new Chronos('2020-01-01 00:00:00'); @@ -35,7 +39,7 @@ public function shutdown() * @Revs(1000) * @Iterations(5) */ - public function benchDiffYears() + public function benchDiffYears(): void { $this->from->diffInYears($this->to); } @@ -44,7 +48,7 @@ public function benchDiffYears() * @Revs(1000) * @Iterations(5) */ - public function benchDiffMonths() + public function benchDiffMonths(): void { $this->from->diffInMonths($this->to); } @@ -53,7 +57,7 @@ public function benchDiffMonths() * @Revs(1000) * @Iterations(5) */ - public function benchDiffDays() + public function benchDiffDays(): void { $this->from->diffInDays($this->to); } diff --git a/tests/TestCase/ChronosTimeTest.php b/tests/TestCase/ChronosTimeTest.php index fa5dd945..1be8a370 100644 --- a/tests/TestCase/ChronosTimeTest.php +++ b/tests/TestCase/ChronosTimeTest.php @@ -28,7 +28,7 @@ public function testConstructNow(): void $t = new ChronosTime(); $this->assertSame('12:13:14.123456', $t->format('H:i:s.u')); - $t = new ChronosTime(null); + $t = new ChronosTime(); $this->assertSame('12:13:14.123456', $t->format('H:i:s.u')); } diff --git a/tests/TestCase/Date/AddTest.php b/tests/TestCase/Date/AddTest.php index ddf591ce..ba831b5c 100644 --- a/tests/TestCase/Date/AddTest.php +++ b/tests/TestCase/Date/AddTest.php @@ -21,7 +21,7 @@ class AddTest extends TestCase { - public function testAddFullDay() + public function testAddFullDay(): void { $interval = DateInterval::createFromDateString('1 day'); $date = ChronosDate::create(2001, 1, 1); @@ -29,7 +29,7 @@ public function testAddFullDay() $this->assertSame('2001-01-02', $new->toDateString()); } - public function testAddRaiseErrorOnTime() + public function testAddRaiseErrorOnTime(): void { $interval = DateInterval::createFromDateString('1 hour, 1 minute, 3 seconds'); $date = ChronosDate::create(2001, 1, 1); @@ -37,7 +37,7 @@ public function testAddRaiseErrorOnTime() $date->add($interval); } - public function testSubFullDay() + public function testSubFullDay(): void { $interval = DateInterval::createFromDateString('1 day'); $date = ChronosDate::create(2001, 1, 1); @@ -45,7 +45,7 @@ public function testSubFullDay() $this->assertSame('2000-12-31', $new->toDateString()); } - public function testSubIgnoreTime() + public function testSubIgnoreTime(): void { $interval = DateInterval::createFromDateString('1 hour, 1 minute, 3 seconds'); $date = ChronosDate::create(2001, 1, 1); @@ -53,38 +53,38 @@ public function testSubIgnoreTime() $date->sub($interval); } - public function testAddDay() + public function testAddDay(): void { $this->assertSame(1, ChronosDate::create(1975, 5, 31)->addDays(1)->day); $this->assertSame(30, ChronosDate::create(1975, 5, 31)->addDays(-1)->day); } - public function testAddMonth() + public function testAddMonth(): void { $this->assertSame(6, ChronosDate::create(1975, 5, 31)->addMonths(1)->month); $this->assertSame(4, ChronosDate::create(1975, 5, 31)->addMonths(-1)->month); } - public function testAddYears() + public function testAddYears(): void { $this->assertSame(1976, ChronosDate::create(1975, 5, 31)->addYears(1)->year); $this->assertSame(1974, ChronosDate::create(1975, 5, 31)->addYears(-1)->year); } - public function testAddWeekdays() + public function testAddWeekdays(): void { $this->assertSame(2, ChronosDate::create(1975, 5, 31)->addWeekdays(1)->day); $this->assertSame(30, ChronosDate::create(1975, 5, 31)->addWeekdays(-1)->day); } - public function testModify() + public function testModify(): void { $date = ChronosDate::create(2001, 1, 1); $new = $date->modify('2 days'); $this->assertSame('2001-01-03', $new->toDateString()); } - public function testModifyTimeComponentError() + public function testModifyTimeComponentError(): void { $date = ChronosDate::create(2001, 1, 1); $this->expectException(InvalidArgumentException::class); diff --git a/tests/TestCase/Date/ComparisonTest.php b/tests/TestCase/Date/ComparisonTest.php index 4586b745..10037a1b 100644 --- a/tests/TestCase/Date/ComparisonTest.php +++ b/tests/TestCase/Date/ComparisonTest.php @@ -20,77 +20,77 @@ class ComparisonTest extends TestCase { - public function testEqualToTrue() + public function testEqualToTrue(): void { $this->assertTrue(ChronosDate::create(2000, 1, 1)->equals(ChronosDate::create(2000, 1, 1))); } - public function testEqualToFalse() + public function testEqualToFalse(): void { $this->assertFalse(ChronosDate::create(2000, 1, 1)->equals(ChronosDate::create(2000, 1, 2))); } - public function testNotEqualToTrue() + public function testNotEqualToTrue(): void { $this->assertTrue(ChronosDate::create(2000, 1, 1)->notEquals(ChronosDate::create(2000, 1, 2))); } - public function testNotEqualToFalse() + public function testNotEqualToFalse(): void { $this->assertFalse(ChronosDate::create(2000, 1, 1)->notEquals(ChronosDate::create(2000, 1, 1))); } - public function testGreaterThanTrue() + public function testGreaterThanTrue(): void { $this->assertTrue(ChronosDate::create(2000, 1, 1)->greaterThan(ChronosDate::create(1999, 12, 31))); } - public function testGreaterThanFalse() + public function testGreaterThanFalse(): void { $this->assertFalse(ChronosDate::create(2000, 1, 1)->greaterThan(ChronosDate::create(2000, 1, 2))); } - public function testGreaterThanOrEqualTrue() + public function testGreaterThanOrEqualTrue(): void { $this->assertTrue(ChronosDate::create(2000, 1, 1)->greaterThanOrEquals(ChronosDate::create(1999, 12, 31))); } - public function testGreaterThanOrEqualTrueEqual() + public function testGreaterThanOrEqualTrueEqual(): void { - $this->assertTrue(ChronosDate::create(2000, 1, 1, 0, 0, 0)->greaterThanOrEquals(ChronosDate::create(2000, 1, 1, 0, 0, 0))); + $this->assertTrue(ChronosDate::create(2000, 1, 1)->greaterThanOrEquals(ChronosDate::create(2000, 1, 1))); } - public function testGreaterThanOrEqualFalse() + public function testGreaterThanOrEqualFalse(): void { $this->assertFalse(ChronosDate::create(2000, 1, 1)->greaterThanOrEquals(ChronosDate::create(2000, 1, 2))); } - public function testLessThanTrue() + public function testLessThanTrue(): void { $this->assertTrue(ChronosDate::create(2000, 1, 1)->lessThan(ChronosDate::create(2000, 1, 2))); } - public function testLessThanFalse() + public function testLessThanFalse(): void { $this->assertFalse(ChronosDate::create(2000, 1, 1)->lessThanOrEquals(ChronosDate::create(1999, 12, 31))); } - public function testLessThanOrEqualTrue() + public function testLessThanOrEqualTrue(): void { $this->assertTrue(ChronosDate::create(2000, 1, 1)->lessThanOrEquals(ChronosDate::create(2000, 1, 2))); } - public function testLessThanOrEqualTrueEqual() + public function testLessThanOrEqualTrueEqual(): void { $this->assertTrue(ChronosDate::create(2000, 1, 1)->lessThanOrEquals(ChronosDate::create(2000, 1, 1))); } - public function testLessThanOrEqualFalse() + public function testLessThanOrEqualFalse(): void { $this->assertFalse(ChronosDate::create(2000, 1, 1)->lessThanOrEquals(ChronosDate::create(1999, 12, 31))); } - public function testBetweenEqualTrue() + public function testBetweenEqualTrue(): void { $this->assertTrue(ChronosDate::create(2000, 1, 15)->between( ChronosDate::create(2000, 1, 1), @@ -99,7 +99,7 @@ public function testBetweenEqualTrue() )); } - public function testBetweenNotEqualTrue() + public function testBetweenNotEqualTrue(): void { $this->assertTrue(ChronosDate::create(2000, 1, 15)->between( ChronosDate::create(2000, 1, 1), @@ -108,7 +108,7 @@ public function testBetweenNotEqualTrue() )); } - public function testBetweenEqualFalse() + public function testBetweenEqualFalse(): void { $this->assertFalse(ChronosDate::create(1999, 12, 31)->between( ChronosDate::create(2000, 1, 1), @@ -117,7 +117,7 @@ public function testBetweenEqualFalse() )); } - public function testBetweenNotEqualFalse() + public function testBetweenNotEqualFalse(): void { $this->assertFalse(ChronosDate::create(2000, 1, 1)->between( ChronosDate::create(2000, 1, 1), @@ -126,7 +126,7 @@ public function testBetweenNotEqualFalse() )); } - public function testBetweenEqualSwitchTrue() + public function testBetweenEqualSwitchTrue(): void { $this->assertTrue(ChronosDate::create(2000, 1, 15)->between( ChronosDate::create(2000, 1, 31), @@ -135,7 +135,7 @@ public function testBetweenEqualSwitchTrue() )); } - public function testBetweenNotEqualSwitchTrue() + public function testBetweenNotEqualSwitchTrue(): void { $this->assertTrue(ChronosDate::create(2000, 1, 15)->between( ChronosDate::create(2000, 1, 31), @@ -144,7 +144,7 @@ public function testBetweenNotEqualSwitchTrue() )); } - public function testBetweenEqualSwitchFalse() + public function testBetweenEqualSwitchFalse(): void { $this->assertFalse(ChronosDate::create(1999, 12, 31)->between( ChronosDate::create(2000, 1, 31), @@ -153,7 +153,7 @@ public function testBetweenEqualSwitchFalse() )); } - public function testBetweenNotEqualSwitchFalse() + public function testBetweenNotEqualSwitchFalse(): void { $this->assertFalse(ChronosDate::create(2000, 1, 1)->between( ChronosDate::create(2000, 1, 31), @@ -162,7 +162,7 @@ public function testBetweenNotEqualSwitchFalse() )); } - public function testClosest() + public function testClosest(): void { $instance = ChronosDate::create(2015, 5, 10); $dt1 = ChronosDate::create(2015, 5, 4); @@ -171,7 +171,7 @@ public function testClosest() $this->assertSame($dt1, $closest); } - public function testClosestWithEquals() + public function testClosestWithEquals(): void { $instance = ChronosDate::create(2015, 5, 10); $dt1 = ChronosDate::create(2015, 5, 10); @@ -191,7 +191,7 @@ public function testClosestWithOthers(): void $this->assertSame($dt1, $closest); } - public function testFarthest() + public function testFarthest(): void { $instance = ChronosDate::create(2015, 5, 10); $dt1 = ChronosDate::create(2015, 5, 4); @@ -200,7 +200,7 @@ public function testFarthest() $this->assertSame($dt2, $Farthest); } - public function testFarthestWithEquals() + public function testFarthestWithEquals(): void { $instance = ChronosDate::create(2015, 5, 10); $dt1 = ChronosDate::create(2015, 5, 10); diff --git a/tests/TestCase/Date/ConstructTest.php b/tests/TestCase/Date/ConstructTest.php index ee090dfa..9f3feab7 100644 --- a/tests/TestCase/Date/ConstructTest.php +++ b/tests/TestCase/Date/ConstructTest.php @@ -27,19 +27,19 @@ */ class ConstructTest extends TestCase { - public function testWithFancyString() + public function testWithFancyString(): void { $c = new ChronosDate('first day of January 2008'); - $this->assertDate($c, 2008, 1, 1, 0, 0, 0); + $this->assertDate($c, 2008, 1, 1); } - public function testParseWithFancyString() + public function testParseWithFancyString(): void { $c = ChronosDate::parse('first day of January 2008'); - $this->assertDate($c, 2008, 1, 1, 0, 0, 0); + $this->assertDate($c, 2008, 1, 1); } - public function testParseWithMicroSeconds() + public function testParseWithMicroSeconds(): void { $date = ChronosDate::parse('2016-12-08 18:06:46.510954'); $this->assertNotNull($date); @@ -50,7 +50,7 @@ public function testParseWithMicroSeconds() * * @return array */ - public static function inputTimeProvider() + public static function inputTimeProvider(): array { return [ ['@' . strtotime('2015-08-19 22:24:32')], @@ -72,13 +72,13 @@ public static function inputTimeProvider() * @return void */ #[DataProvider('inputTimeProvider')] - public function testConstructWithTimeParts($time) + public function testConstructWithTimeParts(string $time): void { $date = new ChronosDate($time); $this->assertNotNull($date); } - public function testConstructWithTestNow() + public function testConstructWithTestNow(): void { Chronos::setTestNow(Chronos::create(2001, 1, 1)); $date = new ChronosDate('+2 days'); @@ -88,7 +88,7 @@ public function testConstructWithTestNow() $this->assertDate($date, 2015, 12, 12); } - public function testConstructWithRelative() + public function testConstructWithRelative(): void { $c = new ChronosDate('+7 days'); $this->assertSame('00:00:00', $c->format('H:i:s')); @@ -173,7 +173,7 @@ public function testConstructWithLargeTimezoneChange(): void $this->assertSame($samoa->format('Y-m-d'), $c->format('Y-m-d')); } - public function testCreateFromExistingInstance() + public function testCreateFromExistingInstance(): void { $existingClass = new ChronosDate(new Chronos()); $this->assertInstanceOf(ChronosDate::class, $existingClass); @@ -184,14 +184,14 @@ public function testCreateFromExistingInstance() $this->assertSame((string)$existingClass, (string)$newClass); } - public function testCreateFromChronos() + public function testCreateFromChronos(): void { $chronos = new Chronos('2021-01-01 01:01:01'); $date = new ChronosDate($chronos); $this->assertSame('2021-01-01 00:00:00', $date->format('Y-m-d H:i:s')); } - public function testCreateFromDateTimeInterface() + public function testCreateFromDateTimeInterface(): void { $existingClass = new DateTimeImmutable(); $newClass = new ChronosDate($existingClass); @@ -204,13 +204,13 @@ public function testCreateFromDateTimeInterface() $this->assertSame($existingClass->format('Y-m-d 00:00:00'), $newClass->format('Y-m-d H:i:s')); } - public function testCreateFromFormat() + public function testCreateFromFormat(): void { $date = ChronosDate::createFromFormat('Y-m-d P', '2014-02-01 Asia/Tokyo'); $this->assertSame('2014-02-01 00:00:00 America/Toronto', $date->format('Y-m-d H:i:s e')); } - public function testCreateFromFormatInvalidFormat() + public function testCreateFromFormatInvalidFormat(): void { $parseException = null; try { diff --git a/tests/TestCase/Date/DayOfWeekModifiersTest.php b/tests/TestCase/Date/DayOfWeekModifiersTest.php index f9481e24..da7cf194 100644 --- a/tests/TestCase/Date/DayOfWeekModifiersTest.php +++ b/tests/TestCase/Date/DayOfWeekModifiersTest.php @@ -21,290 +21,290 @@ class DayOfWeekModifiersTest extends TestCase { - public function testStartOfWeek() + public function testStartOfWeek(): void { - $d = ChronosDate::create(1980, 8, 7, 12, 11, 9)->startOfWeek(); - $this->assertDate($d, 1980, 8, 4, 0, 0, 0); + $d = ChronosDate::create(1980, 8, 7)->startOfWeek(); + $this->assertDate($d, 1980, 8, 4); } - public function testStartOfWeekFromWeekStart() + public function testStartOfWeekFromWeekStart(): void { $d = ChronosDate::create(1980, 8, 4)->startOfWeek(); - $this->assertDate($d, 1980, 8, 4, 0, 0, 0); + $this->assertDate($d, 1980, 8, 4); } - public function testStartOfWeekCrossingYearBoundary() + public function testStartOfWeekCrossingYearBoundary(): void { - $d = ChronosDate::create(2013, 12, 31, 'GMT'); - $this->assertDate($d->startOfWeek(), 2013, 12, 30, 0, 0, 0); + $d = ChronosDate::create(2013, 12, 31); + $this->assertDate($d->startOfWeek(), 2013, 12, 30); } - public function testEndOfWeek() + public function testEndOfWeek(): void { - $d = ChronosDate::create(1980, 8, 7, 11, 12, 13)->endOfWeek(); - $this->assertDate($d, 1980, 8, 10, 23, 59, 59); + $d = ChronosDate::create(1980, 8, 7)->endOfWeek(); + $this->assertDate($d, 1980, 8, 10); } - public function testEndOfWeekFromWeekEnd() + public function testEndOfWeekFromWeekEnd(): void { $d = ChronosDate::create(1980, 8, 9)->endOfWeek(); - $this->assertDate($d, 1980, 8, 10, 23, 59, 59); + $this->assertDate($d, 1980, 8, 10); } - public function testEndOfWeekCrossingYearBoundary() + public function testEndOfWeekCrossingYearBoundary(): void { - $d = ChronosDate::create(2013, 12, 31, 'GMT'); - $this->assertDate($d->endOfWeek(), 2014, 1, 5, 23, 59, 59); + $d = ChronosDate::create(2013, 12, 31); + $this->assertDate($d->endOfWeek(), 2014, 1, 5); } - public function testNext() + public function testNext(): void { $d = ChronosDate::create(1975, 5, 21)->next(); - $this->assertDate($d, 1975, 5, 28, 0, 0, 0); + $this->assertDate($d, 1975, 5, 28); } - public function testStartOrEndOfWeekFromWeekWithUTC() + public function testStartOrEndOfWeekFromWeekWithUTC(): void { - $d = ChronosDate::create(2016, 7, 27, 17, 13, 7, 0, 'UTC'); - $this->assertDate($d->startOfWeek(), 2016, 7, 25, 0, 0, 0); - $this->assertDate($d->endOfWeek(), 2016, 7, 31, 23, 59, 59); - $this->assertDate($d->startOfWeek()->endOfWeek(), 2016, 7, 31, 23, 59, 59); + $d = ChronosDate::create(2016, 7, 27); + $this->assertDate($d->startOfWeek(), 2016, 7, 25); + $this->assertDate($d->endOfWeek(), 2016, 7, 31); + $this->assertDate($d->startOfWeek()->endOfWeek(), 2016, 7, 31); } - public function testStartOrEndOfWeekFromWeekWithOtherTimezone() + public function testStartOrEndOfWeekFromWeekWithOtherTimezone(): void { - $d = ChronosDate::create(2016, 7, 27, 17, 13, 7, 0, 'America/New_York'); - $this->assertDate($d->startOfWeek(), 2016, 7, 25, 0, 0, 0); - $this->assertDate($d->endOfWeek(), 2016, 7, 31, 23, 59, 59); - $this->assertDate($d->startOfWeek()->endOfWeek(), 2016, 7, 31, 23, 59, 59); + $d = ChronosDate::create(2016, 7, 27); + $this->assertDate($d->startOfWeek(), 2016, 7, 25); + $this->assertDate($d->endOfWeek(), 2016, 7, 31); + $this->assertDate($d->startOfWeek()->endOfWeek(), 2016, 7, 31); } - public function testNextMonday() + public function testNextMonday(): void { $d = ChronosDate::create(1975, 5, 21)->next(Chronos::MONDAY); - $this->assertDate($d, 1975, 5, 26, 0, 0, 0); + $this->assertDate($d, 1975, 5, 26); } - public function testNextSaturday() + public function testNextSaturday(): void { $d = ChronosDate::create(1975, 5, 21)->next(6); - $this->assertDate($d, 1975, 5, 24, 0, 0, 0); + $this->assertDate($d, 1975, 5, 24); } - public function testNextTimestamp() + public function testNextTimestamp(): void { $d = ChronosDate::create(1975, 11, 14)->next(); - $this->assertDate($d, 1975, 11, 21, 0, 0, 0); + $this->assertDate($d, 1975, 11, 21); } - public function testPrevious() + public function testPrevious(): void { $d = ChronosDate::create(1975, 5, 21)->previous(); - $this->assertDate($d, 1975, 5, 14, 0, 0, 0); + $this->assertDate($d, 1975, 5, 14); } - public function testPreviousMonday() + public function testPreviousMonday(): void { $d = ChronosDate::create(1975, 5, 21)->previous(Chronos::MONDAY); - $this->assertDate($d, 1975, 5, 19, 0, 0, 0); + $this->assertDate($d, 1975, 5, 19); } - public function testPreviousSaturday() + public function testPreviousSaturday(): void { $d = ChronosDate::create(1975, 5, 21)->previous(6); - $this->assertDate($d, 1975, 5, 17, 0, 0, 0); + $this->assertDate($d, 1975, 5, 17); } - public function testPreviousTimestamp() + public function testPreviousTimestamp(): void { $d = ChronosDate::create(1975, 11, 28)->previous(); - $this->assertDate($d, 1975, 11, 21, 0, 0, 0); + $this->assertDate($d, 1975, 11, 21); } - public function testFirstDayOfMonth() + public function testFirstDayOfMonth(): void { $d = ChronosDate::create(1975, 11, 21)->firstOfMonth(); - $this->assertDate($d, 1975, 11, 1, 0, 0, 0); + $this->assertDate($d, 1975, 11, 1); } - public function testFirstWednesdayOfMonth() + public function testFirstWednesdayOfMonth(): void { $d = ChronosDate::create(1975, 11, 21)->firstOfMonth(Chronos::WEDNESDAY); - $this->assertDate($d, 1975, 11, 5, 0, 0, 0); + $this->assertDate($d, 1975, 11, 5); } - public function testFirstFridayOfMonth() + public function testFirstFridayOfMonth(): void { $d = ChronosDate::create(1975, 11, 21)->firstOfMonth(5); - $this->assertDate($d, 1975, 11, 7, 0, 0, 0); + $this->assertDate($d, 1975, 11, 7); } - public function testLastDayOfMonth() + public function testLastDayOfMonth(): void { $d = ChronosDate::create(1975, 12, 5)->lastOfMonth(); - $this->assertDate($d, 1975, 12, 31, 0, 0, 0); + $this->assertDate($d, 1975, 12, 31); } - public function testLastTuesdayOfMonth() + public function testLastTuesdayOfMonth(): void { $d = ChronosDate::create(1975, 12, 1)->lastOfMonth(Chronos::TUESDAY); - $this->assertDate($d, 1975, 12, 30, 0, 0, 0); + $this->assertDate($d, 1975, 12, 30); } - public function testLastFridayOfMonth() + public function testLastFridayOfMonth(): void { $d = ChronosDate::create(1975, 12, 5)->lastOfMonth(5); - $this->assertDate($d, 1975, 12, 26, 0, 0, 0); + $this->assertDate($d, 1975, 12, 26); } - public function testNthOfMonthOutsideScope() + public function testNthOfMonthOutsideScope(): void { $this->assertFalse(ChronosDate::create(1975, 12, 5)->nthOfMonth(6, Chronos::MONDAY)); } - public function testNthOfMonthOutsideYear() + public function testNthOfMonthOutsideYear(): void { $this->assertFalse(ChronosDate::create(1975, 12, 5)->nthOfMonth(55, Chronos::MONDAY)); } - public function test2ndMondayOfMonth() + public function test2ndMondayOfMonth(): void { $d = ChronosDate::create(1975, 12, 5)->nthOfMonth(2, Chronos::MONDAY); - $this->assertDate($d, 1975, 12, 8, 0, 0, 0); + $this->assertDate($d, 1975, 12, 8); } - public function test3rdWednesdayOfMonth() + public function test3rdWednesdayOfMonth(): void { $d = ChronosDate::create(1975, 12, 5)->nthOfMonth(3, 3); - $this->assertDate($d, 1975, 12, 17, 0, 0, 0); + $this->assertDate($d, 1975, 12, 17); } - public function testFirstDayOfQuarter() + public function testFirstDayOfQuarter(): void { $d = ChronosDate::create(1975, 11, 21)->firstOfQuarter(); - $this->assertDate($d, 1975, 10, 1, 0, 0, 0); + $this->assertDate($d, 1975, 10, 1); } - public function testFirstWednesdayOfQuarter() + public function testFirstWednesdayOfQuarter(): void { $d = ChronosDate::create(1975, 11, 21)->firstOfQuarter(Chronos::WEDNESDAY); - $this->assertDate($d, 1975, 10, 1, 0, 0, 0); + $this->assertDate($d, 1975, 10, 1); } - public function testFirstFridayOfQuarter() + public function testFirstFridayOfQuarter(): void { $d = ChronosDate::create(1975, 11, 21)->firstOfQuarter(5); - $this->assertDate($d, 1975, 10, 3, 0, 0, 0); + $this->assertDate($d, 1975, 10, 3); } - public function testFirstOfQuarterFromADayThatWillNotExistIntheFirstMonth() + public function testFirstOfQuarterFromADayThatWillNotExistIntheFirstMonth(): void { $d = ChronosDate::create(2014, 5, 31)->firstOfQuarter(); - $this->assertDate($d, 2014, 4, 1, 0, 0, 0); + $this->assertDate($d, 2014, 4, 1); } - public function testLastDayOfQuarter() + public function testLastDayOfQuarter(): void { $d = ChronosDate::create(1975, 8, 5)->lastOfQuarter(); - $this->assertDate($d, 1975, 9, 30, 0, 0, 0); + $this->assertDate($d, 1975, 9, 30); } - public function testLastTuesdayOfQuarter() + public function testLastTuesdayOfQuarter(): void { $d = ChronosDate::create(1975, 8, 1)->lastOfQuarter(Chronos::TUESDAY); - $this->assertDate($d, 1975, 9, 30, 0, 0, 0); + $this->assertDate($d, 1975, 9, 30); } - public function testLastFridayOfQuarter() + public function testLastFridayOfQuarter(): void { $d = ChronosDate::create(1975, 7, 5)->lastOfQuarter(5); - $this->assertDate($d, 1975, 9, 26, 0, 0, 0); + $this->assertDate($d, 1975, 9, 26); } - public function testLastOfQuarterFromADayThatWillNotExistIntheLastMonth() + public function testLastOfQuarterFromADayThatWillNotExistIntheLastMonth(): void { $d = ChronosDate::create(2014, 5, 31)->lastOfQuarter(); - $this->assertDate($d, 2014, 6, 30, 0, 0, 0); + $this->assertDate($d, 2014, 6, 30); } - public function testNthOfQuarterOutsideScope() + public function testNthOfQuarterOutsideScope(): void { $this->assertFalse(ChronosDate::create(1975, 1, 5)->nthOfQuarter(20, Chronos::MONDAY)); } - public function testNthOfQuarterOutsideYear() + public function testNthOfQuarterOutsideYear(): void { $this->assertFalse(ChronosDate::create(1975, 1, 5)->nthOfQuarter(55, Chronos::MONDAY)); } - public function testNthOfQuarterFromADayThatWillNotExistIntheFirstMonth() + public function testNthOfQuarterFromADayThatWillNotExistIntheFirstMonth(): void { $d = ChronosDate::create(2014, 5, 31)->nthOfQuarter(2, Chronos::MONDAY); - $this->assertDate($d, 2014, 4, 14, 0, 0, 0); + $this->assertDate($d, 2014, 4, 14); } - public function test2ndMondayOfQuarter() + public function test2ndMondayOfQuarter(): void { $d = ChronosDate::create(1975, 8, 5)->nthOfQuarter(2, Chronos::MONDAY); - $this->assertDate($d, 1975, 7, 14, 0, 0, 0); + $this->assertDate($d, 1975, 7, 14); } - public function test3rdWednesdayOfQuarter() + public function test3rdWednesdayOfQuarter(): void { $d = ChronosDate::create(1975, 8, 5)->nthOfQuarter(3, 3); - $this->assertDate($d, 1975, 7, 16, 0, 0, 0); + $this->assertDate($d, 1975, 7, 16); } - public function testFirstDayOfYear() + public function testFirstDayOfYear(): void { $d = ChronosDate::create(1975, 11, 21)->firstOfYear(); - $this->assertDate($d, 1975, 1, 1, 0, 0, 0); + $this->assertDate($d, 1975, 1, 1); } - public function testFirstWednesdayOfYear() + public function testFirstWednesdayOfYear(): void { $d = ChronosDate::create(1975, 11, 21)->firstOfYear(Chronos::WEDNESDAY); - $this->assertDate($d, 1975, 1, 1, 0, 0, 0); + $this->assertDate($d, 1975, 1, 1); } - public function testFirstFridayOfYear() + public function testFirstFridayOfYear(): void { $d = ChronosDate::create(1975, 11, 21)->firstOfYear(5); - $this->assertDate($d, 1975, 1, 3, 0, 0, 0); + $this->assertDate($d, 1975, 1, 3); } - public function testLastDayOfYear() + public function testLastDayOfYear(): void { $d = ChronosDate::create(1975, 8, 5)->lastOfYear(); - $this->assertDate($d, 1975, 12, 31, 0, 0, 0); + $this->assertDate($d, 1975, 12, 31); } - public function testLastTuesdayOfYear() + public function testLastTuesdayOfYear(): void { $d = ChronosDate::create(1975, 8, 1)->lastOfYear(Chronos::TUESDAY); - $this->assertDate($d, 1975, 12, 30, 0, 0, 0); + $this->assertDate($d, 1975, 12, 30); } - public function testLastFridayOfYear() + public function testLastFridayOfYear(): void { $d = ChronosDate::create(1975, 7, 5)->lastOfYear(5); - $this->assertDate($d, 1975, 12, 26, 0, 0, 0); + $this->assertDate($d, 1975, 12, 26); } - public function testNthOfYearOutsideScope() + public function testNthOfYearOutsideScope(): void { $this->assertFalse(ChronosDate::create(1975, 1, 5)->nthOfYear(55, Chronos::MONDAY)); } - public function test2ndMondayOfYear() + public function test2ndMondayOfYear(): void { $d = ChronosDate::create(1975, 8, 5)->nthOfYear(2, Chronos::MONDAY); - $this->assertDate($d, 1975, 1, 13, 0, 0, 0); + $this->assertDate($d, 1975, 1, 13); } - public function test3rdWednesdayOfYear() + public function test3rdWednesdayOfYear(): void { $d = ChronosDate::create(1975, 8, 5)->nthOfYear(3, 3); - $this->assertDate($d, 1975, 1, 15, 0, 0, 0); + $this->assertDate($d, 1975, 1, 15); } } diff --git a/tests/TestCase/Date/DiffTest.php b/tests/TestCase/Date/DiffTest.php index e78b5408..2b14280e 100644 --- a/tests/TestCase/Date/DiffTest.php +++ b/tests/TestCase/Date/DiffTest.php @@ -28,272 +28,272 @@ protected function wrapWithTestNow(Closure $func, $dt = null) parent::wrapWithTestNow($func, $dt ?? Chronos::createFromDate(2012, 1, 1)); } - public function testDiffInYearsPositive() + public function testDiffInYearsPositive(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(1, $dt->diffInYears($dt->addYears(1))); } - public function testDiffInYearsNegativeWithSign() + public function testDiffInYearsNegativeWithSign(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(-1, $dt->diffInYears($dt->subYears(1), false)); } - public function testDiffInYearsNegativeNoSign() + public function testDiffInYearsNegativeNoSign(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(1, $dt->diffInYears($dt->subYears(1))); } - public function testDiffInYearsVsDefaultNow() + public function testDiffInYearsVsDefaultNow(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame(1, ChronosDate::parse(Chronos::now())->subYears(1)->diffInYears()); }); } - public function testDiffInYearsEnsureIsTruncated() + public function testDiffInYearsEnsureIsTruncated(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(1, $dt->diffInYears($dt->addYears(1)->addMonths(7))); } - public function testDiffInMonthsPositive() + public function testDiffInMonthsPositive(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(13, $dt->diffInMonths($dt->addYears(1)->addMonths(1))); } - public function testDiffInMonthsNegativeWithSign() + public function testDiffInMonthsNegativeWithSign(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(-11, $dt->diffInMonths($dt->subYears(1)->addMonths(1), false)); } - public function testDiffInMonthsNegativeNoSign() + public function testDiffInMonthsNegativeNoSign(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(11, $dt->diffInMonths($dt->subYears(1)->addMonths(1))); } - public function testDiffInMonthsVsDefaultNow() + public function testDiffInMonthsVsDefaultNow(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame(12, ChronosDate::parse(Chronos::now())->subYears(1)->diffInMonths()); }); } - public function testDiffInMonthsEnsureIsTruncated() + public function testDiffInMonthsEnsureIsTruncated(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(1, $dt->diffInMonths($dt->addMonths(1)->addDays(16))); } - public function testDiffInDaysPositive() + public function testDiffInDaysPositive(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(366, $dt->diffInDays($dt->addYears(1))); } - public function testDiffInDaysNegativeWithSign() + public function testDiffInDaysNegativeWithSign(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(-365, $dt->diffInDays($dt->subYears(1), false)); } - public function testDiffInDaysNegativeNoSign() + public function testDiffInDaysNegativeNoSign(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(365, $dt->diffInDays($dt->subYears(1))); } - public function testDiffInDaysVsDefaultNow() + public function testDiffInDaysVsDefaultNow(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame(7, ChronosDate::parse(Chronos::now())->subWeeks(1)->diffInDays()); }); } - public function testDiffInDaysFilteredPositiveWithMutated() + public function testDiffInDaysFilteredPositiveWithMutated(): void { $dt = ChronosDate::create(2000, 1, 1); - $this->assertSame(5, $dt->diffInDaysFiltered(function ($date) { + $this->assertSame(5, $dt->diffInDaysFiltered(function ($date): bool { return $date->dayOfWeek === 1; }, $dt->endOfMonth())); } - public function testDiffInDaysFilteredPositiveWithSecondObject() + public function testDiffInDaysFilteredPositiveWithSecondObject(): void { $dt1 = ChronosDate::create(2000, 1, 1); $dt2 = ChronosDate::create(2000, 1, 31); - $this->assertSame(5, $dt1->diffInDaysFiltered(function ($date) { + $this->assertSame(5, $dt1->diffInDaysFiltered(function ($date): bool { return $date->dayOfWeek === Chronos::SUNDAY; }, $dt2)); } - public function testDiffInDaysFilteredNegativeNoSignWithMutated() + public function testDiffInDaysFilteredNegativeNoSignWithMutated(): void { $dt = ChronosDate::create(2000, 1, 31); - $this->assertSame(5, $dt->diffInDaysFiltered(function ($date) { + $this->assertSame(5, $dt->diffInDaysFiltered(function ($date): bool { return $date->dayOfWeek === Chronos::SUNDAY; }, $dt->startOfMonth())); } - public function testDiffInDaysFilteredNegativeNoSignWithSecondObject() + public function testDiffInDaysFilteredNegativeNoSignWithSecondObject(): void { $dt1 = ChronosDate::create(2000, 1, 31); $dt2 = ChronosDate::create(2000, 1, 1); - $this->assertSame(5, $dt1->diffInDaysFiltered(function ($date) { + $this->assertSame(5, $dt1->diffInDaysFiltered(function ($date): bool { return $date->dayOfWeek === Chronos::SUNDAY; }, $dt2)); } - public function testDiffInDaysFilteredNegativeWithSignWithMutated() + public function testDiffInDaysFilteredNegativeWithSignWithMutated(): void { $dt = ChronosDate::create(2000, 1, 31); - $this->assertSame(-5, $dt->diffInDaysFiltered(function ($date) { + $this->assertSame(-5, $dt->diffInDaysFiltered(function ($date): bool { return $date->dayOfWeek === 1; }, $dt->startOfMonth(), false)); } - public function testDiffInDaysFilteredNegativeWithSignWithSecondObject() + public function testDiffInDaysFilteredNegativeWithSignWithSecondObject(): void { $dt1 = ChronosDate::create(2000, 1, 31); $dt2 = ChronosDate::create(2000, 1, 1); - $this->assertSame(-5, $dt1->diffInDaysFiltered(function ($date) { + $this->assertSame(-5, $dt1->diffInDaysFiltered(function ($date): bool { return $date->dayOfWeek === Chronos::SUNDAY; }, $dt2, false)); } - public function testDiffFilteredNegativeNoSignWithMutated() + public function testDiffFilteredNegativeNoSignWithMutated(): void { $dt = ChronosDate::create(2000, 1, 31); $interval = Chronos::createInterval(days: 2); - $this->assertSame(2, $dt->diffFiltered($interval, function ($date) { + $this->assertSame(2, $dt->diffFiltered($interval, function ($date): bool { return $date->dayOfWeek === Chronos::SUNDAY; }, $dt->startOfMonth())); } - public function testDiffFilteredNegativeNoSignWithSecondObject() + public function testDiffFilteredNegativeNoSignWithSecondObject(): void { $dt1 = ChronosDate::create(2006, 1, 31); $dt2 = ChronosDate::create(2000, 1, 1); $interval = Chronos::createInterval(years: 1); - $this->assertSame(7, $dt1->diffFiltered($interval, function ($date) { + $this->assertSame(7, $dt1->diffFiltered($interval, function ($date): bool { return $date->month === 1; }, $dt2)); } - public function testDiffFilteredNegativeWithSignWithMutated() + public function testDiffFilteredNegativeWithSignWithMutated(): void { $dt = ChronosDate::create(2000, 1, 31); $interval = Chronos::createInterval(weeks: 1); - $this->assertSame(-4, $dt->diffFiltered($interval, function ($date) { + $this->assertSame(-4, $dt->diffFiltered($interval, function ($date): bool { return $date->month === 12; }, $dt->subMonths(3), false)); } - public function testDiffFilteredNegativeWithSignWithSecondObject() + public function testDiffFilteredNegativeWithSignWithSecondObject(): void { $dt1 = ChronosDate::create(2001, 1, 31); $dt2 = ChronosDate::create(1999, 1, 1); $interval = Chronos::createInterval(months: 1); - $this->assertSame(-12, $dt1->diffFiltered($interval, function ($date) { + $this->assertSame(-12, $dt1->diffFiltered($interval, function ($date): bool { return $date->year === 2000; }, $dt2, false)); } - public function testDiffFilteredWithOptions() + public function testDiffFilteredWithOptions(): void { $dt1 = ChronosDate::create(2000, 1, 1); $dt2 = ChronosDate::create(2000, 1, 2); $interval = Chronos::createInterval(days: 1); - $this->assertSame(1, $dt1->diffFiltered($interval, function ($dt) { + $this->assertSame(1, $dt1->diffFiltered($interval, function ($dt): bool { return $dt->day === 1; }, $dt2)); - $this->assertSame(0, $dt1->diffFiltered($interval, function ($dt) { + $this->assertSame(0, $dt1->diffFiltered($interval, function ($dt): bool { return $dt->day === 1; }, $dt2, options: DatePeriod::EXCLUDE_START_DATE)); } - public function testDiffInWeekdaysPositive() + public function testDiffInWeekdaysPositive(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(21, $dt->diffInWeekdays($dt->endOfMonth())); } - public function testDiffInWeekdaysNegativeNoSign() + public function testDiffInWeekdaysNegativeNoSign(): void { $dt = ChronosDate::create(2000, 1, 31); $this->assertSame(21, $dt->diffInWeekdays($dt->startOfMonth())); } - public function testDiffInWeekdaysNegativeWithSign() + public function testDiffInWeekdaysNegativeWithSign(): void { $dt = ChronosDate::create(2000, 1, 31); $this->assertSame(-21, $dt->diffInWeekdays($dt->startOfMonth(), false)); } - public function testDiffInWeekendDaysPositive() + public function testDiffInWeekendDaysPositive(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(10, $dt->diffInWeekendDays($dt->endOfMonth())); } - public function testDiffInWeekendDaysNegativeNoSign() + public function testDiffInWeekendDaysNegativeNoSign(): void { $dt = ChronosDate::create(2000, 1, 31); $this->assertSame(10, $dt->diffInWeekendDays($dt->startOfMonth())); } - public function testDiffInWeekendDaysNegativeWithSign() + public function testDiffInWeekendDaysNegativeWithSign(): void { $dt = ChronosDate::create(2000, 1, 31); $this->assertSame(-10, $dt->diffInWeekendDays($dt->startOfMonth(), false)); } - public function testDiffInWeeksPositive() + public function testDiffInWeeksPositive(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(52, $dt->diffInWeeks($dt->addYears(1))); } - public function testDiffInWeeksNegativeWithSign() + public function testDiffInWeeksNegativeWithSign(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(-52, $dt->diffInWeeks($dt->subYears(1), false)); } - public function testDiffInWeeksNegativeNoSign() + public function testDiffInWeeksNegativeNoSign(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(52, $dt->diffInWeeks($dt->subYears(1))); } - public function testDiffInWeeksVsDefaultNow() + public function testDiffInWeeksVsDefaultNow(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame(1, ChronosDate::parse(Chronos::now())->subWeeks(1)->diffInWeeks()); }); } - public function testDiffInWeeksEnsureIsTruncated() + public function testDiffInWeeksEnsureIsTruncated(): void { $dt = ChronosDate::create(2000, 1, 1); $this->assertSame(0, $dt->diffInWeeks($dt->addWeeks(1)->subDays(1))); } - public static function diffForHumansProvider() + public static function diffForHumansProvider(): array { $now = ChronosDate::parse('2020-01-04'); @@ -326,37 +326,37 @@ public static function diffForHumansProvider() * @return void */ #[DataProvider('diffForHumansProvider')] - public function testDiffForHumansRelative($now, $date, $expected) + public function testDiffForHumansRelative(ChronosDate $now, ChronosDate $date, string $expected): void { $this->assertSame($expected, $now->diffForHumans($date)); } - public function testDiffForHumansWithNow() + public function testDiffForHumansWithNow(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame('1 day ago', ChronosDate::parse(Chronos::now())->subDays(1)->diffForHumans()); $this->assertSame('1 day from now', ChronosDate::parse(Chronos::now())->addDays(1)->diffForHumans()); }); } - public function testDiffForHumansWithNowAbsolute() + public function testDiffForHumansWithNowAbsolute(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame('1 day', ChronosDate::parse(Chronos::now())->subDays(1)->diffForHumans(null, true)); $this->assertSame('1 day', ChronosDate::parse(Chronos::now())->addDays(1)->diffForHumans(null, true)); }); } - public function testDiffForHumansWithoutDiff() + public function testDiffForHumansWithoutDiff(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame('0 seconds ago', ChronosDate::parse(Chronos::now())->diffForHumans()); }); } - public function testDiffForHumansWithoutDiffAbsolute() + public function testDiffForHumansWithoutDiffAbsolute(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame('0 seconds', ChronosDate::parse(Chronos::now())->diffForHumans(null, true)); }); } diff --git a/tests/TestCase/Date/IsTest.php b/tests/TestCase/Date/IsTest.php index 0374e88b..48abd570 100644 --- a/tests/TestCase/Date/IsTest.php +++ b/tests/TestCase/Date/IsTest.php @@ -21,57 +21,57 @@ class IsTest extends TestCase { - public function testIsWeekdayTrue() + public function testIsWeekdayTrue(): void { $this->assertTrue(ChronosDate::create(2012, 1, 2)->isWeekday()); } - public function testIsWeekdayFalse() + public function testIsWeekdayFalse(): void { $this->assertFalse(ChronosDate::create(2012, 1, 1)->isWeekday()); } - public function testIsWeekendTrue() + public function testIsWeekendTrue(): void { $this->assertTrue(ChronosDate::create(2012, 1, 1)->isWeekend()); } - public function testIsWeekendFalse() + public function testIsWeekendFalse(): void { $this->assertFalse(ChronosDate::create(2012, 1, 2)->isWeekend()); } - public function testIsYesterdayTrue() + public function testIsYesterdayTrue(): void { $this->assertTrue(ChronosDate::now()->subDays(1)->isYesterday()); } - public function testIsYesterdayFalseWithToday() + public function testIsYesterdayFalseWithToday(): void { $this->assertFalse(ChronosDate::now()->isYesterday()); } - public function testIsYesterdayFalseWith2Days() + public function testIsYesterdayFalseWith2Days(): void { $this->assertFalse(ChronosDate::now()->subDays(2)->isYesterday()); } - public function testIsTodayTrue() + public function testIsTodayTrue(): void { $this->assertTrue(ChronosDate::now()->isToday()); } - public function testIsTodayFalseWithYesterday() + public function testIsTodayFalseWithYesterday(): void { $this->assertFalse(ChronosDate::now()->subDays(1)->isToday()); } - public function testIsTodayFalseWithTomorrow() + public function testIsTodayFalseWithTomorrow(): void { $this->assertFalse(ChronosDate::now()->addDays(1)->isToday()); } - public function isTodayFalseWithTimezone() + public function isTodayFalseWithTimezone(): void { date_default_timezone_set('Pacific/Kiritimati'); $samoaTimezone = new DateTimeZone('Pacific/Samoa'); @@ -81,32 +81,32 @@ public function isTodayFalseWithTimezone() $this->assertTrue(ChronosDate::now()->isToday('Pacific/Kiritimati')); } - public function testIsTomorrowTrue() + public function testIsTomorrowTrue(): void { $this->assertTrue(ChronosDate::now()->addDays(1)->isTomorrow()); } - public function testIsTomorrowFalseWithToday() + public function testIsTomorrowFalseWithToday(): void { $this->assertFalse(ChronosDate::now()->isTomorrow()); } - public function testIsTomorrowFalseWith2Days() + public function testIsTomorrowFalseWith2Days(): void { $this->assertFalse(Chronos::now()->addDays(2)->isTomorrow()); } - public function testIsNextWeekTrue() + public function testIsNextWeekTrue(): void { $this->assertTrue(ChronosDate::now()->addWeeks(1)->isNextWeek()); } - public function testIsLastWeekTrue() + public function testIsLastWeekTrue(): void { $this->assertTrue(ChronosDate::now()->subWeeks(1)->isLastWeek()); } - public function testIsNextWeekFalse() + public function testIsNextWeekFalse(): void { $this->assertFalse(ChronosDate::now()->addWeeks(2)->isNextWeek()); @@ -115,7 +115,7 @@ public function testIsNextWeekFalse() $this->assertFalse($time->isNextWeek()); } - public function testIsLastWeekFalse() + public function testIsLastWeekFalse(): void { $this->assertFalse(ChronosDate::now()->subWeeks(2)->isLastWeek()); @@ -124,17 +124,17 @@ public function testIsLastWeekFalse() $this->assertFalse($time->isLastWeek()); } - public function testIsNextMonthTrue() + public function testIsNextMonthTrue(): void { $this->assertTrue(ChronosDate::now()->addMonths(1)->isNextMonth()); } - public function testIsLastMonthTrue() + public function testIsLastMonthTrue(): void { $this->assertTrue(ChronosDate::now()->subMonths(1)->isLastMonth()); } - public function testIsNextMonthFalse() + public function testIsNextMonthFalse(): void { $this->assertFalse(ChronosDate::now()->addMonths(2)->isNextMonth()); @@ -143,7 +143,7 @@ public function testIsNextMonthFalse() $this->assertFalse($time->isNextMonth()); } - public function testIsLastMonthFalse() + public function testIsLastMonthFalse(): void { $this->assertFalse(ChronosDate::now()->subMonths(2)->isLastMonth()); @@ -152,62 +152,62 @@ public function testIsLastMonthFalse() $this->assertFalse($time->isLastMonth()); } - public function testIsNextYearTrue() + public function testIsNextYearTrue(): void { $this->assertTrue(ChronosDate::now()->addYears(1)->isNextYear()); } - public function testIsLastYearTrue() + public function testIsLastYearTrue(): void { $this->assertTrue(ChronosDate::now()->subYears(1)->isLastYear()); } - public function testIsNextYearFalse() + public function testIsNextYearFalse(): void { $this->assertFalse(ChronosDate::now()->addYears(2)->isNextYear()); } - public function testIsLastYearFalse() + public function testIsLastYearFalse(): void { $this->assertFalse(ChronosDate::now()->subYears(2)->isLastYear()); } - public function testIsFutureTrue() + public function testIsFutureTrue(): void { $this->assertTrue(ChronosDate::now()->addDays(1)->isFuture()); } - public function testIsFutureFalse() + public function testIsFutureFalse(): void { $this->assertFalse(ChronosDate::now()->isFuture()); } - public function testIsFutureFalseInThePast() + public function testIsFutureFalseInThePast(): void { $this->assertFalse(ChronosDate::now()->subDays(1)->isFuture()); } - public function testIsPastTrue() + public function testIsPastTrue(): void { $this->assertTrue(ChronosDate::now()->subDays(1)->isPast()); } - public function testIsPastFalse() + public function testIsPastFalse(): void { $this->assertFalse(ChronosDate::now()->addDays(1)->isPast()); } - public function testIsLeapYearTrue() + public function testIsLeapYearTrue(): void { $this->assertTrue(ChronosDate::create(2016, 1, 1)->isLeapYear()); } - public function testIsLeapYearFalse() + public function testIsLeapYearFalse(): void { $this->assertFalse(ChronosDate::create(2014, 1, 1)->isLeapYear()); } - public function testIsSunday() + public function testIsSunday(): void { // True in the past past $this->assertTrue(ChronosDate::create(2015, 5, 31)->isSunday()); @@ -227,7 +227,7 @@ public function testIsSunday() $this->assertFalse(ChronosDate::parse(Chronos::now())->addMonths(1)->previous(Chronos::MONDAY)->isSunday()); } - public function testIsMonday() + public function testIsMonday(): void { // True in the past past $this->assertTrue(ChronosDate::create(2015, 6, 1)->isMonday()); @@ -246,7 +246,7 @@ public function testIsMonday() $this->assertFalse(ChronosDate::parse(Chronos::now())->addMonths(1)->previous(Chronos::TUESDAY)->isMonday()); } - public function testIsTuesday() + public function testIsTuesday(): void { // True in the past past $this->assertTrue(ChronosDate::create(2015, 6, 2)->isTuesday()); @@ -265,7 +265,7 @@ public function testIsTuesday() $this->assertFalse(ChronosDate::parse(Chronos::now())->addMonths(1)->previous(Chronos::WEDNESDAY)->isTuesday()); } - public function testIsWednesday() + public function testIsWednesday(): void { // True in the past past $this->assertTrue(ChronosDate::create(2015, 6, 3)->isWednesday()); @@ -284,7 +284,7 @@ public function testIsWednesday() $this->assertFalse(ChronosDate::parse(Chronos::now())->addMonths(1)->previous(Chronos::THURSDAY)->isWednesday()); } - public function testIsThursday() + public function testIsThursday(): void { // True in the past past $this->assertTrue(ChronosDate::create(2015, 6, 4)->isThursday()); @@ -303,7 +303,7 @@ public function testIsThursday() $this->assertFalse(ChronosDate::parse(Chronos::now())->addMonths(1)->previous(Chronos::FRIDAY)->isThursday()); } - public function testIsFriday() + public function testIsFriday(): void { // True in the past past $this->assertTrue(ChronosDate::create(2015, 6, 5)->isFriday()); @@ -322,7 +322,7 @@ public function testIsFriday() $this->assertFalse(ChronosDate::parse(Chronos::now())->addMonths(1)->previous(Chronos::SATURDAY)->isFriday()); } - public function testIsSaturday() + public function testIsSaturday(): void { // True in the past past $this->assertTrue(ChronosDate::create(2015, 6, 6)->isSaturday()); @@ -341,7 +341,7 @@ public function testIsSaturday() $this->assertFalse(ChronosDate::parse(Chronos::now())->addMonths(1)->previous(Chronos::SUNDAY)->isSaturday()); } - public function testWasWithinLast() + public function testWasWithinLast(): void { $this->assertTrue((new Chronos('-1 day'))->wasWithinLast('1 day')); $this->assertTrue((new Chronos('-1 week'))->wasWithinLast('1 week')); @@ -353,7 +353,7 @@ public function testWasWithinLast() $this->assertFalse((new Chronos('-1 weeks'))->wasWithinLast('1 day')); } - public function testIsWithinNext() + public function testIsWithinNext(): void { $this->assertFalse((new Chronos('-1 day'))->isWithinNext('1 day')); $this->assertFalse((new Chronos('-1 week'))->isWithinNext('1 week')); diff --git a/tests/TestCase/Date/StartEndOfTest.php b/tests/TestCase/Date/StartEndOfTest.php index f1a5af7c..961de712 100644 --- a/tests/TestCase/Date/StartEndOfTest.php +++ b/tests/TestCase/Date/StartEndOfTest.php @@ -21,191 +21,191 @@ class StartEndOfTest extends TestCase { - public function testStartOfMonthIsFluid() + public function testStartOfMonthIsFluid(): void { $now = ChronosDate::parse(Chronos::now()); $dt = $now->startOfMonth(); $this->assertTrue($dt instanceof ChronosDate); } - public function testStartOfMonthFromNow() + public function testStartOfMonthFromNow(): void { $dt = ChronosDate::parse(Chronos::now())->startOfMonth(); $this->assertDateTime($dt, $dt->year, $dt->month, 1); } - public function testStartOfMonthFromLastDay() + public function testStartOfMonthFromLastDay(): void { $dt = ChronosDate::create(2000, 1, 31)->startOfMonth(); $this->assertDateTime($dt, 2000, 1, 1); } - public function testStartOfYearIsFluid() + public function testStartOfYearIsFluid(): void { $now = ChronosDate::parse(Chronos::now()); $dt = $now->startOfYear(); $this->assertTrue($dt instanceof ChronosDate); } - public function testStartOfYearFromNow() + public function testStartOfYearFromNow(): void { $dt = ChronosDate::parse(Chronos::now())->startOfYear(); $this->assertDateTime($dt, $dt->year, 1, 1); } - public function testStartOfYearFromFirstDay() + public function testStartOfYearFromFirstDay(): void { $dt = ChronosDate::create(2000, 1, 1)->startOfYear(); $this->assertDateTime($dt, 2000, 1, 1); } - public function testStartOfYearFromLastDay() + public function testStartOfYearFromLastDay(): void { $dt = ChronosDate::create(2000, 12, 31)->startOfYear(); $this->assertDateTime($dt, 2000, 1, 1); } - public function testEndOfMonthIsFluid() + public function testEndOfMonthIsFluid(): void { $now = ChronosDate::parse(Chronos::now()); $dt = $now->endOfMonth(); $this->assertTrue($dt instanceof ChronosDate); } - public function testEndOfMonth() + public function testEndOfMonth(): void { $dt = ChronosDate::create(2000, 1, 1)->endOfMonth(); $this->assertDateTime($dt, 2000, 1, 31); } - public function testEndOfMonthFromLastDay() + public function testEndOfMonthFromLastDay(): void { $dt = ChronosDate::create(2000, 1, 31)->endOfMonth(); $this->assertDateTime($dt, 2000, 1, 31); } - public function testEndOfYearIsFluid() + public function testEndOfYearIsFluid(): void { $now = ChronosDate::parse(Chronos::now()); $dt = $now->endOfYear(); $this->assertTrue($dt instanceof ChronosDate); } - public function testEndOfYearFromNow() + public function testEndOfYearFromNow(): void { $dt = ChronosDate::parse(Chronos::now())->endOfYear(); $this->assertDateTime($dt, $dt->year, 12, 31); } - public function testEndOfYearFromFirstDay() + public function testEndOfYearFromFirstDay(): void { - $dt = ChronosDate::create(2000, 1, 1, 1, 1, 1)->endOfYear(); + $dt = ChronosDate::create(2000, 1, 1)->endOfYear(); $this->assertDateTime($dt, 2000, 12, 31); } - public function testEndOfYearFromLastDay() + public function testEndOfYearFromLastDay(): void { $dt = ChronosDate::create(2000, 12, 31)->endOfYear(); $this->assertDateTime($dt, 2000, 12, 31); } - public function testStartOfDecadeIsFluid() + public function testStartOfDecadeIsFluid(): void { $now = ChronosDate::parse(Chronos::now()); $dt = $now->startOfDecade(); $this->assertTrue($dt instanceof ChronosDate); } - public function testStartOfDecadeFromNow() + public function testStartOfDecadeFromNow(): void { $dt = ChronosDate::parse(Chronos::now())->startOfDecade(); $this->assertDateTime($dt, $dt->year - $dt->year % 10, 1, 1); } - public function testStartOfDecadeFromFirstDay() + public function testStartOfDecadeFromFirstDay(): void { $dt = ChronosDate::create(2000, 1, 1)->startOfDecade(); $this->assertDateTime($dt, 2000, 1, 1); } - public function testStartOfDecadeFromLastDay() + public function testStartOfDecadeFromLastDay(): void { $dt = ChronosDate::create(2009, 12, 31)->startOfDecade(); $this->assertDateTime($dt, 2000, 1, 1); } - public function testEndOfDecadeIsFluid() + public function testEndOfDecadeIsFluid(): void { $now = ChronosDate::parse(Chronos::now()); $dt = $now->endOfDecade(); $this->assertTrue($dt instanceof ChronosDate); } - public function testEndOfDecadeFromNow() + public function testEndOfDecadeFromNow(): void { $dt = ChronosDate::parse(Chronos::now())->endOfDecade(); $this->assertDateTime($dt, $dt->year - $dt->year % 10 + 9, 12, 31); } - public function testEndOfDecadeFromFirstDay() + public function testEndOfDecadeFromFirstDay(): void { $dt = ChronosDate::create(2000, 1, 1)->endOfDecade(); $this->assertDateTime($dt, 2009, 12, 31); } - public function testEndOfDecadeFromLastDay() + public function testEndOfDecadeFromLastDay(): void { $dt = ChronosDate::create(2009, 12, 31)->endOfDecade(); $this->assertDateTime($dt, 2009, 12, 31); } - public function testStartOfCenturyIsFluid() + public function testStartOfCenturyIsFluid(): void { $now = ChronosDate::parse(Chronos::now()); $dt = $now->startOfCentury(); $this->assertTrue($dt instanceof ChronosDate); } - public function testStartOfCenturyFromNow() + public function testStartOfCenturyFromNow(): void { $now = ChronosDate::parse(Chronos::now()); $dt = ChronosDate::parse(Chronos::now())->startOfCentury(); $this->assertDateTime($dt, $now->year - $now->year % 100 + 1, 1, 1); } - public function testStartOfCenturyFromFirstDay() + public function testStartOfCenturyFromFirstDay(): void { $dt = ChronosDate::create(2001, 1, 1)->startOfCentury(); $this->assertDateTime($dt, 2001, 1, 1); } - public function testStartOfCenturyFromLastDay() + public function testStartOfCenturyFromLastDay(): void { $dt = ChronosDate::create(2100, 12, 31)->startOfCentury(); $this->assertDateTime($dt, 2001, 1, 1); } - public function testEndOfCenturyIsFluid() + public function testEndOfCenturyIsFluid(): void { $now = ChronosDate::parse(Chronos::now()); $dt = $now->endOfCentury(); $this->assertTrue($dt instanceof ChronosDate); } - public function testEndOfCenturyFromNow() + public function testEndOfCenturyFromNow(): void { $now = ChronosDate::parse(Chronos::now()); $dt = ChronosDate::parse(Chronos::now())->endOfCentury(); $this->assertDateTime($dt, $now->year - $now->year % 100 + 100, 12, 31); } - public function testEndOfCenturyFromFirstDay() + public function testEndOfCenturyFromFirstDay(): void { - $dt = ChronosDate::create(2001, 1, 1, 1, 1, 1)->endOfCentury(); + $dt = ChronosDate::create(2001, 1, 1)->endOfCentury(); $this->assertDateTime($dt, 2100, 12, 31); } - public function testEndOfCenturyFromLastDay() + public function testEndOfCenturyFromLastDay(): void { $dt = ChronosDate::create(2100, 12, 31)->endOfCentury(); $this->assertDateTime($dt, 2100, 12, 31); diff --git a/tests/TestCase/Date/StringsTest.php b/tests/TestCase/Date/StringsTest.php index aede1d4c..e9f59e66 100644 --- a/tests/TestCase/Date/StringsTest.php +++ b/tests/TestCase/Date/StringsTest.php @@ -30,7 +30,7 @@ class StringsTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->tz = date_default_timezone_get(); @@ -42,7 +42,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); date_default_timezone_set($this->tz); @@ -50,20 +50,20 @@ public function tearDown(): void unset($this->tz); } - public function testToString() + public function testToString(): void { $d = ChronosDate::parse('2021-01-01'); $this->assertSame($d->toDateString(), '' . $d); } - public function testSetToStringFormat() + public function testSetToStringFormat(): void { ChronosDate::setToStringFormat('jS \o\f F, Y g:i:s a'); $d = ChronosDate::create(1975, 12, 25); $this->assertSame('25th of December, 1975 12:00:00 am', '' . $d); } - public function testResetToStringFormat() + public function testResetToStringFormat(): void { $d = ChronosDate::parse(Chronos::now()); ChronosDate::setToStringFormat('123'); @@ -71,45 +71,45 @@ public function testResetToStringFormat() $this->assertSame($d->toDateString(), '' . $d); } - public function testToDateString() + public function testToDateString(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); $this->assertSame('1975-12-25', $d->toDateString()); } - public function testToFormattedDateString() + public function testToFormattedDateString(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); $this->assertSame('Dec 25, 1975', $d->toFormattedDateString()); } - public function testToTimeString() + public function testToTimeString(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); $this->assertSame('00:00:00', $d->toTimeString()); } - public function testToDateTimeString() + public function testToDateTimeString(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); $this->assertSame('1975-12-25 00:00:00', $d->toDateTimeString()); } - public function testToDayDateTimeString() + public function testToDayDateTimeString(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); $this->assertSame('Thu, Dec 25, 1975 12:00 AM', $d->toDayDateTimeString()); } - public function testToAtomString() + public function testToAtomString(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); $this->assertSame('1975-12-25T00:00:00+00:00', $d->toAtomString()); } - public function testToCOOKIEString() + public function testToCOOKIEString(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); if (DateTime::COOKIE === 'l, d-M-y H:i:s T') { $cookieString = 'Thursday, 25-Dec-75 00:00:00 UTC'; } else { @@ -119,57 +119,57 @@ public function testToCOOKIEString() $this->assertSame($cookieString, $d->toCOOKIEString()); } - public function testToIso8601String() + public function testToIso8601String(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); $this->assertSame('1975-12-25T00:00:00+00:00', $d->toIso8601String()); } - public function testToRC822String() + public function testToRC822String(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); $this->assertSame('Thu, 25 Dec 75 00:00:00 +0000', $d->toRfc822String()); } - public function testToRfc850String() + public function testToRfc850String(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); $this->assertSame('Thursday, 25-Dec-75 00:00:00 UTC', $d->toRfc850String()); } - public function testToRfc1036String() + public function testToRfc1036String(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); $this->assertSame('Thu, 25 Dec 75 00:00:00 +0000', $d->toRfc1036String()); } - public function testToRfc1123String() + public function testToRfc1123String(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); $this->assertSame('Thu, 25 Dec 1975 00:00:00 +0000', $d->toRfc1123String()); } - public function testToRfc2822String() + public function testToRfc2822String(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); $this->assertSame('Thu, 25 Dec 1975 00:00:00 +0000', $d->toRfc2822String()); } - public function testToRfc3339String() + public function testToRfc3339String(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); $this->assertSame('1975-12-25T00:00:00+00:00', $d->toRfc3339String()); } - public function testToRssString() + public function testToRssString(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); $this->assertSame('Thu, 25 Dec 1975 00:00:00 +0000', $d->toRssString()); } - public function testToW3cString() + public function testToW3cString(): void { - $d = ChronosDate::create(1975, 12, 25, 14, 15, 16); + $d = ChronosDate::create(1975, 12, 25); $this->assertSame('1975-12-25T00:00:00+00:00', $d->toW3cString()); } diff --git a/tests/TestCase/DateTime/AddTest.php b/tests/TestCase/DateTime/AddTest.php index 866f0531..5a0fee89 100644 --- a/tests/TestCase/DateTime/AddTest.php +++ b/tests/TestCase/DateTime/AddTest.php @@ -20,52 +20,52 @@ class AddTest extends TestCase { - public function testAddYearsPositive() + public function testAddYearsPositive(): void { $this->assertSame(1976, Chronos::createFromDate(1975)->addYears(1)->year); } - public function testAddYearsZero() + public function testAddYearsZero(): void { $this->assertSame(1975, Chronos::createFromDate(1975)->addYears(0)->year); } - public function testAddYearsNegative() + public function testAddYearsNegative(): void { $this->assertSame(1974, Chronos::createFromDate(1975)->addYears(-1)->year); } - public function testAddYears() + public function testAddYears(): void { $this->assertSame(1976, Chronos::createFromDate(1975)->addYears(1)->year); } - public function testAddMonthsPositive() + public function testAddMonthsPositive(): void { $this->assertSame(1, Chronos::createFromDate(1975, 12)->addMonths(1)->month); } - public function testAddMonthsZero() + public function testAddMonthsZero(): void { $this->assertSame(12, Chronos::createFromDate(1975, 12)->addMonths(0)->month); } - public function testAddMonthsNegative() + public function testAddMonthsNegative(): void { $this->assertSame(11, Chronos::createFromDate(1975, 12, 1)->addMonths(-1)->month); } - public function testAddMonth() + public function testAddMonth(): void { $this->assertSame(1, Chronos::createFromDate(1975, 12)->addMonths(1)->month); } - public function testAddMonthWithOverflow() + public function testAddMonthWithOverflow(): void { $this->assertSame(3, Chronos::createFromDate(2012, 1, 31)->addMonthsWithOverflow(1)->month); } - public function testAddMonthsNoOverflowPositive() + public function testAddMonthsNoOverflowPositive(): void { $this->assertSame('2012-02-29', Chronos::createFromDate(2012, 1, 31)->addMonths(1)->toDateString()); $this->assertSame('2012-03-31', Chronos::createFromDate(2012, 1, 31)->addMonths(2)->toDateString()); @@ -73,12 +73,12 @@ public function testAddMonthsNoOverflowPositive() $this->assertSame('2012-02-29', Chronos::createFromDate(2011, 12, 31)->addMonths(2)->toDateString()); } - public function testAddMonthsNoOverflowZero() + public function testAddMonthsNoOverflowZero(): void { $this->assertSame(12, Chronos::createFromDate(1975, 12)->addMonths(0)->month); } - public function testAddMonthsNoOverflowNegative() + public function testAddMonthsNoOverflowNegative(): void { $this->assertSame('2012-01-29', Chronos::createFromDate(2012, 2, 29)->addMonths(-1)->toDateString()); $this->assertSame('2012-01-31', Chronos::createFromDate(2012, 3, 31)->addMonths(-2)->toDateString()); @@ -86,32 +86,32 @@ public function testAddMonthsNoOverflowNegative() $this->assertSame('2011-12-31', Chronos::createFromDate(2012, 1, 31)->addMonths(-1)->toDateString()); } - public function testAddDaysPositive() + public function testAddDaysPositive(): void { $this->assertSame(1, Chronos::createFromDate(1975, 5, 31)->addDays(1)->day); } - public function testAddDaysZero() + public function testAddDaysZero(): void { $this->assertSame(31, Chronos::createFromDate(1975, 5, 31)->addDays(0)->day); } - public function testAddDaysNegative() + public function testAddDaysNegative(): void { $this->assertSame(30, Chronos::createFromDate(1975, 5, 31)->addDays(-1)->day); } - public function testAddDay() + public function testAddDay(): void { $this->assertSame(1, Chronos::createFromDate(1975, 5, 31)->addDays(1)->day); } - public function testAddWeekdayDuringWeekend() + public function testAddWeekdayDuringWeekend(): void { $this->assertSame(9, Chronos::createFromDate(2012, 1, 7)->addWeekdays(1)->day); } - public function testAddWeekdaysPositive() + public function testAddWeekdaysPositive(): void { $dt = Chronos::create(2012, 1, 4, 13, 2, 1)->addWeekdays(9); $this->assertSame(17, $dt->day); @@ -122,114 +122,114 @@ public function testAddWeekdaysPositive() $this->assertSame(1, $dt->second); } - public function testAddWeekdaysZero() + public function testAddWeekdaysZero(): void { $this->assertSame(4, Chronos::createFromDate(2012, 1, 4)->addWeekdays(0)->day); } - public function testAddWeekdaysNegative() + public function testAddWeekdaysNegative(): void { $this->assertSame(18, Chronos::createFromDate(2012, 1, 31)->addWeekdays(-9)->day); } - public function testAddWeekday() + public function testAddWeekday(): void { $this->assertSame(9, Chronos::createFromDate(2012, 1, 6)->addWeekdays(1)->day); } - public function testAddWeeksPositive() + public function testAddWeeksPositive(): void { $this->assertSame(28, Chronos::createFromDate(1975, 5, 21)->addWeeks(1)->day); } - public function testAddWeeksZero() + public function testAddWeeksZero(): void { $this->assertSame(21, Chronos::createFromDate(1975, 5, 21)->addWeeks(0)->day); } - public function testAddWeeksNegative() + public function testAddWeeksNegative(): void { $this->assertSame(14, Chronos::createFromDate(1975, 5, 21)->addWeeks(-1)->day); } - public function testAddWeek() + public function testAddWeek(): void { $this->assertSame(28, Chronos::createFromDate(1975, 5, 21)->addWeeks(1)->day); } - public function testAddHoursPositive() + public function testAddHoursPositive(): void { $this->assertSame(1, Chronos::createFromTime(0)->addHours(1)->hour); } - public function testAddHoursZero() + public function testAddHoursZero(): void { $this->assertSame(0, Chronos::createFromTime(0)->addHours(0)->hour); } - public function testAddHoursNegative() + public function testAddHoursNegative(): void { $this->assertSame(23, Chronos::createFromTime(0)->addHours(-1)->hour); } - public function testAddHour() + public function testAddHour(): void { $this->assertSame(1, Chronos::createFromTime(0)->addHours(1)->hour); } - public function testAddMinutesPositive() + public function testAddMinutesPositive(): void { $this->assertSame(1, Chronos::createFromTime(0, 0)->addMinutes(1)->minute); } - public function testAddMinutesZero() + public function testAddMinutesZero(): void { $this->assertSame(0, Chronos::createFromTime(0, 0)->addMinutes(0)->minute); } - public function testAddMinutesNegative() + public function testAddMinutesNegative(): void { $this->assertSame(59, Chronos::createFromTime(0, 0)->addMinutes(-1)->minute); } - public function testAddMinute() + public function testAddMinute(): void { $this->assertSame(1, Chronos::createFromTime(0, 0)->addMinutes(1)->minute); } - public function testAddSecondsPositive() + public function testAddSecondsPositive(): void { $this->assertSame(1, Chronos::createFromTime(0, 0, 0)->addSeconds(1)->second); } - public function testAddSecondsZero() + public function testAddSecondsZero(): void { $this->assertSame(0, Chronos::createFromTime(0, 0, 0)->addSeconds(0)->second); } - public function testAddSecondsNegative() + public function testAddSecondsNegative(): void { $this->assertSame(59, Chronos::createFromTime(0, 0, 0)->addSeconds(-1)->second); } - public function testAddSecond() + public function testAddSecond(): void { $this->assertSame(1, Chronos::createFromTime(0, 0, 0)->addSeconds(1)->second); } /***** Test non plural methods with non default args *****/ - public function testAddYearPassingArg() + public function testAddYearPassingArg(): void { $this->assertSame(1977, Chronos::createFromDate(1975)->addYears(2)->year); } - public function testAddYearWithOverflow() + public function testAddYearWithOverflow(): void { $this->assertSame('2013-03-01', Chronos::createFromDate(2012, 2, 29)->addYearsWithOverflow(1)->toDateString()); } - public function testAddYearsNoOverflowPositive() + public function testAddYearsNoOverflowPositive(): void { $this->assertSame('2013-01-31', Chronos::createFromDate(2012, 1, 31)->addYears(1)->toDateString()); $this->assertSame('2014-01-31', Chronos::createFromDate(2012, 1, 31)->addYears(2)->toDateString()); @@ -237,12 +237,12 @@ public function testAddYearsNoOverflowPositive() $this->assertSame('2013-12-31', Chronos::createFromDate(2011, 12, 31)->addYears(2)->toDateString()); } - public function testAddYearsNoOverflowZero() + public function testAddYearsNoOverflowZero(): void { $this->assertSame('1975-12-31', Chronos::createFromDate(1975, 12, 31)->addYears(0)->toDateString()); } - public function testAddYearsNoOverflowNegative() + public function testAddYearsNoOverflowNegative(): void { $this->assertSame('2011-02-28', Chronos::createFromDate(2012, 2, 29)->addYears(-1)->toDateString()); $this->assertSame('2010-03-31', Chronos::createFromDate(2012, 3, 31)->addYears(-2)->toDateString()); @@ -250,12 +250,12 @@ public function testAddYearsNoOverflowNegative() $this->assertSame('2011-01-31', Chronos::createFromDate(2012, 1, 31)->addYears(-1)->toDateString()); } - public function testAddMonthPassingArg() + public function testAddMonthPassingArg(): void { $this->assertSame(7, Chronos::createFromDate(1975, 5, 1)->addMonths(2)->month); } - public function testAddMonthNoOverflowPassingArg() + public function testAddMonthNoOverflowPassingArg(): void { $dt = Chronos::createFromDate(2010, 12, 31)->addMonths(2); $this->assertSame(2011, $dt->year); @@ -263,22 +263,22 @@ public function testAddMonthNoOverflowPassingArg() $this->assertSame(28, $dt->day); } - public function testAddDayPassingArg() + public function testAddDayPassingArg(): void { $this->assertSame(12, Chronos::createFromDate(1975, 5, 10)->addDays(2)->day); } - public function testAddHourPassingArg() + public function testAddHourPassingArg(): void { $this->assertSame(2, Chronos::createFromTime(0)->addHours(2)->hour); } - public function testAddMinutePassingArg() + public function testAddMinutePassingArg(): void { $this->assertSame(2, Chronos::createFromTime(0)->addMinutes(2)->minute); } - public function testAddSecondPassingArg() + public function testAddSecondPassingArg(): void { $this->assertSame(2, Chronos::createFromTime(0)->addSeconds(2)->second); } diff --git a/tests/TestCase/DateTime/ComparisonTest.php b/tests/TestCase/DateTime/ComparisonTest.php index 3c0e5781..31903f51 100644 --- a/tests/TestCase/DateTime/ComparisonTest.php +++ b/tests/TestCase/DateTime/ComparisonTest.php @@ -22,7 +22,7 @@ class ComparisonTest extends TestCase { - public function testGetSetWeekendDays() + public function testGetSetWeekendDays(): void { $expected = [Chronos::SATURDAY, Chronos::SUNDAY]; $this->assertSame($expected, Chronos::getWeekendDays()); @@ -34,7 +34,7 @@ public function testGetSetWeekendDays() Chronos::setWeekendDays($expected); } - public function testEquals() + public function testEquals(): void { $left = Chronos::create(2000, 1, 1, 0, 0, 0); $this->assertTrue($left == new Chronos('2000-01-01 00:00:00')); @@ -55,7 +55,7 @@ public function testEquals() $this->assertFalse($left->equals(new DateTimeImmutable('2000-01-01 12:00:00', new DateTimeZone('America/Vancouver')))); } - public function testNotEquals() + public function testNotEquals(): void { $left = Chronos::create(2000, 1, 1, 0, 0, 0); $this->assertTrue($left != new Chronos('2000-01-02 00:00:00')); @@ -76,7 +76,7 @@ public function testNotEquals() $this->assertFalse($left->notEquals(new DateTimeImmutable('2000-01-01 9:00:00', new DateTimeZone('America/Vancouver')))); } - public function testGreaterThan() + public function testGreaterThan(): void { $left = Chronos::create(2000, 1, 2, 0, 0, 0); $this->assertTrue($left > new Chronos('2000-01-01 00:00:00')); @@ -97,7 +97,7 @@ public function testGreaterThan() $this->assertFalse($left->greaterThan(new DateTimeImmutable('2000-01-01 09:00:00', new DateTimeZone('America/Vancouver')))); } - public function testGreaterThanOrEqual() + public function testGreaterThanOrEqual(): void { $left = Chronos::create(2000, 1, 2, 0, 0, 0); $this->assertTrue($left >= new Chronos('2000-01-01 00:00:00')); @@ -126,7 +126,7 @@ public function testGreaterThanOrEqual() $this->assertFalse($left->greaterThanOrEquals(new DateTimeImmutable('2000-01-01 10:00:00', new DateTimeZone('America/Vancouver')))); } - public function testLessThan() + public function testLessThan(): void { $left = Chronos::create(2000, 1, 1, 0, 0, 0); $this->assertTrue($left < new Chronos('2000-01-02 00:00:00')); @@ -147,7 +147,7 @@ public function testLessThan() $this->assertFalse($left->lessThan(new DateTimeImmutable('2000-01-01 09:00:00', new DateTimeZone('America/Vancouver')))); } - public function testLessThanOrEqual() + public function testLessThanOrEqual(): void { $left = Chronos::create(2000, 1, 2, 0, 0, 0); $this->assertTrue($left <= new Chronos('2000-01-03 00:00:00')); @@ -176,7 +176,7 @@ public function testLessThanOrEqual() $this->assertFalse($left->lessThanOrEquals(new DateTimeImmutable('2000-01-01 08:00:00', new DateTimeZone('America/Vancouver')))); } - public function testBetween() + public function testBetween(): void { $date = new Chronos('2000-01-15 00:00:00'); $this->assertTrue($date->between(new Chronos('2000-01-14 00:00:00'), new Chronos('2000-01-15 00:00:00'))); @@ -199,19 +199,19 @@ public function testBetween() $this->assertFalse($date->between(new DateTimeImmutable('2000-01-15 00:00:00'), new DateTimeImmutable('2000-01-14 00:00:00'), false)); } - public function testMinIsFluid() + public function testMinIsFluid(): void { $dt = Chronos::now(); $this->assertTrue($dt->min() instanceof Chronos); } - public function testMinWithNow() + public function testMinWithNow(): void { $dt = Chronos::create(2012, 1, 1, 0, 0, 0)->min(); $this->assertDateTime($dt, 2012, 1, 1, 0, 0, 0); } - public function testMinWithInstance() + public function testMinWithInstance(): void { $dt1 = Chronos::create(2013, 12, 31, 23, 59, 59); $dt2 = Chronos::create(2012, 1, 1, 0, 0, 0)->min($dt1); @@ -222,19 +222,19 @@ public function testMinWithInstance() $this->assertDateTime($dt2, 2012, 1, 1, 0, 0, 0); } - public function testMaxIsFluid() + public function testMaxIsFluid(): void { $dt = Chronos::now(); $this->assertTrue($dt->max() instanceof Chronos); } - public function testMaxWithNow() + public function testMaxWithNow(): void { $dt = Chronos::create(2099, 12, 31, 23, 59, 59)->max(); $this->assertDateTime($dt, 2099, 12, 31, 23, 59, 59); } - public function testMaxWithInstance() + public function testMaxWithInstance(): void { $dt1 = Chronos::create(2012, 1, 1, 0, 0, 0); $dt2 = Chronos::create(2099, 12, 31, 23, 59, 59)->max($dt1); @@ -245,7 +245,7 @@ public function testMaxWithInstance() $this->assertDateTime($dt2, 2099, 12, 31, 23, 59, 59); } - public function testIsBirthday() + public function testIsBirthday(): void { $dt = Chronos::now(); $aBirthday = $dt->subYears(1); @@ -265,7 +265,7 @@ public function testIsBirthday() $this->assertFalse($dt1->isBirthday(new DateTimeImmutable('2014-04-22 00:00:00'))); } - public function testClosest() + public function testClosest(): void { $instance = Chronos::create(2015, 5, 28, 12, 0, 0); $dt1 = Chronos::create(2015, 5, 28, 11, 0, 0); @@ -280,7 +280,7 @@ public function testClosest() $this->assertInstanceOf(Chronos::class, $closest); } - public function testClosestWithEquals() + public function testClosestWithEquals(): void { $instance = Chronos::create(2015, 5, 28, 12, 0, 0); $dt1 = Chronos::create(2015, 5, 28, 12, 0, 0); @@ -306,7 +306,7 @@ public function testClosestWithOthers(): void $this->assertSame($dt1, $closest); } - public function testFarthest() + public function testFarthest(): void { $instance = Chronos::create(2015, 5, 28, 12, 0, 0); $dt1 = Chronos::create(2015, 5, 28, 11, 0, 0); @@ -321,7 +321,7 @@ public function testFarthest() $this->assertInstanceOf(Chronos::class, $farthest); } - public function testFarthestWithEquals() + public function testFarthestWithEquals(): void { $instance = Chronos::create(2015, 5, 28, 12, 0, 0); $dt1 = Chronos::create(2015, 5, 28, 12, 0, 0); diff --git a/tests/TestCase/DateTime/ConstructTest.php b/tests/TestCase/DateTime/ConstructTest.php index f8d17304..989cc2d0 100644 --- a/tests/TestCase/DateTime/ConstructTest.php +++ b/tests/TestCase/DateTime/ConstructTest.php @@ -25,7 +25,7 @@ class ConstructTest extends TestCase { - public function testCreateFromTimestamp() + public function testCreateFromTimestamp(): void { $ts = 1454284800; $time = new Chronos($ts); @@ -40,7 +40,7 @@ public function testCreateFromTimestamp() $this->assertSame((int)$ts, $time->getTimestamp()); } - public function testCreatesAnInstanceDefaultToNow() + public function testCreatesAnInstanceDefaultToNow(): void { $c = new Chronos(); $now = Chronos::now(); @@ -49,7 +49,7 @@ public function testCreatesAnInstanceDefaultToNow() $this->assertDateTime($c, $now->year, $now->month, $now->day, $now->hour, $now->minute, $now->second); } - public function testParseCreatesAnInstanceDefaultToNow() + public function testParseCreatesAnInstanceDefaultToNow(): void { $c = Chronos::parse(); $now = Chronos::now(); @@ -58,25 +58,25 @@ public function testParseCreatesAnInstanceDefaultToNow() $this->assertDateTime($c, $now->year, $now->month, $now->day, $now->hour, $now->minute, $now->second); } - public function testWithFancyString() + public function testWithFancyString(): void { $c = new Chronos('first day of January 2008'); $this->assertDateTime($c, 2008, 1, 1, 0, 0, 0); } - public function testParseWithFancyString() + public function testParseWithFancyString(): void { $c = Chronos::parse('first day of January 2008'); $this->assertDateTime($c, 2008, 1, 1, 0, 0, 0); } - public function testDefaultTimezone() + public function testDefaultTimezone(): void { $c = new Chronos('now'); $this->assertSame('America/Toronto', $c->tzName); } - public function testConstructWithMicrosecondsAndOffset() + public function testConstructWithMicrosecondsAndOffset(): void { $c = new Chronos('2014-09-29 18:24:54.591767+02:00'); $this->assertDateTime($c, 2014, 9, 29, 18, 24, 54); @@ -84,13 +84,13 @@ public function testConstructWithMicrosecondsAndOffset() $this->assertSame('+02:00', $c->getTimezone()->getName()); } - public function testParseWithDefaultTimezone() + public function testParseWithDefaultTimezone(): void { $c = Chronos::parse('now'); $this->assertSame('America/Toronto', $c->tzName); } - public function testSettingTimezone() + public function testSettingTimezone(): void { $timezone = 'Europe/London'; $dtz = new DateTimeZone($timezone); @@ -102,7 +102,7 @@ public function testSettingTimezone() $this->assertSame($dayLightSavingTimeOffset, $c->offsetHours); } - public function testParseSettingTimezone() + public function testParseSettingTimezone(): void { $timezone = 'Europe/London'; $dtz = new DateTimeZone($timezone); @@ -114,7 +114,7 @@ public function testParseSettingTimezone() $this->assertSame($dayLightSavingTimeOffset, $c->offsetHours); } - public function testSettingTimezoneWithString() + public function testSettingTimezoneWithString(): void { $timezone = 'Asia/Tokyo'; $dtz = new DateTimeZone($timezone); @@ -126,7 +126,7 @@ public function testSettingTimezoneWithString() $this->assertSame(9 + $dayLightSavingTimeOffset, $c->offsetHours); } - public function testParseSettingTimezoneWithString() + public function testParseSettingTimezoneWithString(): void { $timezone = 'Asia/Tokyo'; $dtz = new DateTimeZone($timezone); @@ -138,21 +138,21 @@ public function testParseSettingTimezoneWithString() $this->assertSame(9 + $dayLightSavingTimeOffset, $c->offsetHours); } - public function testCreateFromExistingInstance() + public function testCreateFromExistingInstance(): void { $existingClass = new Chronos(); $newClass = new Chronos($existingClass); $this->assertSame((string)$existingClass, (string)$newClass); } - public function testCreateFromChronosDate() + public function testCreateFromChronosDate(): void { $date = new ChronosDate('2021-01-01'); $chronos = new Chronos($date); $this->assertSame('2021-01-01 00:00:00', $chronos->format('Y-m-d H:i:s')); } - public function testCreateFromChronosTime() + public function testCreateFromChronosTime(): void { $time = new ChronosTime('20:14:12.123456'); $chronos = new Chronos($time); @@ -170,7 +170,7 @@ public function testCreateFromChronosTime() $this->assertSame('Asia/Tokyo', $chronos->tzName); } - public function testCreateFromDateTimeInterface() + public function testCreateFromDateTimeInterface(): void { $existingClass = new DateTimeImmutable(); $newClass = new Chronos($existingClass); diff --git a/tests/TestCase/DateTime/CreateFromDateTest.php b/tests/TestCase/DateTime/CreateFromDateTest.php index b43470e4..e9fbba48 100644 --- a/tests/TestCase/DateTime/CreateFromDateTest.php +++ b/tests/TestCase/DateTime/CreateFromDateTest.php @@ -21,44 +21,44 @@ class CreateFromDateTest extends TestCase { - public function testCreateFromDateWithDefaults() + public function testCreateFromDateWithDefaults(): void { $d = Chronos::createFromDate(); - $this->assertSame($d->timestamp, Chronos::create(null, null, null, null, null, null, null)->timestamp); + $this->assertSame($d->timestamp, Chronos::create()->timestamp); } - public function testCreateFromDate() + public function testCreateFromDate(): void { $d = Chronos::createFromDate(1975, 5, 21); $this->assertDateTime($d, 1975, 5, 21); } - public function testCreateFromDateWithYear() + public function testCreateFromDateWithYear(): void { $d = Chronos::createFromDate(1975); $this->assertSame(1975, $d->year); } - public function testCreateFromDateWithMonth() + public function testCreateFromDateWithMonth(): void { $d = Chronos::createFromDate(null, 5); $this->assertSame(5, $d->month); } - public function testCreateFromDateWithDay() + public function testCreateFromDateWithDay(): void { $d = Chronos::createFromDate(null, null, 21); $this->assertSame(21, $d->day); } - public function testCreateFromDateWithTimezone() + public function testCreateFromDateWithTimezone(): void { $d = Chronos::createFromDate(1975, 5, 21, 'Europe/London'); $this->assertDateTime($d, 1975, 5, 21); $this->assertSame('Europe/London', $d->tzName); } - public function testCreateFromDateWithDateTimeZone() + public function testCreateFromDateWithDateTimeZone(): void { $d = Chronos::createFromDate(1975, 5, 21, new DateTimeZone('Europe/London')); $this->assertDateTime($d, 1975, 5, 21); diff --git a/tests/TestCase/DateTime/CreateFromFormatTest.php b/tests/TestCase/DateTime/CreateFromFormatTest.php index f124679e..b58ce260 100644 --- a/tests/TestCase/DateTime/CreateFromFormatTest.php +++ b/tests/TestCase/DateTime/CreateFromFormatTest.php @@ -22,34 +22,34 @@ class CreateFromFormatTest extends TestCase { - public function testCreateFromFormatReturnsInstance() + public function testCreateFromFormatReturnsInstance(): void { $d = Chronos::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11'); $this->assertDateTime($d, 1975, 5, 21, 22, 32, 11); $this->assertTrue($d instanceof Chronos); } - public function testCreateFromFormatWithTimezoneString() + public function testCreateFromFormatWithTimezoneString(): void { $d = Chronos::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11', 'Europe/London'); $this->assertDateTime($d, 1975, 5, 21, 22, 32, 11); $this->assertSame('Europe/London', $d->tzName); } - public function testCreateFromFormatWithTimezone() + public function testCreateFromFormatWithTimezone(): void { $d = Chronos::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11', new DateTimeZone('Europe/London')); $this->assertDateTime($d, 1975, 5, 21, 22, 32, 11); $this->assertSame('Europe/London', $d->tzName); } - public function testCreateFromFormatWithMillis() + public function testCreateFromFormatWithMillis(): void { $d = Chronos::createFromFormat('Y-m-d H:i:s.u', '1975-05-21 22:32:11.254687'); $this->assertSame(254687, $d->micro); } - public function testCreateFromFormatInvalidFormat() + public function testCreateFromFormatInvalidFormat(): void { $parseException = null; try { @@ -63,7 +63,7 @@ public function testCreateFromFormatInvalidFormat() $this->assertNotEmpty(Chronos::getLastErrors()['errors']); } - public function testCreateFromFormatDoesNotUseTestNow() + public function testCreateFromFormatDoesNotUseTestNow(): void { // createFromFormat should not use testNow - it should behave like PHP's native method Chronos::setTestNow(new Chronos('2020-12-01 14:30:45')); diff --git a/tests/TestCase/DateTime/CreateFromTimeTest.php b/tests/TestCase/DateTime/CreateFromTimeTest.php index b61f7be3..e6f5ff93 100644 --- a/tests/TestCase/DateTime/CreateFromTimeTest.php +++ b/tests/TestCase/DateTime/CreateFromTimeTest.php @@ -21,19 +21,19 @@ class CreateFromTimeTest extends TestCase { - public function testCreateFromDateWithDefaults() + public function testCreateFromDateWithDefaults(): void { $d = Chronos::createFromTime(); - $this->assertSame($d->timestamp, Chronos::create(null, null, null, null, null, null)->timestamp); + $this->assertSame($d->timestamp, Chronos::create()->timestamp); } - public function testCreateFromDate() + public function testCreateFromDate(): void { $d = Chronos::createFromTime(23, 5, 21); $this->assertDateTime($d, Chronos::now()->year, Chronos::now()->month, Chronos::now()->day, 23, 5, 21); } - public function testCreateFromTimeWithHour() + public function testCreateFromTimeWithHour(): void { $d = Chronos::createFromTime(22); $this->assertSame(22, $d->hour); @@ -41,25 +41,25 @@ public function testCreateFromTimeWithHour() $this->assertSame(0, $d->second); } - public function testCreateFromTimeWithMinute() + public function testCreateFromTimeWithMinute(): void { $d = Chronos::createFromTime(null, 5); $this->assertSame(5, $d->minute); } - public function testCreateFromTimeWithSecond() + public function testCreateFromTimeWithSecond(): void { $d = Chronos::createFromTime(null, null, 21); $this->assertSame(21, $d->second); } - public function testCreateFromTimeWithMicrosecond() + public function testCreateFromTimeWithMicrosecond(): void { $d = Chronos::createFromTime(null, null, null, 123456); $this->assertSame(123456, $d->microsecond); } - public function testCreateFromTimeWithDateTimeZone() + public function testCreateFromTimeWithDateTimeZone(): void { $now = Chronos::now(); $d = Chronos::createFromTime(12, 0, 0, 0, new DateTimeZone('Europe/London')); @@ -67,7 +67,7 @@ public function testCreateFromTimeWithDateTimeZone() $this->assertSame('Europe/London', $d->tzName); } - public function testCreateFromTimeWithTimeZoneString() + public function testCreateFromTimeWithTimeZoneString(): void { $now = Chronos::now(); $d = Chronos::createFromTime(12, 0, 0, 0, 'Europe/London'); diff --git a/tests/TestCase/DateTime/CreateFromTimestampTest.php b/tests/TestCase/DateTime/CreateFromTimestampTest.php index 96dc6261..38cee239 100644 --- a/tests/TestCase/DateTime/CreateFromTimestampTest.php +++ b/tests/TestCase/DateTime/CreateFromTimestampTest.php @@ -21,14 +21,14 @@ class CreateFromTimestampTest extends TestCase { - public function testCreateReturnsDatingInstance() + public function testCreateReturnsDatingInstance(): void { $d = Chronos::createFromTimestamp(Chronos::create(1975, 5, 21, 22, 32, 5)->timestamp); $this->assertDateTime($d, 1975, 5, 22, 2, 32, 5); $this->assertSame('+00:00', $d->tzName); } - public function testCreateFromTimestampUsesUTC() + public function testCreateFromTimestampUsesUTC(): void { $d = Chronos::createFromTimestamp(0); @@ -37,14 +37,14 @@ public function testCreateFromTimestampUsesUTC() $this->assertSame('+00:00', $d->tzName); } - public function testCreateFromTimestampWithDateTimeZone() + public function testCreateFromTimestampWithDateTimeZone(): void { $d = Chronos::createFromTimestamp(0, new DateTimeZone('UTC')); $this->assertSame('UTC', $d->tzName); $this->assertDateTime($d, 1970, 1, 1, 0, 0, 0); } - public function testCreateFromTimestampWithString() + public function testCreateFromTimestampWithString(): void { $d = Chronos::createFromTimestamp(0, 'America/Toronto'); // We know Toronto is -5 since no DST in Jan diff --git a/tests/TestCase/DateTime/CreateTest.php b/tests/TestCase/DateTime/CreateTest.php index 82708e56..f1aad5b0 100644 --- a/tests/TestCase/DateTime/CreateTest.php +++ b/tests/TestCase/DateTime/CreateTest.php @@ -22,81 +22,81 @@ class CreateTest extends TestCase { - public function testCreateReturnsDatingInstance() + public function testCreateReturnsDatingInstance(): void { $d = Chronos::create(); $this->assertTrue($d instanceof Chronos); } - public function testCreateWithDefaults() + public function testCreateWithDefaults(): void { $d = Chronos::create(); $this->assertSame($d->timestamp, Chronos::now()->timestamp); } - public function testCreateWithYear() + public function testCreateWithYear(): void { $d = Chronos::create(2012); $this->assertSame(2012, $d->year); } - public function testCreateHandlesNegativeYear() + public function testCreateHandlesNegativeYear(): void { $d = Chronos::create(-1, 10, 12, 1, 2, 3); $this->assertDateTime($d, -1, 10, 12, 1, 2, 3); } - public function testCreateHandlesFiveDigitsPositiveYears() + public function testCreateHandlesFiveDigitsPositiveYears(): void { $c = Chronos::create(999999999, 10, 12, 1, 2, 3); $this->assertDateTime($c, 999999999, 10, 12, 1, 2, 3); } - public function testCreateHandlesFiveDigitsNegativeYears() + public function testCreateHandlesFiveDigitsNegativeYears(): void { $c = Chronos::create(-999999999, 10, 12, 1, 2, 3); $this->assertDateTime($c, -999999999, 10, 12, 1, 2, 3); } - public function testCreateWithMonth() + public function testCreateWithMonth(): void { $d = Chronos::create(null, 3); $this->assertSame(3, $d->month); } - public function testCreateWithInvalidMonth() + public function testCreateWithInvalidMonth(): void { $this->expectException(InvalidArgumentException::class); Chronos::create(null, -5); } - public function testCreateMonthWraps() + public function testCreateMonthWraps(): void { $d = Chronos::create(2011, 0, 1, 0, 0, 0); $this->assertDateTime($d, 2010, 12, 1, 0, 0, 0); } - public function testCreateWithDay() + public function testCreateWithDay(): void { $d = Chronos::create(null, null, 21); $this->assertSame(21, $d->day); } - public function testCreateWithInvalidDay() + public function testCreateWithInvalidDay(): void { $this->expectException(InvalidArgumentException::class); Chronos::create(null, null, -4); } - public function testCreateDayWraps() + public function testCreateDayWraps(): void { $d = Chronos::create(2011, 1, 40, 0, 0, 0); $this->assertDateTime($d, 2011, 2, 9, 0, 0, 0); } - public function testCreateWithHourAndDefaultMinSecToZero() + public function testCreateWithHourAndDefaultMinSecToZero(): void { $d = Chronos::create(null, null, null, 14); $this->assertSame(14, $d->hour); @@ -104,72 +104,72 @@ public function testCreateWithHourAndDefaultMinSecToZero() $this->assertSame(0, $d->second); } - public function testCreateWithInvalidHour() + public function testCreateWithInvalidHour(): void { $this->expectException(InvalidArgumentException::class); Chronos::create(null, null, null, -1); } - public function testCreateHourWraps() + public function testCreateHourWraps(): void { $d = Chronos::create(2011, 1, 1, 24, 0, 0); $this->assertDateTime($d, 2011, 1, 2, 0, 0, 0); } - public function testCreateWithMinute() + public function testCreateWithMinute(): void { $d = Chronos::create(null, null, null, null, 58); $this->assertSame(58, $d->minute); } - public function testCreateWithInvalidMinute() + public function testCreateWithInvalidMinute(): void { $this->expectException(InvalidArgumentException::class); Chronos::create(2011, 1, 1, 0, -2, 0); } - public function testCreateMinuteWraps() + public function testCreateMinuteWraps(): void { $d = Chronos::create(2011, 1, 1, 0, 62, 0); $this->assertDateTime($d, 2011, 1, 1, 1, 2, 0); } - public function testCreateWithSecond() + public function testCreateWithSecond(): void { $d = Chronos::create(null, null, null, null, null, 59); $this->assertSame(59, $d->second); } - public function testCreateWithInvalidSecond() + public function testCreateWithInvalidSecond(): void { $this->expectException(InvalidArgumentException::class); Chronos::create(null, null, null, null, null, -2); } - public function testCreateSecondsWrap() + public function testCreateSecondsWrap(): void { $d = Chronos::create(2012, 1, 1, 0, 0, 61); $this->assertDateTime($d, 2012, 1, 1, 0, 1, 1); } - public function testCreateWithDateTimeZone() + public function testCreateWithDateTimeZone(): void { $d = Chronos::create(2012, 1, 1, 0, 0, 0, 0, new DateTimeZone('Europe/London')); $this->assertDateTime($d, 2012, 1, 1, 0, 0, 0); $this->assertSame('Europe/London', $d->tzName); } - public function testCreateWithTimeZoneString() + public function testCreateWithTimeZoneString(): void { $d = Chronos::create(2012, 1, 1, 0, 0, 0, 0, 'Europe/London'); $this->assertDateTime($d, 2012, 1, 1, 0, 0, 0); $this->assertSame('Europe/London', $d->tzName); } - public function testCreateFromArray() + public function testCreateFromArray(): void { $values = [ 'year' => 2012, @@ -186,7 +186,7 @@ public function testCreateFromArray() $this->assertSame('America/Toronto', $d->tzName); } - public function testCreateFromArrayDateOnly() + public function testCreateFromArrayDateOnly(): void { $values = [ 'year' => 2012, @@ -198,7 +198,7 @@ public function testCreateFromArrayDateOnly() $this->assertSame('America/Toronto', $d->tzName); } - public function testCreateFromArrayTimeOnly() + public function testCreateFromArrayTimeOnly(): void { $values = [ 'hour' => 12, diff --git a/tests/TestCase/DateTime/DayOfWeekModifiersTest.php b/tests/TestCase/DateTime/DayOfWeekModifiersTest.php index dfb1a5dc..a867c5b8 100644 --- a/tests/TestCase/DateTime/DayOfWeekModifiersTest.php +++ b/tests/TestCase/DateTime/DayOfWeekModifiersTest.php @@ -20,49 +20,49 @@ class DayOfWeekModifiersTest extends TestCase { - public function testStartOfWeek() + public function testStartOfWeek(): void { $d = Chronos::create(1980, 8, 7, 12, 11, 9)->startOfWeek(); $this->assertDateTime($d, 1980, 8, 4, 0, 0, 0); } - public function testStartOfWeekFromWeekStart() + public function testStartOfWeekFromWeekStart(): void { $d = Chronos::createFromDate(1980, 8, 4)->startOfWeek(); $this->assertDateTime($d, 1980, 8, 4, 0, 0, 0); } - public function testStartOfWeekCrossingYearBoundary() + public function testStartOfWeekCrossingYearBoundary(): void { $d = Chronos::createFromDate(2013, 12, 31, 'GMT'); $this->assertDateTime($d->startOfWeek(), 2013, 12, 30, 0, 0, 0); } - public function testEndOfWeek() + public function testEndOfWeek(): void { $d = Chronos::create(1980, 8, 7, 11, 12, 13)->endOfWeek(); $this->assertDateTime($d, 1980, 8, 10, 23, 59, 59); } - public function testEndOfWeekFromWeekEnd() + public function testEndOfWeekFromWeekEnd(): void { $d = Chronos::createFromDate(1980, 8, 9)->endOfWeek(); $this->assertDateTime($d, 1980, 8, 10, 23, 59, 59); } - public function testEndOfWeekCrossingYearBoundary() + public function testEndOfWeekCrossingYearBoundary(): void { $d = Chronos::createFromDate(2013, 12, 31, 'GMT'); $this->assertDateTime($d->endOfWeek(), 2014, 1, 5, 23, 59, 59); } - public function testNext() + public function testNext(): void { $d = Chronos::createFromDate(1975, 5, 21)->next(); $this->assertDateTime($d, 1975, 5, 28, 0, 0, 0); } - public function testStartOrEndOfWeekFromWeekWithUTC() + public function testStartOrEndOfWeekFromWeekWithUTC(): void { $d = Chronos::create(2016, 7, 27, 17, 13, 7, 0, 'UTC'); $this->assertDateTime($d->startOfWeek(), 2016, 7, 25, 0, 0, 0); @@ -70,7 +70,7 @@ public function testStartOrEndOfWeekFromWeekWithUTC() $this->assertDateTime($d->startOfWeek()->endOfWeek(), 2016, 7, 31, 23, 59, 59); } - public function testStartOrEndOfWeekFromWeekWithOtherTimezone() + public function testStartOrEndOfWeekFromWeekWithOtherTimezone(): void { $d = Chronos::create(2016, 7, 27, 17, 13, 7, 0, 'America/New_York'); $this->assertDateTime($d->startOfWeek(), 2016, 7, 25, 0, 0, 0); @@ -78,230 +78,230 @@ public function testStartOrEndOfWeekFromWeekWithOtherTimezone() $this->assertDateTime($d->startOfWeek()->endOfWeek(), 2016, 7, 31, 23, 59, 59); } - public function testNextMonday() + public function testNextMonday(): void { $d = Chronos::createFromDate(1975, 5, 21)->next(Chronos::MONDAY); $this->assertDateTime($d, 1975, 5, 26, 0, 0, 0); } - public function testNextSaturday() + public function testNextSaturday(): void { $d = Chronos::createFromDate(1975, 5, 21)->next(6); $this->assertDateTime($d, 1975, 5, 24, 0, 0, 0); } - public function testNextTimestamp() + public function testNextTimestamp(): void { $d = Chronos::createFromDate(1975, 11, 14)->next(); $this->assertDateTime($d, 1975, 11, 21, 0, 0, 0); } - public function testPrevious() + public function testPrevious(): void { $d = Chronos::createFromDate(1975, 5, 21)->previous(); $this->assertDateTime($d, 1975, 5, 14, 0, 0, 0); } - public function testPreviousMonday() + public function testPreviousMonday(): void { $d = Chronos::createFromDate(1975, 5, 21)->previous(Chronos::MONDAY); $this->assertDateTime($d, 1975, 5, 19, 0, 0, 0); } - public function testPreviousSaturday() + public function testPreviousSaturday(): void { $d = Chronos::createFromDate(1975, 5, 21)->previous(6); $this->assertDateTime($d, 1975, 5, 17, 0, 0, 0); } - public function testPreviousTimestamp() + public function testPreviousTimestamp(): void { $d = Chronos::createFromDate(1975, 11, 28)->previous(); $this->assertDateTime($d, 1975, 11, 21, 0, 0, 0); } - public function testFirstDayOfMonth() + public function testFirstDayOfMonth(): void { $d = Chronos::createFromDate(1975, 11, 21)->firstOfMonth(); $this->assertDateTime($d, 1975, 11, 1, 0, 0, 0); } - public function testFirstWednesdayOfMonth() + public function testFirstWednesdayOfMonth(): void { $d = Chronos::createFromDate(1975, 11, 21)->firstOfMonth(Chronos::WEDNESDAY); $this->assertDateTime($d, 1975, 11, 5, 0, 0, 0); } - public function testFirstFridayOfMonth() + public function testFirstFridayOfMonth(): void { $d = Chronos::createFromDate(1975, 11, 21)->firstOfMonth(5); $this->assertDateTime($d, 1975, 11, 7, 0, 0, 0); } - public function testLastDayOfMonth() + public function testLastDayOfMonth(): void { $d = Chronos::createFromDate(1975, 12, 5)->lastOfMonth(); $this->assertDateTime($d, 1975, 12, 31, 0, 0, 0); } - public function testLastTuesdayOfMonth() + public function testLastTuesdayOfMonth(): void { $d = Chronos::createFromDate(1975, 12, 1)->lastOfMonth(Chronos::TUESDAY); $this->assertDateTime($d, 1975, 12, 30, 0, 0, 0); } - public function testLastFridayOfMonth() + public function testLastFridayOfMonth(): void { $d = Chronos::createFromDate(1975, 12, 5)->lastOfMonth(5); $this->assertDateTime($d, 1975, 12, 26, 0, 0, 0); } - public function testNthOfMonthOutsideScope() + public function testNthOfMonthOutsideScope(): void { $this->assertFalse(Chronos::createFromDate(1975, 12, 5)->nthOfMonth(6, Chronos::MONDAY)); } - public function testNthOfMonthOutsideYear() + public function testNthOfMonthOutsideYear(): void { $this->assertFalse(Chronos::createFromDate(1975, 12, 5)->nthOfMonth(55, Chronos::MONDAY)); } - public function test2ndMondayOfMonth() + public function test2ndMondayOfMonth(): void { $d = Chronos::createFromDate(1975, 12, 5)->nthOfMonth(2, Chronos::MONDAY); $this->assertDateTime($d, 1975, 12, 8, 0, 0, 0); } - public function test3rdWednesdayOfMonth() + public function test3rdWednesdayOfMonth(): void { $d = Chronos::createFromDate(1975, 12, 5)->nthOfMonth(3, 3); $this->assertDateTime($d, 1975, 12, 17, 0, 0, 0); } - public function testFirstDayOfQuarter() + public function testFirstDayOfQuarter(): void { $d = Chronos::createFromDate(1975, 11, 21)->firstOfQuarter(); $this->assertDateTime($d, 1975, 10, 1, 0, 0, 0); } - public function testFirstWednesdayOfQuarter() + public function testFirstWednesdayOfQuarter(): void { $d = Chronos::createFromDate(1975, 11, 21)->firstOfQuarter(Chronos::WEDNESDAY); $this->assertDateTime($d, 1975, 10, 1, 0, 0, 0); } - public function testFirstFridayOfQuarter() + public function testFirstFridayOfQuarter(): void { $d = Chronos::createFromDate(1975, 11, 21)->firstOfQuarter(5); $this->assertDateTime($d, 1975, 10, 3, 0, 0, 0); } - public function testFirstOfQuarterFromADayThatWillNotExistIntheFirstMonth() + public function testFirstOfQuarterFromADayThatWillNotExistIntheFirstMonth(): void { $d = Chronos::createFromDate(2014, 5, 31)->firstOfQuarter(); $this->assertDateTime($d, 2014, 4, 1, 0, 0, 0); } - public function testLastDayOfQuarter() + public function testLastDayOfQuarter(): void { $d = Chronos::createFromDate(1975, 8, 5)->lastOfQuarter(); $this->assertDateTime($d, 1975, 9, 30, 0, 0, 0); } - public function testLastTuesdayOfQuarter() + public function testLastTuesdayOfQuarter(): void { $d = Chronos::createFromDate(1975, 8, 1)->lastOfQuarter(Chronos::TUESDAY); $this->assertDateTime($d, 1975, 9, 30, 0, 0, 0); } - public function testLastFridayOfQuarter() + public function testLastFridayOfQuarter(): void { $d = Chronos::createFromDate(1975, 7, 5)->lastOfQuarter(5); $this->assertDateTime($d, 1975, 9, 26, 0, 0, 0); } - public function testLastOfQuarterFromADayThatWillNotExistIntheLastMonth() + public function testLastOfQuarterFromADayThatWillNotExistIntheLastMonth(): void { $d = Chronos::createFromDate(2014, 5, 31)->lastOfQuarter(); $this->assertDateTime($d, 2014, 6, 30, 0, 0, 0); } - public function testNthOfQuarterOutsideScope() + public function testNthOfQuarterOutsideScope(): void { $this->assertFalse(Chronos::createFromDate(1975, 1, 5)->nthOfQuarter(20, Chronos::MONDAY)); } - public function testNthOfQuarterOutsideYear() + public function testNthOfQuarterOutsideYear(): void { $this->assertFalse(Chronos::createFromDate(1975, 1, 5)->nthOfQuarter(55, Chronos::MONDAY)); } - public function testNthOfQuarterFromADayThatWillNotExistIntheFirstMonth() + public function testNthOfQuarterFromADayThatWillNotExistIntheFirstMonth(): void { $d = Chronos::createFromDate(2014, 5, 31)->nthOfQuarter(2, Chronos::MONDAY); $this->assertDateTime($d, 2014, 4, 14, 0, 0, 0); } - public function test2ndMondayOfQuarter() + public function test2ndMondayOfQuarter(): void { $d = Chronos::createFromDate(1975, 8, 5)->nthOfQuarter(2, Chronos::MONDAY); $this->assertDateTime($d, 1975, 7, 14, 0, 0, 0); } - public function test3rdWednesdayOfQuarter() + public function test3rdWednesdayOfQuarter(): void { $d = Chronos::createFromDate(1975, 8, 5)->nthOfQuarter(3, 3); $this->assertDateTime($d, 1975, 7, 16, 0, 0, 0); } - public function testFirstDayOfYear() + public function testFirstDayOfYear(): void { $d = Chronos::createFromDate(1975, 11, 21)->firstOfYear(); $this->assertDateTime($d, 1975, 1, 1, 0, 0, 0); } - public function testFirstWednesdayOfYear() + public function testFirstWednesdayOfYear(): void { $d = Chronos::createFromDate(1975, 11, 21)->firstOfYear(Chronos::WEDNESDAY); $this->assertDateTime($d, 1975, 1, 1, 0, 0, 0); } - public function testFirstFridayOfYear() + public function testFirstFridayOfYear(): void { $d = Chronos::createFromDate(1975, 11, 21)->firstOfYear(5); $this->assertDateTime($d, 1975, 1, 3, 0, 0, 0); } - public function testLastDayOfYear() + public function testLastDayOfYear(): void { $d = Chronos::createFromDate(1975, 8, 5)->lastOfYear(); $this->assertDateTime($d, 1975, 12, 31, 0, 0, 0); } - public function testLastTuesdayOfYear() + public function testLastTuesdayOfYear(): void { $d = Chronos::createFromDate(1975, 8, 1)->lastOfYear(Chronos::TUESDAY); $this->assertDateTime($d, 1975, 12, 30, 0, 0, 0); } - public function testLastFridayOfYear() + public function testLastFridayOfYear(): void { $d = Chronos::createFromDate(1975, 7, 5)->lastOfYear(5); $this->assertDateTime($d, 1975, 12, 26, 0, 0, 0); } - public function testNthOfYearOutsideScope() + public function testNthOfYearOutsideScope(): void { $this->assertFalse(Chronos::createFromDate(1975, 1, 5)->nthOfYear(55, Chronos::MONDAY)); } - public function test2ndMondayOfYear() + public function test2ndMondayOfYear(): void { $d = Chronos::createFromDate(1975, 8, 5)->nthOfYear(2, Chronos::MONDAY); $this->assertDateTime($d, 1975, 1, 13, 0, 0, 0); } - public function test3rdWednesdayOfYear() + public function test3rdWednesdayOfYear(): void { $d = Chronos::createFromDate(1975, 8, 5)->nthOfYear(3, 3); $this->assertDateTime($d, 1975, 1, 15, 0, 0, 0); @@ -310,7 +310,7 @@ public function test3rdWednesdayOfYear() /** * Test nextOccurrenceOf when today is the target day and time hasn't passed. */ - public function testNextOccurrenceOfSameDayBeforeTime() + public function testNextOccurrenceOfSameDayBeforeTime(): void { // It's Tuesday 9am, looking for Tuesday 12pm -> should be today $d = Chronos::create(2024, 1, 9, 9, 0, 0); // Tuesday @@ -321,7 +321,7 @@ public function testNextOccurrenceOfSameDayBeforeTime() /** * Test nextOccurrenceOf when today is the target day but time has passed. */ - public function testNextOccurrenceOfSameDayAfterTime() + public function testNextOccurrenceOfSameDayAfterTime(): void { // It's Tuesday 4pm, looking for Tuesday 12pm -> should be next Tuesday $d = Chronos::create(2024, 1, 9, 16, 0, 0); // Tuesday @@ -332,7 +332,7 @@ public function testNextOccurrenceOfSameDayAfterTime() /** * Test nextOccurrenceOf when today is not the target day. */ - public function testNextOccurrenceOfDifferentDay() + public function testNextOccurrenceOfDifferentDay(): void { // It's Monday, looking for Tuesday 12pm -> should be tomorrow $d = Chronos::create(2024, 1, 8, 9, 0, 0); // Monday @@ -343,7 +343,7 @@ public function testNextOccurrenceOfDifferentDay() /** * Test nextOccurrenceOf with seconds. */ - public function testNextOccurrenceOfWithSeconds() + public function testNextOccurrenceOfWithSeconds(): void { $d = Chronos::create(2024, 1, 8, 9, 0, 0); // Monday $result = $d->nextOccurrenceOf(Chronos::WEDNESDAY, 14, 30, 45); @@ -353,7 +353,7 @@ public function testNextOccurrenceOfWithSeconds() /** * Test nextOccurrenceOf at exact same time returns next week. */ - public function testNextOccurrenceOfAtExactTime() + public function testNextOccurrenceOfAtExactTime(): void { // It's Tuesday 12pm exactly, looking for Tuesday 12pm -> should be next week $d = Chronos::create(2024, 1, 9, 12, 0, 0); // Tuesday 12pm @@ -364,7 +364,7 @@ public function testNextOccurrenceOfAtExactTime() /** * Test previousOccurrenceOf when today is the target day and time has passed. */ - public function testPreviousOccurrenceOfSameDayAfterTime() + public function testPreviousOccurrenceOfSameDayAfterTime(): void { // It's Tuesday 4pm, looking for previous Tuesday 12pm -> should be today $d = Chronos::create(2024, 1, 9, 16, 0, 0); // Tuesday @@ -375,7 +375,7 @@ public function testPreviousOccurrenceOfSameDayAfterTime() /** * Test previousOccurrenceOf when today is the target day but time hasn't passed. */ - public function testPreviousOccurrenceOfSameDayBeforeTime() + public function testPreviousOccurrenceOfSameDayBeforeTime(): void { // It's Tuesday 9am, looking for previous Tuesday 12pm -> should be last Tuesday $d = Chronos::create(2024, 1, 9, 9, 0, 0); // Tuesday @@ -386,7 +386,7 @@ public function testPreviousOccurrenceOfSameDayBeforeTime() /** * Test previousOccurrenceOf when today is not the target day. */ - public function testPreviousOccurrenceOfDifferentDay() + public function testPreviousOccurrenceOfDifferentDay(): void { // It's Wednesday, looking for previous Tuesday 12pm -> should be yesterday $d = Chronos::create(2024, 1, 10, 9, 0, 0); // Wednesday @@ -397,7 +397,7 @@ public function testPreviousOccurrenceOfDifferentDay() /** * Test previousOccurrenceOf at exact same time returns last week. */ - public function testPreviousOccurrenceOfAtExactTime() + public function testPreviousOccurrenceOfAtExactTime(): void { // It's Tuesday 12pm exactly, looking for previous Tuesday 12pm -> should be last week $d = Chronos::create(2024, 1, 9, 12, 0, 0); // Tuesday 12pm diff --git a/tests/TestCase/DateTime/DiffTest.php b/tests/TestCase/DateTime/DiffTest.php index 90abb7e2..0c8a321d 100644 --- a/tests/TestCase/DateTime/DiffTest.php +++ b/tests/TestCase/DateTime/DiffTest.php @@ -29,69 +29,69 @@ protected function wrapWithTestNow(Closure $func, $dt = null) parent::wrapWithTestNow($func, $dt ?? Chronos::createFromDate(2012, 1, 1)); } - public function testDiffInYearsPositive() + public function testDiffInYearsPositive(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(1, $dt->diffInYears($dt->addYears(1))); } - public function testDiffInYearsNegativeWithSign() + public function testDiffInYearsNegativeWithSign(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(-1, $dt->diffInYears($dt->subYears(1), false)); } - public function testDiffInYearsNegativeNoSign() + public function testDiffInYearsNegativeNoSign(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(1, $dt->diffInYears($dt->subYears(1))); } - public function testDiffInYearsVsDefaultNow() + public function testDiffInYearsVsDefaultNow(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame(1, Chronos::now()->subYears(1)->diffInYears()); }); } - public function testDiffInYearsEnsureIsTruncated() + public function testDiffInYearsEnsureIsTruncated(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(1, $dt->diffInYears($dt->addYears(1)->addMonths(7))); } - public function testDiffInMonthsPositive() + public function testDiffInMonthsPositive(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(13, $dt->diffInMonths($dt->addYears(1)->addMonths(1))); } - public function testDiffInMonthsNegativeWithSign() + public function testDiffInMonthsNegativeWithSign(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(-11, $dt->diffInMonths($dt->subYears(1)->addMonths(1), false)); } - public function testDiffInMonthsNegativeNoSign() + public function testDiffInMonthsNegativeNoSign(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(11, $dt->diffInMonths($dt->subYears(1)->addMonths(1))); } - public function testDiffInMonthsVsDefaultNow() + public function testDiffInMonthsVsDefaultNow(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame(12, Chronos::now()->subYears(1)->diffInMonths()); }); } - public function testDiffInMonthsEnsureIsTruncated() + public function testDiffInMonthsEnsureIsTruncated(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(1, $dt->diffInMonths($dt->addMonths(1)->addDays(16))); } - public function testDiffInMonthsIgnoreTimezone() + public function testDiffInMonthsIgnoreTimezone(): void { $tokyoStart = new Chronos('2019-06-01', new DateTimeZone('Asia/Tokyo')); $utcStart = new Chronos('2019-06-01', new DateTimeZone('UTC')); @@ -105,204 +105,204 @@ public function testDiffInMonthsIgnoreTimezone() $this->assertSame($monthOffset + 12, $utcStart->diffInMonthsIgnoreTimezone($end)); } - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame(1, Chronos::now()->subMonths(1)->startOfMonth()->diffInMonthsIgnoreTimezone()); }); } - public function testDiffInDaysPositive() + public function testDiffInDaysPositive(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(366, $dt->diffInDays($dt->addYears(1))); } - public function testDiffInDaysNegativeWithSign() + public function testDiffInDaysNegativeWithSign(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(-365, $dt->diffInDays($dt->subYears(1), false)); } - public function testDiffInDaysNegativeNoSign() + public function testDiffInDaysNegativeNoSign(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(365, $dt->diffInDays($dt->subYears(1))); } - public function testDiffInDaysVsDefaultNow() + public function testDiffInDaysVsDefaultNow(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame(7, Chronos::now()->subWeeks(1)->diffInDays()); }); } - public function testDiffInDaysEnsureIsTruncated() + public function testDiffInDaysEnsureIsTruncated(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(1, $dt->diffInDays($dt->addDays(1)->addHours(13))); } - public function testDiffInDaysFilteredPositiveWithMutated() + public function testDiffInDaysFilteredPositiveWithMutated(): void { $dt = Chronos::createFromDate(2000, 1, 1); - $this->assertSame(5, $dt->diffInDaysFiltered(function ($date) { + $this->assertSame(5, $dt->diffInDaysFiltered(function ($date): bool { return $date->dayOfWeek === 1; }, $dt->endOfMonth())); } - public function testDiffInDaysFilteredPositiveWithSecondObject() + public function testDiffInDaysFilteredPositiveWithSecondObject(): void { $dt1 = Chronos::createFromDate(2000, 1, 1); $dt2 = Chronos::createFromDate(2000, 1, 31); - $this->assertSame(5, $dt1->diffInDaysFiltered(function ($date) { + $this->assertSame(5, $dt1->diffInDaysFiltered(function ($date): bool { return $date->dayOfWeek === Chronos::SUNDAY; }, $dt2)); } - public function testDiffInDaysFilteredNegativeNoSignWithMutated() + public function testDiffInDaysFilteredNegativeNoSignWithMutated(): void { $dt = Chronos::createFromDate(2000, 1, 31); - $this->assertSame(5, $dt->diffInDaysFiltered(function ($date) { + $this->assertSame(5, $dt->diffInDaysFiltered(function ($date): bool { return $date->dayOfWeek === Chronos::SUNDAY; }, $dt->startOfMonth())); } - public function testDiffInDaysFilteredNegativeNoSignWithSecondObject() + public function testDiffInDaysFilteredNegativeNoSignWithSecondObject(): void { $dt1 = Chronos::createFromDate(2000, 1, 31); $dt2 = Chronos::createFromDate(2000, 1, 1); - $this->assertSame(5, $dt1->diffInDaysFiltered(function ($date) { + $this->assertSame(5, $dt1->diffInDaysFiltered(function ($date): bool { return $date->dayOfWeek === Chronos::SUNDAY; }, $dt2)); } - public function testDiffInDaysFilteredNegativeWithSignWithMutated() + public function testDiffInDaysFilteredNegativeWithSignWithMutated(): void { $dt = Chronos::createFromDate(2000, 1, 31); - $this->assertSame(-5, $dt->diffInDaysFiltered(function ($date) { + $this->assertSame(-5, $dt->diffInDaysFiltered(function ($date): bool { return $date->dayOfWeek === 1; }, $dt->startOfMonth(), false)); } - public function testDiffInDaysFilteredNegativeWithSignWithSecondObject() + public function testDiffInDaysFilteredNegativeWithSignWithSecondObject(): void { $dt1 = Chronos::createFromDate(2000, 1, 31); $dt2 = Chronos::createFromDate(2000, 1, 1); - $this->assertSame(-5, $dt1->diffInDaysFiltered(function ($date) { + $this->assertSame(-5, $dt1->diffInDaysFiltered(function ($date): bool { return $date->dayOfWeek === Chronos::SUNDAY; }, $dt2, false)); } - public function testDiffInHoursFiltered() + public function testDiffInHoursFiltered(): void { $dt1 = Chronos::createFromDate(2000, 1, 31)->endOfDay(); $dt2 = Chronos::createFromDate(2000, 1, 1)->startOfDay(); - $this->assertSame(31, $dt1->diffInHoursFiltered(function ($date) { + $this->assertSame(31, $dt1->diffInHoursFiltered(function ($date): bool { return $date->hour === 9; }, $dt2)); } - public function testDiffInHoursFilteredNegative() + public function testDiffInHoursFilteredNegative(): void { $dt1 = Chronos::createFromDate(2000, 1, 31)->endOfDay(); $dt2 = Chronos::createFromDate(2000, 1, 1)->startOfDay(); - $this->assertSame(-31, $dt1->diffInHoursFiltered(function ($date) { + $this->assertSame(-31, $dt1->diffInHoursFiltered(function ($date): bool { return $date->hour === 9; }, $dt2, false)); } - public function testDiffInHoursFilteredWorkHoursPerWeek() + public function testDiffInHoursFilteredWorkHoursPerWeek(): void { $dt1 = Chronos::createFromDate(2000, 1, 5)->endOfDay(); $dt2 = Chronos::createFromDate(2000, 1, 1)->startOfDay(); - $this->assertSame(40, $dt1->diffInHoursFiltered(function ($date) { + $this->assertSame(40, $dt1->diffInHoursFiltered(function ($date): bool { return $date->hour > 8 && $date->hour < 17; }, $dt2)); } - public function testDiffFilteredUsingMinutesPositiveWithMutated() + public function testDiffFilteredUsingMinutesPositiveWithMutated(): void { $dt = Chronos::createFromDate(2000, 1, 1)->startOfDay(); $interval = Chronos::createInterval(minutes: 1); - $this->assertSame(60, $dt->diffFiltered($interval, function ($date) { + $this->assertSame(60, $dt->diffFiltered($interval, function ($date): bool { return $date->hour === 12; }, Chronos::createFromDate(2000, 1, 1)->endOfDay())); } - public function testDiffFilteredPositiveWithSecondObject() + public function testDiffFilteredPositiveWithSecondObject(): void { $dt1 = Chronos::create(2000, 1, 1); $dt2 = $dt1->addSeconds(80); $interval = Chronos::createInterval(seconds: 1); - $this->assertSame(40, $dt1->diffFiltered($interval, function ($date) { + $this->assertSame(40, $dt1->diffFiltered($interval, function ($date): bool { return $date->second % 2 === 0; }, $dt2)); } - public function testDiffFilteredNegativeNoSignWithMutated() + public function testDiffFilteredNegativeNoSignWithMutated(): void { $dt = Chronos::createFromDate(2000, 1, 31); $interval = Chronos::createInterval(days: 2); - $this->assertSame(2, $dt->diffFiltered($interval, function ($date) { + $this->assertSame(2, $dt->diffFiltered($interval, function ($date): bool { return $date->dayOfWeek === Chronos::SUNDAY; }, $dt->startOfMonth())); } - public function testDiffFilteredNegativeNoSignWithSecondObject() + public function testDiffFilteredNegativeNoSignWithSecondObject(): void { $dt1 = Chronos::createFromDate(2006, 1, 31); $dt2 = Chronos::createFromDate(2000, 1, 1); $interval = Chronos::createInterval(years: 1); - $this->assertSame(7, $dt1->diffFiltered($interval, function ($date) { + $this->assertSame(7, $dt1->diffFiltered($interval, function ($date): bool { return $date->month === 1; }, $dt2)); } - public function testDiffFilteredNegativeWithSignWithMutated() + public function testDiffFilteredNegativeWithSignWithMutated(): void { $dt = Chronos::createFromDate(2000, 1, 31); $interval = Chronos::createInterval(weeks: 1); - $this->assertSame(-4, $dt->diffFiltered($interval, function ($date) { + $this->assertSame(-4, $dt->diffFiltered($interval, function ($date): bool { return $date->month === 12; }, $dt->subMonths(3), false)); } - public function testDiffFilteredNegativeWithSignWithSecondObject() + public function testDiffFilteredNegativeWithSignWithSecondObject(): void { $dt1 = Chronos::createFromDate(2001, 1, 31); $dt2 = Chronos::createFromDate(1999, 1, 1); $interval = Chronos::createInterval(months: 1); - $this->assertSame(-12, $dt1->diffFiltered($interval, function ($date) { + $this->assertSame(-12, $dt1->diffFiltered($interval, function ($date): bool { return $date->year === 2000; }, $dt2, false)); } - public function testDiffFilteredWithOptions() + public function testDiffFilteredWithOptions(): void { $dt1 = Chronos::create(2000, 1, 1); $dt2 = Chronos::create(2000, 1, 2); $interval = Chronos::createInterval(days: 1); - $this->assertSame(1, $dt1->diffFiltered($interval, function ($dt) { + $this->assertSame(1, $dt1->diffFiltered($interval, function ($dt): bool { return $dt->day === 1; }, $dt2)); - $this->assertSame(0, $dt1->diffFiltered($interval, function ($dt) { + $this->assertSame(0, $dt1->diffFiltered($interval, function ($dt): bool { return $dt->day === 1; }, $dt2, options: DatePeriod::EXCLUDE_START_DATE)); } - public function testBug188DiffWithSameDates() + public function testBug188DiffWithSameDates(): void { $start = Chronos::create(2014, 10, 8, 15, 20, 0); $end = clone $start; @@ -311,7 +311,7 @@ public function testBug188DiffWithSameDates() $this->assertSame(0, $start->diffInWeekdays($end)); } - public function testBug188DiffWithDatesOnlyHoursApart() + public function testBug188DiffWithDatesOnlyHoursApart(): void { $start = Chronos::create(2014, 10, 8, 15, 20, 0); $end = clone $start; @@ -320,7 +320,7 @@ public function testBug188DiffWithDatesOnlyHoursApart() $this->assertSame(0, $start->diffInWeekdays($end)); } - public function testBug188DiffWithSameDates1DayApart() + public function testBug188DiffWithSameDates1DayApart(): void { $start = Chronos::create(2014, 10, 8, 15, 20, 0); $end = $start->addDays(1); @@ -329,196 +329,197 @@ public function testBug188DiffWithSameDates1DayApart() $this->assertSame(1, $start->diffInWeekdays($end)); } - public function testBug188DiffWithDatesOnTheWeekend() + public function testBug188DiffWithDatesOnTheWeekend(): void { $start = Chronos::create(2014, 1, 1, 0, 0, 0); $start = $start->next(Chronos::SATURDAY); + $end = $start->addDays(1); $this->assertSame(1, $start->diffInDays($end)); $this->assertSame(0, $start->diffInWeekdays($end)); } - public function testDiffInWeekdaysPositive() + public function testDiffInWeekdaysPositive(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(21, $dt->diffInWeekdays($dt->endOfMonth())); } - public function testDiffInWeekdaysNegativeNoSign() + public function testDiffInWeekdaysNegativeNoSign(): void { $dt = Chronos::createFromDate(2000, 1, 31); $this->assertSame(21, $dt->diffInWeekdays($dt->startOfMonth())); } - public function testDiffInWeekdaysNegativeWithSign() + public function testDiffInWeekdaysNegativeWithSign(): void { $dt = Chronos::createFromDate(2000, 1, 31); $this->assertSame(-21, $dt->diffInWeekdays($dt->startOfMonth(), false)); } - public function testDiffInWeekendDaysPositive() + public function testDiffInWeekendDaysPositive(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(10, $dt->diffInWeekendDays($dt->endOfMonth())); } - public function testDiffInWeekendDaysNegativeNoSign() + public function testDiffInWeekendDaysNegativeNoSign(): void { $dt = Chronos::createFromDate(2000, 1, 31); $this->assertSame(10, $dt->diffInWeekendDays($dt->startOfMonth())); } - public function testDiffInWeekendDaysNegativeWithSign() + public function testDiffInWeekendDaysNegativeWithSign(): void { $dt = Chronos::createFromDate(2000, 1, 31); $this->assertSame(-10, $dt->diffInWeekendDays($dt->startOfMonth(), false)); } - public function testDiffInWeeksPositive() + public function testDiffInWeeksPositive(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(52, $dt->diffInWeeks($dt->addYears(1))); } - public function testDiffInWeeksNegativeWithSign() + public function testDiffInWeeksNegativeWithSign(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(-52, $dt->diffInWeeks($dt->subYears(1), false)); } - public function testDiffInWeeksNegativeNoSign() + public function testDiffInWeeksNegativeNoSign(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(52, $dt->diffInWeeks($dt->subYears(1))); } - public function testDiffInWeeksVsDefaultNow() + public function testDiffInWeeksVsDefaultNow(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame(1, Chronos::now()->subWeeks(1)->diffInWeeks()); }); } - public function testDiffInWeeksEnsureIsTruncated() + public function testDiffInWeeksEnsureIsTruncated(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(0, $dt->diffInWeeks($dt->addWeeks(1)->subDays(1))); } - public function testDiffInHoursPositive() + public function testDiffInHoursPositive(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(26, $dt->diffInHours($dt->addDays(1)->addHours(2))); } - public function testDiffInHoursNegativeWithSign() + public function testDiffInHoursNegativeWithSign(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(-22, $dt->diffInHours($dt->subDays(1)->addHours(2), false)); } - public function testDiffInHoursNegativeNoSign() + public function testDiffInHoursNegativeNoSign(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(22, $dt->diffInHours($dt->subDays(1)->addHours(2))); } - public function testDiffInHoursVsDefaultNow() + public function testDiffInHoursVsDefaultNow(): void { date_default_timezone_set('UTC'); - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame(48, Chronos::now()->subDays(2)->diffInHours()); }, Chronos::create(2012, 1, 15)); } - public function testDiffInHoursEnsureIsTruncated() + public function testDiffInHoursEnsureIsTruncated(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(1, $dt->diffInHours($dt->addHours(1)->addMinutes(31))); } - public function testDiffInMinutesPositive() + public function testDiffInMinutesPositive(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(62, $dt->diffInMinutes($dt->addHours(1)->addMinutes(2))); } - public function testDiffInMinutesPositiveAlot() + public function testDiffInMinutesPositiveAlot(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(1502, $dt->diffInMinutes($dt->addHours(25)->addMinutes(2))); } - public function testDiffInMinutesNegativeWithSign() + public function testDiffInMinutesNegativeWithSign(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(-58, $dt->diffInMinutes($dt->subHours(1)->addMinutes(2), false)); } - public function testDiffInMinutesNegativeNoSign() + public function testDiffInMinutesNegativeNoSign(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(58, $dt->diffInMinutes($dt->subHours(1)->addMinutes(2))); } - public function testDiffInMinutesVsDefaultNow() + public function testDiffInMinutesVsDefaultNow(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame(60, Chronos::now()->subHours(1)->diffInMinutes()); }); } - public function testDiffInMinutesEnsureIsTruncated() + public function testDiffInMinutesEnsureIsTruncated(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(1, $dt->diffInMinutes($dt->addMinutes(1)->addSeconds(31))); } - public function testDiffInSecondsPositive() + public function testDiffInSecondsPositive(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(62, $dt->diffInSeconds($dt->addMinutes(1)->addSeconds(2))); } - public function testDiffInSecondsPositiveAlot() + public function testDiffInSecondsPositiveAlot(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(7202, $dt->diffInSeconds($dt->addHours(2)->addSeconds(2))); } - public function testDiffInSecondsNegativeWithSign() + public function testDiffInSecondsNegativeWithSign(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(-58, $dt->diffInSeconds($dt->subMinutes(1)->addSeconds(2), false)); } - public function testDiffInSecondsNegativeNoSign() + public function testDiffInSecondsNegativeNoSign(): void { $dt = Chronos::createFromDate(2000, 1, 1); $this->assertSame(58, $dt->diffInSeconds($dt->subMinutes(1)->addSeconds(2))); } - public function testDiffInSecondsVsDefaultNow() + public function testDiffInSecondsVsDefaultNow(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame(3600, Chronos::now()->subHours(1)->diffInSeconds()); }); } - public function testDiffInSecondsWithTimezones() + public function testDiffInSecondsWithTimezones(): void { $dtOttawa = Chronos::createFromDate(2000, 1, 1, 'America/Toronto'); $dtVancouver = Chronos::createFromDate(2000, 1, 1, 'America/Vancouver'); $this->assertSame(3 * 60 * 60, $dtOttawa->diffInSeconds($dtVancouver)); } - public function testDiffInSecondsWithTimezonesAndVsDefaulessThan() + public function testDiffInSecondsWithTimezonesAndVsDefaulessThan(): void { $vanNow = Chronos::now('America/Vancouver'); $hereNow = $vanNow->setTimezone(Chronos::now()->tz); - $this->wrapWithTestNow(function () use ($vanNow) { + $this->wrapWithTestNow(function () use ($vanNow): void { $this->assertSame(0, $vanNow->diffInSeconds()); }, $hereNow); } @@ -526,7 +527,7 @@ public function testDiffInSecondsWithTimezonesAndVsDefaulessThan() /** * Tests the "from now" time calculation. */ - public function testFromNow() + public function testFromNow(): void { $date = Chronos::now(); $date = $date->modify('-1 year') @@ -537,7 +538,7 @@ public function testFromNow() $this->assertSame($result, '1 0 6 00 0 51'); } - public static function diffForHumansProvider() + public static function diffForHumansProvider(): array { $now = Chronos::parse('2020-01-04 10:01:01'); @@ -588,42 +589,42 @@ public static function diffForHumansProvider() * @return void */ #[DataProvider('diffForHumansProvider')] - public function testDiffForHumansRelative($now, $date, $expected) + public function testDiffForHumansRelative(Chronos $now, Chronos $date, string $expected): void { $this->assertSame($expected, $now->diffForHumans($date)); } - public function testDiffForHumansWithNow() + public function testDiffForHumansWithNow(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame('1 second ago', Chronos::now()->subSeconds(1)->diffForHumans()); $this->assertSame('1 second from now', Chronos::now()->addSeconds(1)->diffForHumans()); }); } - public function testDiffForHumansWithNowAbsolute() + public function testDiffForHumansWithNowAbsolute(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame('1 second', Chronos::now()->subSeconds(1)->diffForHumans(null, true)); $this->assertSame('1 second', Chronos::now()->addSeconds(1)->diffForHumans(null, true)); }); } - public function testDiffForHumansWithoutDiff() + public function testDiffForHumansWithoutDiff(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame('0 seconds ago', Chronos::now()->diffForHumans()); }); } - public function testDiffForHumansWithoutDiffAbsolute() + public function testDiffForHumansWithoutDiffAbsolute(): void { - $this->wrapWithTestNow(function () { + $this->wrapWithTestNow(function (): void { $this->assertSame('0 seconds', Chronos::now()->diffForHumans(null, true)); }); } - public function testDiffFormatterSameObject() + public function testDiffFormatterSameObject(): void { $formatter = Chronos::diffFormatter(); $this->assertInstanceOf('Cake\Chronos\DifferenceFormatter', $formatter); @@ -632,7 +633,7 @@ public function testDiffFormatterSameObject() $this->assertSame($second, $formatter, 'Same object returned on multiple calls'); } - public function testDiffFormatterSetter() + public function testDiffFormatterSetter(): void { $formatter = new DifferenceFormatter(); $result = Chronos::diffFormatter($formatter); diff --git a/tests/TestCase/DateTime/FluidSettersTest.php b/tests/TestCase/DateTime/FluidSettersTest.php index c3aae851..949fa917 100644 --- a/tests/TestCase/DateTime/FluidSettersTest.php +++ b/tests/TestCase/DateTime/FluidSettersTest.php @@ -21,7 +21,7 @@ class FluidSettersTest extends TestCase { - public function testFluidYearSetter() + public function testFluidYearSetter(): void { $d = Chronos::now(); $d = $d->year(1995); @@ -29,7 +29,7 @@ public function testFluidYearSetter() $this->assertSame(1995, $d->year); } - public function testFluidMonthSetter() + public function testFluidMonthSetter(): void { $d = Chronos::now(); $d = $d->month(3); @@ -37,7 +37,7 @@ public function testFluidMonthSetter() $this->assertSame(3, $d->month); } - public function testFluidMonthSetterWithWrap() + public function testFluidMonthSetterWithWrap(): void { $d = Chronos::createFromDate(2012, 8, 21); $d = $d->month(13); @@ -45,7 +45,7 @@ public function testFluidMonthSetterWithWrap() $this->assertSame(1, $d->month); } - public function testFluidDaySetter() + public function testFluidDaySetter(): void { $d = Chronos::now(); $d = $d->day(2); @@ -53,7 +53,7 @@ public function testFluidDaySetter() $this->assertSame(2, $d->day); } - public function testFluidDaySetterWithWrap() + public function testFluidDaySetterWithWrap(): void { $d = Chronos::createFromDate(2000, 1, 1); $d = $d->day(32); @@ -61,7 +61,7 @@ public function testFluidDaySetterWithWrap() $this->assertSame(1, $d->day); } - public function testFluidSetDate() + public function testFluidSetDate(): void { $d = Chronos::createFromDate(2000, 1, 1); $d = $d->setDate(1995, 13, 32); @@ -69,7 +69,7 @@ public function testFluidSetDate() $this->assertDateTime($d, 1996, 2, 1); } - public function testFluidChronosSetISODate() + public function testFluidChronosSetISODate(): void { $d = Chronos::createFromDate(2000, 1, 1); $d = $d->setISODate(2023, 17, 3); @@ -77,7 +77,7 @@ public function testFluidChronosSetISODate() $this->assertDateTime($d, 2023, 04, 26); } - public function testFluidChronosDateSetISODate() + public function testFluidChronosDateSetISODate(): void { $d = ChronosDate::create(2000, 1, 1); $d = $d->setISODate(2023, 17, 3); @@ -85,7 +85,7 @@ public function testFluidChronosDateSetISODate() $this->assertDateTime($d, 2023, 04, 26); } - public function testFluidHourSetter() + public function testFluidHourSetter(): void { $d = Chronos::now(); $d = $d->hour(2); @@ -93,7 +93,7 @@ public function testFluidHourSetter() $this->assertSame(2, $d->hour); } - public function testFluidHourSetterWithWrap() + public function testFluidHourSetterWithWrap(): void { $d = Chronos::now(); $d = $d->hour(25); @@ -101,7 +101,7 @@ public function testFluidHourSetterWithWrap() $this->assertSame(1, $d->hour); } - public function testFluidMinuteSetter() + public function testFluidMinuteSetter(): void { $d = Chronos::now(); $d = $d->minute(2); @@ -109,7 +109,7 @@ public function testFluidMinuteSetter() $this->assertSame(2, $d->minute); } - public function testFluidMinuteSetterWithWrap() + public function testFluidMinuteSetterWithWrap(): void { $d = Chronos::now(); $d = $d->minute(61); @@ -117,7 +117,7 @@ public function testFluidMinuteSetterWithWrap() $this->assertSame(1, $d->minute); } - public function testFluidSecondSetter() + public function testFluidSecondSetter(): void { $d = Chronos::now(); $d = $d->second(2); @@ -125,7 +125,7 @@ public function testFluidSecondSetter() $this->assertSame(2, $d->second); } - public function testFluidSecondSetterWithWrap() + public function testFluidSecondSetterWithWrap(): void { $d = Chronos::now(); $d = $d->second(62); @@ -133,7 +133,7 @@ public function testFluidSecondSetterWithWrap() $this->assertSame(2, $d->second); } - public function testFluidMicroecondSetter() + public function testFluidMicroecondSetter(): void { $d = Chronos::now(); $second = $d->second; @@ -143,7 +143,7 @@ public function testFluidMicroecondSetter() $this->assertSame($second, $d->second); } - public function testFluidSetTime() + public function testFluidSetTime(): void { $d = Chronos::createFromDate(2000, 1, 1); $d = $d->setTime(25, 61, 61); @@ -151,7 +151,7 @@ public function testFluidSetTime() $this->assertDateTime($d, 2000, 1, 2, 2, 2, 1); } - public function testFluidTimestampSetter() + public function testFluidTimestampSetter(): void { $d = Chronos::now(); $d = $d->timestamp(10); diff --git a/tests/TestCase/DateTime/GettersTest.php b/tests/TestCase/DateTime/GettersTest.php index 54a65aa2..474048b4 100644 --- a/tests/TestCase/DateTime/GettersTest.php +++ b/tests/TestCase/DateTime/GettersTest.php @@ -22,100 +22,100 @@ class GettersTest extends TestCase { - public function testGettersThrowExceptionOnUnknownGetter() + public function testGettersThrowExceptionOnUnknownGetter(): void { $this->expectException(InvalidArgumentException::class); Chronos::create(1234, 5, 6, 7, 8, 9)->sdfsdfss; } - public function testYearGetter() + public function testYearGetter(): void { $d = Chronos::create(1234, 5, 6, 7, 8, 9); $this->assertSame(1234, $d->year); } - public function testYearIsoGetter() + public function testYearIsoGetter(): void { $d = Chronos::createFromDate(2012, 12, 31); $this->assertSame(2013, $d->yearIso); } - public function testMonthGetter() + public function testMonthGetter(): void { $d = Chronos::create(1234, 5, 6, 7, 8, 9); $this->assertSame(5, $d->month); } - public function testDayGetter() + public function testDayGetter(): void { $d = Chronos::create(1234, 5, 6, 7, 8, 9); $this->assertSame(6, $d->day); } - public function testHourGetter() + public function testHourGetter(): void { $d = Chronos::create(1234, 5, 6, 7, 8, 9); $this->assertSame(7, $d->hour); } - public function testMinuteGetter() + public function testMinuteGetter(): void { $d = Chronos::create(1234, 5, 6, 7, 8, 9); $this->assertSame(8, $d->minute); } - public function testSecondGetter() + public function testSecondGetter(): void { $d = Chronos::create(1234, 5, 6, 7, 8, 9); $this->assertSame(9, $d->second); } - public function testMicroGetter() + public function testMicroGetter(): void { $micro = 345678; $d = Chronos::parse('2014-01-05 12:34:11.' . $micro); $this->assertSame($micro, $d->micro); } - public function testDayOfWeekGetter() + public function testDayOfWeekGetter(): void { $d = Chronos::create(2012, 5, 7, 7, 8, 9); $this->assertSame(Chronos::MONDAY, $d->dayOfWeek); } - public function testDayOfWeekNameGetter() + public function testDayOfWeekNameGetter(): void { $d = Chronos::create(2012, 5, 7, 7, 8, 9); $this->assertSame('Monday', $d->dayOfWeekName); } - public function testDayOfYearGetter() + public function testDayOfYearGetter(): void { $d = Chronos::createFromDate(2012, 5, 7); $this->assertSame(127, $d->dayOfYear); } - public function testDaysInMonthGetter() + public function testDaysInMonthGetter(): void { $d = Chronos::createFromDate(2012, 5, 7); $this->assertSame(31, $d->daysInMonth); } - public function testTimestampGetter() + public function testTimestampGetter(): void { $d = Chronos::create(); $d = $d->setTimezone('GMT')->setDateTime(1970, 1, 1, 0, 0, 0); $this->assertSame(0, $d->timestamp); } - public function testGetAge() + public function testGetAge(): void { $d = Chronos::now(); $this->assertSame(0, $d->age); } - public function testGetAgeWithRealAge() + public function testGetAgeWithRealAge(): void { $d = Chronos::createFromDate(1975, 5, 21); $age = intval(substr( @@ -127,37 +127,37 @@ public function testGetAgeWithRealAge() $this->assertSame($age, $d->age); } - public function testGetQuarterFirst() + public function testGetQuarterFirst(): void { $d = Chronos::createFromDate(2012, 1, 1); $this->assertSame(1, $d->quarter); } - public function testGetQuarterFirstEnd() + public function testGetQuarterFirstEnd(): void { $d = Chronos::createFromDate(2012, 3, 31); $this->assertSame(1, $d->quarter); } - public function testGetQuarterSecond() + public function testGetQuarterSecond(): void { $d = Chronos::createFromDate(2012, 4, 1); $this->assertSame(2, $d->quarter); } - public function testGetQuarterThird() + public function testGetQuarterThird(): void { $d = Chronos::createFromDate(2012, 7, 1); $this->assertSame(3, $d->quarter); } - public function testGetQuarterFourth() + public function testGetQuarterFourth(): void { $d = Chronos::createFromDate(2012, 10, 1); $this->assertSame(4, $d->quarter); } - public function testGetQuarterFirstLast() + public function testGetQuarterFirstLast(): void { $d = Chronos::createFromDate(2012, 12, 31); $this->assertSame(4, $d->quarter); @@ -181,7 +181,7 @@ public function testHalfOfYear(int $month, int $expectedHalfOfYear): void $this->assertSame($expectedHalfOfYear, $d->half); } - public function testGetLocalTrue() + public function testGetLocalTrue(): void { // Default timezone has been set to America/Toronto in TestCase.php // @see : https://en.wikipedia.org/wiki/List_of_UTC_time_offsets @@ -189,19 +189,19 @@ public function testGetLocalTrue() $this->assertTrue(Chronos::createFromDate(2012, 1, 1, 'America/New_York')->local); } - public function testGetLocalFalse() + public function testGetLocalFalse(): void { $this->assertFalse(Chronos::createFromDate(2012, 7, 1, 'UTC')->local); $this->assertFalse(Chronos::createFromDate(2012, 7, 1, 'Europe/London')->local); } - public function testGetUtcFalse() + public function testGetUtcFalse(): void { $this->assertFalse(Chronos::createFromDate(2013, 1, 1, 'America/Toronto')->utc); $this->assertFalse(Chronos::createFromDate(2013, 1, 1, 'Europe/Paris')->utc); } - public function testGetUtcTrue() + public function testGetUtcTrue(): void { $this->assertTrue(Chronos::createFromDate(2013, 1, 1, 'Atlantic/Reykjavik')->utc); $this->assertTrue(Chronos::createFromDate(2013, 1, 1, 'Europe/Lisbon')->utc); @@ -213,57 +213,57 @@ public function testGetUtcTrue() $this->assertTrue(Chronos::createFromDate(2013, 1, 1, 'GMT')->utc); } - public function testGetDstFalse() + public function testGetDstFalse(): void { $this->assertFalse(Chronos::createFromDate(2012, 1, 1, 'America/Toronto')->dst); } - public function testGetDstTrue() + public function testGetDstTrue(): void { $this->assertTrue(Chronos::createFromDate(2012, 7, 1, 'America/Toronto')->dst); } - public function testOffsetForTorontoWithDST() + public function testOffsetForTorontoWithDST(): void { $this->assertSame(-18000, Chronos::createFromDate(2012, 1, 1, 'America/Toronto')->offset); } - public function testOffsetForTorontoNoDST() + public function testOffsetForTorontoNoDST(): void { $this->assertSame(-14400, Chronos::createFromDate(2012, 6, 1, 'America/Toronto')->offset); } - public function testOffsetForGMT() + public function testOffsetForGMT(): void { $this->assertSame(0, Chronos::createFromDate(2012, 6, 1, 'GMT')->offset); } - public function testOffsetHoursForTorontoWithDST() + public function testOffsetHoursForTorontoWithDST(): void { $this->assertSame(-5, Chronos::createFromDate(2012, 1, 1, 'America/Toronto')->offsetHours); } - public function testOffsetHoursForTorontoNoDST() + public function testOffsetHoursForTorontoNoDST(): void { $this->assertSame(-4, Chronos::createFromDate(2012, 6, 1, 'America/Toronto')->offsetHours); } - public function testOffsetHoursForGMT() + public function testOffsetHoursForGMT(): void { $this->assertSame(0, Chronos::createFromDate(2012, 6, 1, 'GMT')->offsetHours); } - public function testIsLeapYearTrue() + public function testIsLeapYearTrue(): void { $this->assertTrue(Chronos::createFromDate(2012, 1, 1)->isLeapYear()); } - public function testIsLeapYearFalse() + public function testIsLeapYearFalse(): void { $this->assertFalse(Chronos::createFromDate(2011, 1, 1)->isLeapYear()); } - public function testWeekOfMonth() + public function testWeekOfMonth(): void { $this->assertSame(5, Chronos::createFromDate(2012, 9, 30)->weekOfMonth); $this->assertSame(4, Chronos::createFromDate(2012, 9, 28)->weekOfMonth); @@ -272,19 +272,19 @@ public function testWeekOfMonth() $this->assertSame(1, Chronos::createFromDate(2012, 9, 1)->weekOfMonth); } - public function testWeekOfYearFirstWeek() + public function testWeekOfYearFirstWeek(): void { $this->assertSame(52, Chronos::createFromDate(2012, 1, 1)->weekOfYear); $this->assertSame(1, Chronos::createFromDate(2012, 1, 2)->weekOfYear); } - public function testWeekOfYearLastWeek() + public function testWeekOfYearLastWeek(): void { $this->assertSame(52, Chronos::createFromDate(2012, 12, 30)->weekOfYear); $this->assertSame(1, Chronos::createFromDate(2012, 12, 31)->weekOfYear); } - public function testGetWeekStartsAt() + public function testGetWeekStartsAt(): void { $d = Chronos::createFromDate(2012, 12, 31); $this->assertSame(Chronos::MONDAY, $d->getWeekStartsAt()); @@ -293,7 +293,7 @@ public function testGetWeekStartsAt() $this->assertSame(Chronos::SUNDAY, $d->getWeekStartsAt()); } - public function testGetWeekEndsAt() + public function testGetWeekEndsAt(): void { $d = Chronos::createFromDate(2012, 12, 31); $this->assertSame(Chronos::SUNDAY, $d->getWeekEndsAt()); @@ -302,31 +302,31 @@ public function testGetWeekEndsAt() $this->assertSame(Chronos::SATURDAY, $d->getWeekEndsAt()); } - public function testGetTimezone() + public function testGetTimezone(): void { $dt = Chronos::createFromDate(2000, 1, 1, 'America/Toronto'); $this->assertSame('America/Toronto', $dt->timezone->getName()); } - public function testGetTz() + public function testGetTz(): void { $dt = Chronos::createFromDate(2000, 1, 1, 'America/Toronto'); $this->assertSame('America/Toronto', $dt->tz->getName()); } - public function testGetTimezoneName() + public function testGetTimezoneName(): void { $dt = Chronos::createFromDate(2000, 1, 1, 'America/Toronto'); $this->assertSame('America/Toronto', $dt->timezoneName); } - public function testGetTzName() + public function testGetTzName(): void { $dt = Chronos::createFromDate(2000, 1, 1, 'America/Toronto'); $this->assertSame('America/Toronto', $dt->tzName); } - public function testInvalidGetter() + public function testInvalidGetter(): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/TestCase/DateTime/InstanceTest.php b/tests/TestCase/DateTime/InstanceTest.php index 1ebee24c..d50ec8fa 100644 --- a/tests/TestCase/DateTime/InstanceTest.php +++ b/tests/TestCase/DateTime/InstanceTest.php @@ -22,13 +22,13 @@ class InstanceTest extends TestCase { - public function testInstanceFromDateTime() + public function testInstanceFromDateTime(): void { $dating = Chronos::instance(DateTime::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11')); $this->assertDateTime($dating, 1975, 5, 21, 22, 32, 11); } - public function testInstanceFromDateTimeKeepsTimezoneName() + public function testInstanceFromDateTimeKeepsTimezoneName(): void { $dating = Chronos::instance(DateTime::createFromFormat( 'Y-m-d H:i:s', @@ -37,7 +37,7 @@ public function testInstanceFromDateTimeKeepsTimezoneName() $this->assertSame('America/Vancouver', $dating->tzName); } - public function testInstanceFromDateTimeKeepsMicros() + public function testInstanceFromDateTimeKeepsMicros(): void { $micro = 254687; $datetime = DateTime::createFromFormat('Y-m-d H:i:s.u', '2014-02-01 03:45:27.' . $micro); diff --git a/tests/TestCase/DateTime/IsTest.php b/tests/TestCase/DateTime/IsTest.php index 1a521945..e97c38f2 100644 --- a/tests/TestCase/DateTime/IsTest.php +++ b/tests/TestCase/DateTime/IsTest.php @@ -22,87 +22,87 @@ class IsTest extends TestCase { - public function testIsWeekdayTrue() + public function testIsWeekdayTrue(): void { $this->assertTrue(Chronos::createFromDate(2012, 1, 2)->isWeekday()); } - public function testIsWeekdayFalse() + public function testIsWeekdayFalse(): void { $this->assertFalse(Chronos::createFromDate(2012, 1, 1)->isWeekday()); } - public function testIsWeekendTrue() + public function testIsWeekendTrue(): void { $this->assertTrue(Chronos::createFromDate(2012, 1, 1)->isWeekend()); } - public function testIsWeekendFalse() + public function testIsWeekendFalse(): void { $this->assertFalse(Chronos::createFromDate(2012, 1, 2)->isWeekend()); } - public function testIsYesterdayTrue() + public function testIsYesterdayTrue(): void { $this->assertTrue(Chronos::now()->subDays(1)->isYesterday()); } - public function testIsYesterdayFalseWithToday() + public function testIsYesterdayFalseWithToday(): void { $this->assertFalse(Chronos::now()->endOfDay()->isYesterday()); } - public function testIsYesterdayFalseWith2Days() + public function testIsYesterdayFalseWith2Days(): void { $this->assertFalse(Chronos::now()->subDays(2)->startOfDay()->isYesterday()); } - public function testIsTodayTrue() + public function testIsTodayTrue(): void { $this->assertTrue(Chronos::now()->isToday()); } - public function testIsTodayFalseWithYesterday() + public function testIsTodayFalseWithYesterday(): void { $this->assertFalse(Chronos::now()->subDays(1)->endOfDay()->isToday()); } - public function testIsTodayFalseWithTomorrow() + public function testIsTodayFalseWithTomorrow(): void { $this->assertFalse(Chronos::now()->addDays(1)->startOfDay()->isToday()); } - public function testIsTodayWithTimezone() + public function testIsTodayWithTimezone(): void { $this->assertTrue(Chronos::now('Asia/Tokyo')->isToday()); } - public function testIsTomorrowTrue() + public function testIsTomorrowTrue(): void { $this->assertTrue(Chronos::now()->addDays(1)->isTomorrow()); } - public function testIsTomorrowFalseWithToday() + public function testIsTomorrowFalseWithToday(): void { $this->assertFalse(Chronos::now()->endOfDay()->isTomorrow()); } - public function testIsTomorrowFalseWith2Days() + public function testIsTomorrowFalseWith2Days(): void { $this->assertFalse(Chronos::now()->addDays(2)->startOfDay()->isTomorrow()); } - public function testIsNextWeekTrue() + public function testIsNextWeekTrue(): void { $this->assertTrue(Chronos::now()->addWeeks(1)->isNextWeek()); } - public function testIsLastWeekTrue() + public function testIsLastWeekTrue(): void { $this->assertTrue(Chronos::now()->subWeeks(1)->isLastWeek()); } - public function testIsNextWeekFalse() + public function testIsNextWeekFalse(): void { $this->assertFalse(Chronos::now()->addWeeks(2)->isNextWeek()); @@ -111,7 +111,7 @@ public function testIsNextWeekFalse() $this->assertFalse($time->isNextWeek()); } - public function testIsLastWeekFalse() + public function testIsLastWeekFalse(): void { $this->assertFalse(Chronos::now()->subWeeks(2)->isLastWeek()); @@ -120,17 +120,17 @@ public function testIsLastWeekFalse() $this->assertFalse($time->isLastWeek()); } - public function testIsNextMonthTrue() + public function testIsNextMonthTrue(): void { $this->assertTrue(Chronos::now()->addMonths(1)->isNextMonth()); } - public function testIsLastMonthTrue() + public function testIsLastMonthTrue(): void { $this->assertTrue(Chronos::now()->subMonths(1)->isLastMonth()); } - public function testIsNextMonthFalse() + public function testIsNextMonthFalse(): void { $this->assertFalse(Chronos::now()->addMonths(2)->isNextMonth()); @@ -139,7 +139,7 @@ public function testIsNextMonthFalse() $this->assertFalse($time->isNextMonth()); } - public function testIsLastMonthFalse() + public function testIsLastMonthFalse(): void { $this->assertFalse(Chronos::now()->subMonths(2)->isLastMonth()); @@ -148,98 +148,98 @@ public function testIsLastMonthFalse() $this->assertFalse($time->isLastMonth()); } - public function testIsNextYearTrue() + public function testIsNextYearTrue(): void { $this->assertTrue(Chronos::now()->addYears(1)->isNextYear()); } - public function testIsLastYearTrue() + public function testIsLastYearTrue(): void { $this->assertTrue(Chronos::now()->subYears(1)->isLastYear()); } - public function testIsNextYearFalse() + public function testIsNextYearFalse(): void { $this->assertFalse(Chronos::now()->addYears(2)->isNextYear()); } - public function testIsLastYearFalse() + public function testIsLastYearFalse(): void { $this->assertFalse(Chronos::now()->subYears(2)->isLastYear()); } - public function testIsFutureTrue() + public function testIsFutureTrue(): void { $this->assertTrue(Chronos::now()->addSeconds(1)->isFuture()); } - public function testIsFutureFalse() + public function testIsFutureFalse(): void { $this->assertFalse(Chronos::now()->isFuture()); } - public function testIsFutureFalseInThePast() + public function testIsFutureFalseInThePast(): void { $this->assertFalse(Chronos::now()->subSeconds(1)->isFuture()); } - public function testIsPastTrue() + public function testIsPastTrue(): void { $this->assertTrue(Chronos::now()->subSeconds(1)->isPast()); } - public function testIsPastFalse() + public function testIsPastFalse(): void { $this->assertFalse(Chronos::now()->addSeconds(1)->isPast()); } - public function testIsLeapYearTrue() + public function testIsLeapYearTrue(): void { $this->assertTrue(Chronos::createFromDate(2016, 1, 1)->isLeapYear()); } - public function testIsLeapYearFalse() + public function testIsLeapYearFalse(): void { $this->assertFalse(Chronos::createFromDate(2014, 1, 1)->isLeapYear()); } - public function testIsSameDayTrue() + public function testIsSameDayTrue(): void { $current = Chronos::createFromDate(2012, 1, 2); $this->assertTrue($current->isSameDay(Chronos::createFromDate(2012, 1, 2))); } - public function testIsSameDayFalse() + public function testIsSameDayFalse(): void { $current = Chronos::createFromDate(2012, 1, 2); $this->assertFalse($current->isSameDay(Chronos::createFromDate(2012, 1, 3))); } - public function testIsSameMonthTrue() + public function testIsSameMonthTrue(): void { $current = Chronos::createFromDate(2012, 1, 2); $this->assertTrue($current->isSameMonth(Chronos::createFromDate(2012, 1, 3))); } - public function testIsSameMonthFalse() + public function testIsSameMonthFalse(): void { $current = Chronos::createFromDate(2012, 1, 2); $this->assertFalse($current->isSameMonth(Chronos::createFromDate(2013, 1, 2))); } - public function testIsSameYearTrue() + public function testIsSameYearTrue(): void { $current = Chronos::createFromDate(2012, 1, 2); $this->assertTrue($current->isSameYear(Chronos::createFromDate(2012, 3, 2))); } - public function testIsSameYearFalse() + public function testIsSameYearFalse(): void { $current = Chronos::createFromDate(2012, 1, 2); $this->assertFalse($current->isSameYear(Chronos::createFromDate(2013, 1, 2))); } - public function testIsSunday() + public function testIsSunday(): void { // True in the past past $this->assertTrue(Chronos::createFromDate(2015, 5, 31)->isSunday()); @@ -259,7 +259,7 @@ public function testIsSunday() $this->assertFalse(Chronos::now()->addMonths(1)->previous(Chronos::MONDAY)->isSunday()); } - public function testIsMonday() + public function testIsMonday(): void { // True in the past past $this->assertTrue(Chronos::createFromDate(2015, 6, 1)->isMonday()); @@ -278,7 +278,7 @@ public function testIsMonday() $this->assertFalse(Chronos::now()->addMonths(1)->previous(Chronos::TUESDAY)->isMonday()); } - public function testIsTuesday() + public function testIsTuesday(): void { // True in the past past $this->assertTrue(Chronos::createFromDate(2015, 6, 2)->isTuesday()); @@ -297,7 +297,7 @@ public function testIsTuesday() $this->assertFalse(Chronos::now()->addMonths(1)->previous(Chronos::WEDNESDAY)->isTuesday()); } - public function testIsWednesday() + public function testIsWednesday(): void { // True in the past past $this->assertTrue(Chronos::createFromDate(2015, 6, 3)->isWednesday()); @@ -316,7 +316,7 @@ public function testIsWednesday() $this->assertFalse(Chronos::now()->addMonths(1)->previous(Chronos::THURSDAY)->isWednesday()); } - public function testIsThursday() + public function testIsThursday(): void { // True in the past past $this->assertTrue(Chronos::createFromDate(2015, 6, 4)->isThursday()); @@ -335,7 +335,7 @@ public function testIsThursday() $this->assertFalse(Chronos::now()->addMonths(1)->previous(Chronos::FRIDAY)->isThursday()); } - public function testIsFriday() + public function testIsFriday(): void { // True in the past past $this->assertTrue(Chronos::createFromDate(2015, 6, 5)->isFriday()); @@ -354,7 +354,7 @@ public function testIsFriday() $this->assertFalse(Chronos::now()->addMonths(1)->previous(Chronos::SATURDAY)->isFriday()); } - public function testIsSaturday() + public function testIsSaturday(): void { // True in the past past $this->assertTrue(Chronos::createFromDate(2015, 6, 6)->isSaturday()); @@ -373,7 +373,7 @@ public function testIsSaturday() $this->assertFalse(Chronos::now()->addMonths(1)->previous(Chronos::SUNDAY)->isSaturday()); } - public function testIsThisWeek() + public function testIsThisWeek(): void { $time = new Chronos('this sunday'); $this->assertTrue($time->isThisWeek()); @@ -389,7 +389,7 @@ public function testIsThisWeek() $this->assertFalse($time->isThisWeek()); } - public function testIsThisMonth() + public function testIsThisMonth(): void { $time = new Chronos(); $this->assertTrue($time->isThisMonth()); @@ -401,7 +401,7 @@ public function testIsThisMonth() $this->assertFalse($time->modify('next month')->isThisMonth()); } - public function testIsThisYear() + public function testIsThisYear(): void { $time = new Chronos(); $this->assertTrue($time->isThisYear()); @@ -410,7 +410,7 @@ public function testIsThisYear() $this->assertFalse($time->isThisYear()); } - public function testWasWithinLast() + public function testWasWithinLast(): void { $this->assertTrue((new Chronos('-1 day'))->wasWithinLast('1 day')); $this->assertTrue((new Chronos('-1 week'))->wasWithinLast('1 week')); @@ -426,7 +426,7 @@ public function testWasWithinLast() $this->assertFalse((new Chronos('-1 weeks'))->wasWithinLast('1 day')); } - public function testIsWithinNext() + public function testIsWithinNext(): void { $this->assertFalse((new Chronos('-1 day'))->isWithinNext('1 day')); $this->assertFalse((new Chronos('-1 week'))->isWithinNext('1 week')); diff --git a/tests/TestCase/DateTime/IssetTest.php b/tests/TestCase/DateTime/IssetTest.php index 3ce6744e..49d967a5 100644 --- a/tests/TestCase/DateTime/IssetTest.php +++ b/tests/TestCase/DateTime/IssetTest.php @@ -20,12 +20,12 @@ class IssetTest extends TestCase { - public function testIssetReturnFalseForUnknownProperty() + public function testIssetReturnFalseForUnknownProperty(): void { $this->assertFalse(isset(Chronos::create(1234, 5, 6, 7, 8, 9)->sdfsdfss)); } - public function testIssetReturnTrueForProperties() + public function testIssetReturnTrueForProperties(): void { $properties = [ 'year', diff --git a/tests/TestCase/DateTime/NowAndOtherStaticHelpersTest.php b/tests/TestCase/DateTime/NowAndOtherStaticHelpersTest.php index 5976b396..ec88d04d 100644 --- a/tests/TestCase/DateTime/NowAndOtherStaticHelpersTest.php +++ b/tests/TestCase/DateTime/NowAndOtherStaticHelpersTest.php @@ -22,66 +22,66 @@ class NowAndOtherStaticHelpersTest extends TestCase { - public function testNow() + public function testNow(): void { $dt = Chronos::now(); $this->assertSame(time(), $dt->timestamp); } - public function testNowWithTimezone() + public function testNowWithTimezone(): void { $dt = Chronos::now('Europe/London'); $this->assertSame(time(), $dt->timestamp); $this->assertSame('Europe/London', $dt->tzName); } - public function testToday() + public function testToday(): void { $dt = Chronos::today(); $this->assertSame(date('Y-m-d 00:00:00'), $dt->toDateTimeString()); } - public function testTodayWithTimezone() + public function testTodayWithTimezone(): void { $dt = Chronos::today('Europe/London'); $dt2 = new DateTime('now', new DateTimeZone('Europe/London')); $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString()); } - public function testTomorrow() + public function testTomorrow(): void { $dt = Chronos::tomorrow(); $dt2 = new DateTime('tomorrow'); $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString()); } - public function testTomorrowWithTimezone() + public function testTomorrowWithTimezone(): void { $dt = Chronos::tomorrow('Europe/London'); $dt2 = new DateTime('tomorrow', new DateTimeZone('Europe/London')); $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString()); } - public function testYesterday() + public function testYesterday(): void { $dt = Chronos::yesterday(); $dt2 = new DateTime('yesterday'); $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString()); } - public function testYesterdayWithTimezone() + public function testYesterdayWithTimezone(): void { $dt = Chronos::yesterday('Europe/London'); $dt2 = new DateTime('yesterday', new DateTimeZone('Europe/London')); $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString()); } - public function testMinValue() + public function testMinValue(): void { $this->assertLessThanOrEqual(-2147483647, Chronos::minValue()->getTimestamp()); } - public function testMinValueNonUtcTimezone() + public function testMinValueNonUtcTimezone(): void { date_default_timezone_set('Europe/Amsterdam'); @@ -89,12 +89,12 @@ public function testMinValueNonUtcTimezone() $this->assertTrue(Chronos::now()->greaterThan(Chronos::minValue())); } - public function testMaxValue() + public function testMaxValue(): void { $this->assertGreaterThanOrEqual(2147483647, Chronos::maxValue()->getTimestamp()); } - public function testMaxValueNonUtcTimezone() + public function testMaxValueNonUtcTimezone(): void { date_default_timezone_set('Europe/Amsterdam'); diff --git a/tests/TestCase/DateTime/PhpBug72338Test.php b/tests/TestCase/DateTime/PhpBug72338Test.php index 5d2ccfa1..388f17f3 100644 --- a/tests/TestCase/DateTime/PhpBug72338Test.php +++ b/tests/TestCase/DateTime/PhpBug72338Test.php @@ -23,7 +23,7 @@ class PhpBug72338Test extends TestCase /** * Ensures that $date->format('U') returns unchanged timestamp */ - public function testTimestamp() + public function testTimestamp(): void { $date = Chronos::createFromTimestamp(0)->setTimezone('+02:00'); $this->assertSame('0', $date->format('U')); @@ -32,7 +32,7 @@ public function testTimestamp() /** * Ensures that date created from string with timezone and with same timezone set by setTimezone() is equal */ - public function testEqualSetAndCreate() + public function testEqualSetAndCreate(): void { $date = Chronos::createFromTimestamp(0)->setTimezone('+02:00'); $date1 = new Chronos('1970-01-01T02:00:00+02:00'); @@ -42,7 +42,7 @@ public function testEqualSetAndCreate() /** * Ensures that second call to setTimezone() dont changing timestamp */ - public function testSecondSetTimezone() + public function testSecondSetTimezone(): void { $date = Chronos::createFromTimestamp(0)->setTimezone('+02:00')->setTimezone('Europe/Moscow'); $this->assertSame('0', $date->format('U')); diff --git a/tests/TestCase/DateTime/RelativeTest.php b/tests/TestCase/DateTime/RelativeTest.php index 47d9d158..fdf6e734 100644 --- a/tests/TestCase/DateTime/RelativeTest.php +++ b/tests/TestCase/DateTime/RelativeTest.php @@ -20,7 +20,7 @@ class RelativeTest extends TestCase { - public function testSecondsSinceMidnight() + public function testSecondsSinceMidnight(): void { $d = Chronos::today()->addSeconds(30); $this->assertSame(30, $d->secondsSinceMidnight()); @@ -35,7 +35,7 @@ public function testSecondsSinceMidnight() $this->assertSame(42, $d->secondsSinceMidnight()); } - public function testSecondsUntilEndOfDay() + public function testSecondsUntilEndOfDay(): void { $d = Chronos::today()->endOfDay(); $this->assertSame(0, $d->secondsUntilEndOfDay()); diff --git a/tests/TestCase/DateTime/StartEndOfTest.php b/tests/TestCase/DateTime/StartEndOfTest.php index c67caa3b..c99324df 100644 --- a/tests/TestCase/DateTime/StartEndOfTest.php +++ b/tests/TestCase/DateTime/StartEndOfTest.php @@ -20,7 +20,7 @@ class StartEndOfTest extends TestCase { - public function testStartOfDay() + public function testStartOfDay(): void { $now = Chronos::now(); $dt = $now->startOfDay(); @@ -28,7 +28,7 @@ public function testStartOfDay() $this->assertDateTime($dt, $dt->year, $dt->month, $dt->day, 0, 0, 0); } - public function testEndOfDay() + public function testEndOfDay(): void { $now = Chronos::now(); $dt = $now->endOfDay(); @@ -40,217 +40,217 @@ public function testEndOfDay() $this->assertDateTime($dt, $dt->year, $dt->month, $dt->day, 23, 59, 59, 999999); } - public function testStartOfMonthIsFluid() + public function testStartOfMonthIsFluid(): void { $now = Chronos::now(); $dt = $now->startOfMonth(); $this->assertTrue($dt instanceof Chronos); } - public function testStartOfMonthFromNow() + public function testStartOfMonthFromNow(): void { $dt = Chronos::now()->startOfMonth(); $this->assertDateTime($dt, $dt->year, $dt->month, 1, 0, 0, 0); } - public function testStartOfMonthFromLastDay() + public function testStartOfMonthFromLastDay(): void { $dt = Chronos::create(2000, 1, 31, 2, 3, 4)->startOfMonth(); $this->assertDateTime($dt, 2000, 1, 1, 0, 0, 0); } - public function testStartOfYearIsFluid() + public function testStartOfYearIsFluid(): void { $now = Chronos::now(); $dt = $now->startOfYear(); $this->assertTrue($dt instanceof Chronos); } - public function testStartOfYearFromNow() + public function testStartOfYearFromNow(): void { $dt = Chronos::now()->startOfYear(); $this->assertDateTime($dt, $dt->year, 1, 1, 0, 0, 0); } - public function testStartOfYearFromFirstDay() + public function testStartOfYearFromFirstDay(): void { $dt = Chronos::create(2000, 1, 1, 1, 1, 1)->startOfYear(); $this->assertDateTime($dt, 2000, 1, 1, 0, 0, 0); } - public function testStartOfYearFromLastDay() + public function testStartOfYearFromLastDay(): void { $dt = Chronos::create(2000, 12, 31, 23, 59, 59)->startOfYear(); $this->assertDateTime($dt, 2000, 1, 1, 0, 0, 0); } - public function testEndOfMonthIsFluid() + public function testEndOfMonthIsFluid(): void { $now = Chronos::now(); $dt = $now->endOfMonth(); $this->assertTrue($dt instanceof Chronos); } - public function testEndOfMonth() + public function testEndOfMonth(): void { $dt = Chronos::create(2000, 1, 1, 2, 3, 4)->endOfMonth(); $this->assertDateTime($dt, 2000, 1, 31, 23, 59, 59); } - public function testEndOfMonthFromLastDay() + public function testEndOfMonthFromLastDay(): void { $dt = Chronos::create(2000, 1, 31, 2, 3, 4)->endOfMonth(); $this->assertDateTime($dt, 2000, 1, 31, 23, 59, 59); } - public function testEndOfYearIsFluid() + public function testEndOfYearIsFluid(): void { $now = Chronos::now(); $dt = $now->endOfYear(); $this->assertTrue($dt instanceof Chronos); } - public function testEndOfYearFromNow() + public function testEndOfYearFromNow(): void { $dt = Chronos::now()->endOfYear(); $this->assertDateTime($dt, $dt->year, 12, 31, 23, 59, 59); } - public function testEndOfYearFromFirstDay() + public function testEndOfYearFromFirstDay(): void { $dt = Chronos::create(2000, 1, 1, 1, 1, 1)->endOfYear(); $this->assertDateTime($dt, 2000, 12, 31, 23, 59, 59); } - public function testEndOfYearFromLastDay() + public function testEndOfYearFromLastDay(): void { $dt = Chronos::create(2000, 12, 31, 23, 59, 59)->endOfYear(); $this->assertDateTime($dt, 2000, 12, 31, 23, 59, 59); } - public function testStartOfDecadeIsFluid() + public function testStartOfDecadeIsFluid(): void { $now = Chronos::now(); $dt = $now->startOfDecade(); $this->assertTrue($dt instanceof Chronos); } - public function testStartOfDecadeFromNow() + public function testStartOfDecadeFromNow(): void { $dt = Chronos::now()->startOfDecade(); $this->assertDateTime($dt, $dt->year - $dt->year % 10, 1, 1, 0, 0, 0); } - public function testStartOfDecadeFromFirstDay() + public function testStartOfDecadeFromFirstDay(): void { $dt = Chronos::create(2000, 1, 1, 1, 1, 1)->startOfDecade(); $this->assertDateTime($dt, 2000, 1, 1, 0, 0, 0); } - public function testStartOfDecadeFromLastDay() + public function testStartOfDecadeFromLastDay(): void { $dt = Chronos::create(2009, 12, 31, 23, 59, 59)->startOfDecade(); $this->assertDateTime($dt, 2000, 1, 1, 0, 0, 0); } - public function testEndOfDecadeIsFluid() + public function testEndOfDecadeIsFluid(): void { $now = Chronos::now(); $dt = $now->endOfDecade(); $this->assertTrue($dt instanceof Chronos); } - public function testEndOfDecadeFromNow() + public function testEndOfDecadeFromNow(): void { $dt = Chronos::now()->endOfDecade(); $this->assertDateTime($dt, $dt->year - $dt->year % 10 + 9, 12, 31, 23, 59, 59); } - public function testEndOfDecadeFromFirstDay() + public function testEndOfDecadeFromFirstDay(): void { $dt = Chronos::create(2000, 1, 1, 1, 1, 1)->endOfDecade(); $this->assertDateTime($dt, 2009, 12, 31, 23, 59, 59); } - public function testEndOfDecadeFromLastDay() + public function testEndOfDecadeFromLastDay(): void { $dt = Chronos::create(2009, 12, 31, 23, 59, 59)->endOfDecade(); $this->assertDateTime($dt, 2009, 12, 31, 23, 59, 59); } - public function testStartOfCenturyIsFluid() + public function testStartOfCenturyIsFluid(): void { $now = Chronos::now(); $dt = $now->startOfCentury(); $this->assertTrue($dt instanceof Chronos); } - public function testStartOfCenturyFromNow() + public function testStartOfCenturyFromNow(): void { $now = Chronos::now(); $dt = Chronos::now()->startOfCentury(); $this->assertDateTime($dt, $now->year - $now->year % 100 + 1, 1, 1, 0, 0, 0); } - public function testStartOfCenturyFromFirstDay() + public function testStartOfCenturyFromFirstDay(): void { $dt = Chronos::create(2001, 1, 1, 1, 1, 1)->startOfCentury(); $this->assertDateTime($dt, 2001, 1, 1, 0, 0, 0); } - public function testStartOfCenturyFromLastDay() + public function testStartOfCenturyFromLastDay(): void { $dt = Chronos::create(2100, 12, 31, 23, 59, 59)->startOfCentury(); $this->assertDateTime($dt, 2001, 1, 1, 0, 0, 0); } - public function testEndOfCenturyIsFluid() + public function testEndOfCenturyIsFluid(): void { $now = Chronos::now(); $dt = $now->endOfCentury(); $this->assertTrue($dt instanceof Chronos); } - public function testEndOfCenturyFromNow() + public function testEndOfCenturyFromNow(): void { $now = Chronos::now(); $dt = Chronos::now()->endOfCentury(); $this->assertDateTime($dt, $now->year - $now->year % 100 + 100, 12, 31, 23, 59, 59); } - public function testEndOfCenturyFromFirstDay() + public function testEndOfCenturyFromFirstDay(): void { $dt = Chronos::create(2001, 1, 1, 1, 1, 1)->endOfCentury(); $this->assertDateTime($dt, 2100, 12, 31, 23, 59, 59); } - public function testEndOfCenturyFromLastDay() + public function testEndOfCenturyFromLastDay(): void { $dt = Chronos::create(2100, 12, 31, 23, 59, 59)->endOfCentury(); $this->assertDateTime($dt, 2100, 12, 31, 23, 59, 59); } - public function testAverageIsFluid() + public function testAverageIsFluid(): void { $dt = Chronos::now()->average(); $this->assertTrue($dt instanceof Chronos); } - public function testAverageFromSame() + public function testAverageFromSame(): void { $dt1 = Chronos::create(2000, 1, 31, 2, 3, 4); $dt2 = Chronos::create(2000, 1, 31, 2, 3, 4)->average($dt1); $this->assertDateTime($dt2, 2000, 1, 31, 2, 3, 4); } - public function testAverageFromGreater() + public function testAverageFromGreater(): void { $dt1 = Chronos::create(2000, 1, 1, 1, 1, 1); $dt2 = Chronos::create(2009, 12, 31, 23, 59, 59)->average($dt1); $this->assertDateTime($dt2, 2004, 12, 31, 12, 30, 30); } - public function testAverageFromLower() + public function testAverageFromLower(): void { $dt1 = Chronos::create(2009, 12, 31, 23, 59, 59); $dt2 = Chronos::create(2000, 1, 1, 1, 1, 1)->average($dt1); diff --git a/tests/TestCase/DateTime/StringsTest.php b/tests/TestCase/DateTime/StringsTest.php index 9e245fe6..31227584 100644 --- a/tests/TestCase/DateTime/StringsTest.php +++ b/tests/TestCase/DateTime/StringsTest.php @@ -22,20 +22,20 @@ class StringsTest extends TestCase { - public function testToString() + public function testToString(): void { $d = Chronos::now(); $this->assertSame(Chronos::now()->toDateTimeString(), '' . $d); } - public function testSetToStringFormat() + public function testSetToStringFormat(): void { Chronos::setToStringFormat('jS \o\f F, Y g:i:s a'); $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('25th of December, 1975 2:15:16 pm', '' . $d); } - public function testResetToStringFormat() + public function testResetToStringFormat(): void { $d = Chronos::now(); Chronos::setToStringFormat('123'); @@ -43,49 +43,49 @@ public function testResetToStringFormat() $this->assertSame($d->toDateTimeString(), '' . $d); } - public function testToDateString() + public function testToDateString(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('1975-12-25', $d->toDateString()); } - public function testToFormattedDateString() + public function testToFormattedDateString(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('Dec 25, 1975', $d->toFormattedDateString()); } - public function testToTimeString() + public function testToTimeString(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('14:15:16', $d->toTimeString()); } - public function testToDateTimeString() + public function testToDateTimeString(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('1975-12-25 14:15:16', $d->toDateTimeString()); } - public function testToDateTimeStringWithPaddedZeroes() + public function testToDateTimeStringWithPaddedZeroes(): void { $d = Chronos::create(2000, 5, 2, 4, 3, 4); $this->assertSame('2000-05-02 04:03:04', $d->toDateTimeString()); } - public function testToDayDateTimeString() + public function testToDayDateTimeString(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('Thu, Dec 25, 1975 2:15 PM', $d->toDayDateTimeString()); } - public function testToAtomString() + public function testToAtomString(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('1975-12-25T14:15:16-05:00', $d->toAtomString()); } - public function testToCOOKIEString() + public function testToCOOKIEString(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); if (DateTime::COOKIE === 'l, d-M-y H:i:s T') { @@ -97,61 +97,61 @@ public function testToCOOKIEString() $this->assertSame($cookieString, $d->toCOOKIEString()); } - public function testToIso8601String() + public function testToIso8601String(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('1975-12-25T14:15:16-05:00', $d->toIso8601String()); } - public function testToRC822String() + public function testToRC822String(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('Thu, 25 Dec 75 14:15:16 -0500', $d->toRfc822String()); } - public function testToRfc850String() + public function testToRfc850String(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('Thursday, 25-Dec-75 14:15:16 EST', $d->toRfc850String()); } - public function testToRfc1036String() + public function testToRfc1036String(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('Thu, 25 Dec 75 14:15:16 -0500', $d->toRfc1036String()); } - public function testToRfc1123String() + public function testToRfc1123String(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('Thu, 25 Dec 1975 14:15:16 -0500', $d->toRfc1123String()); } - public function testToRfc2822String() + public function testToRfc2822String(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('Thu, 25 Dec 1975 14:15:16 -0500', $d->toRfc2822String()); } - public function testToRfc3339String() + public function testToRfc3339String(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('1975-12-25T14:15:16-05:00', $d->toRfc3339String()); } - public function testToRssString() + public function testToRssString(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('Thu, 25 Dec 1975 14:15:16 -0500', $d->toRssString()); } - public function testToW3cString() + public function testToW3cString(): void { $d = Chronos::create(1975, 12, 25, 14, 15, 16); $this->assertSame('1975-12-25T14:15:16-05:00', $d->toW3cString()); } - public function testToUnixString() + public function testToUnixString(): void { $time = Chronos::parse('2014-04-20 08:00:00'); $this->assertSame('1397995200', $time->toUnixString()); @@ -160,7 +160,7 @@ public function testToUnixString() $this->assertSame('1639224001', $time->toUnixString()); } - public function testToRfc7231String() + public function testToRfc7231String(): void { $time = Chronos::parse('2014-04-20 08:00:00', 'America/Toronto'); $this->assertSame('Sun, 20 Apr 2014 12:00:00 GMT', $time->toRfc7231String()); @@ -171,7 +171,7 @@ public function testToRfc7231String() * * @return array */ - public static function toQuarterProvider() + public static function toQuarterProvider(): array { return [ ['2007-12-25', 4], @@ -186,12 +186,12 @@ public static function toQuarterProvider() * @return void */ #[DataProvider('toQuarterProvider')] - public function testToQuarter($date, $expected, $range = false) + public function testToQuarter(string $date, int $expected, $range = false): void { $this->assertSame($expected, (new Chronos($date))->toQuarter()); } - public static function toQuarterRangeProvider() + public static function toQuarterRangeProvider(): array { return [ ['2007-3-25', ['2007-01-01', '2007-03-31']], @@ -202,10 +202,10 @@ public static function toQuarterRangeProvider() } #[DataProvider('toQuarterRangeProvider')] - public function testToQuarterRange($date, $expected) + public function testToQuarterRange(string $date, array $expected): void { $this->assertSame($expected, (new Chronos($date))->toQuarterRange()); - $this->deprecated(function () use ($date, $expected) { + $this->deprecated(function () use ($date, $expected): void { $this->assertSame($expected, (new Chronos($date))->toQuarter(true)); }); } @@ -215,7 +215,7 @@ public function testToQuarterRange($date, $expected) * * @return array */ - public static function toWeekProvider() + public static function toWeekProvider(): array { return [ ['2007-1-1', 1], @@ -231,7 +231,7 @@ public static function toWeekProvider() * @return void */ #[DataProvider('toWeekProvider')] - public function testToWeek($date, $expected) + public function testToWeek(string $date, int $expected): void { $this->assertSame($expected, (new Chronos($date))->toWeek()); } diff --git a/tests/TestCase/DateTime/SubTest.php b/tests/TestCase/DateTime/SubTest.php index e8228186..d8ba17a4 100644 --- a/tests/TestCase/DateTime/SubTest.php +++ b/tests/TestCase/DateTime/SubTest.php @@ -20,88 +20,88 @@ class SubTest extends TestCase { - public function testSubYearsPositive() + public function testSubYearsPositive(): void { $this->assertSame(1974, Chronos::createFromDate(1975)->subYears(1)->year); } - public function testSubYearsZero() + public function testSubYearsZero(): void { $this->assertSame(1975, Chronos::createFromDate(1975)->subYears(0)->year); } - public function testSubYearsNegative() + public function testSubYearsNegative(): void { $this->assertSame(1976, Chronos::createFromDate(1975)->subYears(-1)->year); } - public function testSubYearNoOverflowPassingArg() + public function testSubYearNoOverflowPassingArg(): void { $dt = Chronos::createFromDate(2013, 2, 28)->subYears(1); $this->assertSame(2, $dt->month); $this->assertSame(28, $dt->day); } - public function testSubYearsWithOverflowPassingArg() + public function testSubYearsWithOverflowPassingArg(): void { $dt = Chronos::createFromDate(2014, 2, 29)->subYearsWithOverflow(2); $this->assertSame(2, $dt->month); $this->assertSame(28, $dt->day); } - public function testSubYearWithOverflowPassingArg() + public function testSubYearWithOverflowPassingArg(): void { $dt = Chronos::createFromDate(2013, 2, 28)->subYearsWithOverflow(1); $this->assertSame(2, $dt->month); $this->assertSame(28, $dt->day); } - public function testSubMonthsPositive() + public function testSubMonthsPositive(): void { $this->assertSame(12, Chronos::createFromDate(1975, 1, 1)->subMonths(1)->month); } - public function testSubMonthsZero() + public function testSubMonthsZero(): void { $this->assertSame(1, Chronos::createFromDate(1975, 1, 1)->subMonths(0)->month); } - public function testSubMonthsNegative() + public function testSubMonthsNegative(): void { $this->assertSame(2, Chronos::createFromDate(1975, 1, 1)->subMonths(-1)->month); } - public function testSubMonth() + public function testSubMonth(): void { $this->assertSame(12, Chronos::createFromDate(1975, 1, 1)->subMonths(1)->month); } - public function testSubDaysPositive() + public function testSubDaysPositive(): void { $this->assertSame(30, Chronos::createFromDate(1975, 5, 1)->subDays(1)->day); } - public function testSubDaysZero() + public function testSubDaysZero(): void { $this->assertSame(1, Chronos::createFromDate(1975, 5, 1)->subDays(0)->day); } - public function testSubDaysNegative() + public function testSubDaysNegative(): void { $this->assertSame(2, Chronos::createFromDate(1975, 5, 1)->subDays(-1)->day); } - public function testSubDay() + public function testSubDay(): void { $this->assertSame(30, Chronos::createFromDate(1975, 5, 1)->subDays(1)->day); } - public function testSubWeekdayDuringWeekend() + public function testSubWeekdayDuringWeekend(): void { $this->assertSame(6, Chronos::createFromDate(2012, 1, 8)->subWeekdays(1)->day); } - public function testSubWeekdaysPositive() + public function testSubWeekdaysPositive(): void { $dt = Chronos::create(2012, 1, 4, 13, 2, 1)->subWeekdays(9); $this->assertSame(22, $dt->day); @@ -112,150 +112,150 @@ public function testSubWeekdaysPositive() $this->assertSame(1, $dt->second); } - public function testSubWeekdaysZero() + public function testSubWeekdaysZero(): void { $this->assertSame(4, Chronos::createFromDate(2012, 1, 4)->subWeekdays(0)->day); } - public function testSubWeekdaysNegative() + public function testSubWeekdaysNegative(): void { $this->assertSame(13, Chronos::createFromDate(2012, 1, 31)->subWeekdays(-9)->day); } - public function testSubWeekday() + public function testSubWeekday(): void { $this->assertSame(6, Chronos::createFromDate(2012, 1, 9)->subWeekdays(1)->day); } - public function testSubWeeksPositive() + public function testSubWeeksPositive(): void { $this->assertSame(14, Chronos::createFromDate(1975, 5, 21)->subWeeks(1)->day); } - public function testSubWeeksZero() + public function testSubWeeksZero(): void { $this->assertSame(21, Chronos::createFromDate(1975, 5, 21)->subWeeks(0)->day); } - public function testSubWeeksNegative() + public function testSubWeeksNegative(): void { $this->assertSame(28, Chronos::createFromDate(1975, 5, 21)->subWeeks(-1)->day); } - public function testSubWeek() + public function testSubWeek(): void { $this->assertSame(14, Chronos::createFromDate(1975, 5, 21)->subWeeks(1)->day); } - public function testSubHoursPositive() + public function testSubHoursPositive(): void { $this->assertSame(23, Chronos::createFromTime(0)->subHours(1)->hour); } - public function testSubHoursZero() + public function testSubHoursZero(): void { $this->assertSame(0, Chronos::createFromTime(0)->subHours(0)->hour); } - public function testSubHoursNegative() + public function testSubHoursNegative(): void { $this->assertSame(1, Chronos::createFromTime(0)->subHours(-1)->hour); } - public function testSubHour() + public function testSubHour(): void { $this->assertSame(23, Chronos::createFromTime(0)->subHours(1)->hour); } - public function testSubMinutesPositive() + public function testSubMinutesPositive(): void { $this->assertSame(59, Chronos::createFromTime(0, 0)->subMinutes(1)->minute); } - public function testSubMinutesZero() + public function testSubMinutesZero(): void { $this->assertSame(0, Chronos::createFromTime(0, 0)->subMinutes(0)->minute); } - public function testSubMinutesNegative() + public function testSubMinutesNegative(): void { $this->assertSame(1, Chronos::createFromTime(0, 0)->subMinutes(-1)->minute); } - public function testSubMinute() + public function testSubMinute(): void { $this->assertSame(59, Chronos::createFromTime(0, 0)->subMinutes(1)->minute); } - public function testSubSecondsPositive() + public function testSubSecondsPositive(): void { $this->assertSame(59, Chronos::createFromTime(0, 0, 0)->subSeconds(1)->second); } - public function testSubSecondsZero() + public function testSubSecondsZero(): void { $this->assertSame(0, Chronos::createFromTime(0, 0, 0)->subSeconds(0)->second); } - public function testSubSecondsNegative() + public function testSubSecondsNegative(): void { $this->assertSame(1, Chronos::createFromTime(0, 0, 0)->subSeconds(-1)->second); } - public function testSubSecond() + public function testSubSecond(): void { $this->assertSame(59, Chronos::createFromTime(0, 0, 0)->subSeconds(1)->second); } /***** Test non plural methods with non default args *****/ - public function testSubYearPassingArg() + public function testSubYearPassingArg(): void { $this->assertSame(1973, Chronos::createFromDate(1975)->subYears(2)->year); } - public function testSubMonthPassingArg() + public function testSubMonthPassingArg(): void { $this->assertSame(3, Chronos::createFromDate(1975, 5, 1)->subMonths(2)->month); } - public function testSubMonthNoOverflowPassingArg() + public function testSubMonthNoOverflowPassingArg(): void { $dt = Chronos::createFromDate(2011, 4, 30)->subMonths(2); $this->assertSame(2, $dt->month); $this->assertSame(28, $dt->day); } - public function testSubMonthsWithOverflowPassingArg() + public function testSubMonthsWithOverflowPassingArg(): void { $dt = Chronos::createFromDate(2011, 4, 30)->subMonthsWithOverflow(2); $this->assertSame(3, $dt->month); $this->assertSame(2, $dt->day); } - public function testSubMonthWithOverflowPassingArg() + public function testSubMonthWithOverflowPassingArg(): void { $dt = Chronos::createFromDate(2011, 3, 30)->subMonthsWithOverflow(1); $this->assertSame(3, $dt->month); $this->assertSame(2, $dt->day); } - public function testSubDayPassingArg() + public function testSubDayPassingArg(): void { $this->assertSame(8, Chronos::createFromDate(1975, 5, 10)->subDays(2)->day); } - public function testSubHourPassingArg() + public function testSubHourPassingArg(): void { $this->assertSame(22, Chronos::createFromTime(0)->subHours(2)->hour); } - public function testSubMinutePassingArg() + public function testSubMinutePassingArg(): void { $this->assertSame(58, Chronos::createFromTime(0)->subMinutes(2)->minute); } - public function testSubSecondPassingArg() + public function testSubSecondPassingArg(): void { $this->assertSame(58, Chronos::createFromTime(0)->subSeconds(2)->second); } diff --git a/tests/TestCase/DateTime/TestingAidsTest.php b/tests/TestCase/DateTime/TestingAidsTest.php index 4775b3c1..2cd2cb4c 100644 --- a/tests/TestCase/DateTime/TestingAidsTest.php +++ b/tests/TestCase/DateTime/TestingAidsTest.php @@ -23,7 +23,7 @@ class TestingAidsTest extends TestCase { - public function testTestingAidsWithTestNowNotSet() + public function testTestingAidsWithTestNowNotSet(): void { Chronos::setTestNow(); @@ -31,7 +31,7 @@ public function testTestingAidsWithTestNowNotSet() $this->assertNull(Chronos::getTestNow()); } - public function testTestingAidsWithTestNowSet() + public function testTestingAidsWithTestNowSet(): void { $notNow = Chronos::yesterday(); Chronos::setTestNow($notNow); @@ -40,14 +40,14 @@ public function testTestingAidsWithTestNowSet() $this->assertSame($notNow, Chronos::getTestNow()); } - public function testTestingAidsWithTestNowSetToString() + public function testTestingAidsWithTestNowSetToString(): void { Chronos::setTestNow('2016-11-23'); $this->assertTrue(Chronos::hasTestNow()); $this->assertSame((string)Chronos::getTestNow(), (string)Chronos::parse('2016-11-23')); } - public function testConstructorWithTestValueSet() + public function testConstructorWithTestValueSet(): void { $notNow = Chronos::yesterday(); Chronos::setTestNow($notNow); @@ -58,7 +58,7 @@ public function testConstructorWithTestValueSet() $this->assertSame((string)$notNow, (string)new Chronos('now')); } - public function testNowWithTestValueSet() + public function testNowWithTestValueSet(): void { $notNow = Chronos::yesterday(); Chronos::setTestNow($notNow); @@ -69,7 +69,7 @@ public function testNowWithTestValueSet() /** * Ensure that using test now doesn't mutate test now. */ - public function testNowNoMutateDateTime() + public function testNowNoMutateDateTime(): void { $value = '2018-06-21 10:11:12'; $notNow = new Chronos($value); @@ -85,7 +85,7 @@ public function testNowNoMutateDateTime() /** * Ensure that using test now doesn't mutate test now. */ - public function testNowNoMutateDate() + public function testNowNoMutateDate(): void { $value = '2018-06-21 10:11:12'; $notNow = new Chronos($value); @@ -101,7 +101,7 @@ public function testNowNoMutateDate() $this->assertSame('2018-06-20 00:00:00', $instance->format('Y-m-d H:i:s')); } - public function testParseWithTestValueSet() + public function testParseWithTestValueSet(): void { $notNow = Chronos::yesterday(); Chronos::setTestNow($notNow); @@ -112,7 +112,7 @@ public function testParseWithTestValueSet() $this->assertSame((string)$notNow, (string)Chronos::parse('now')); } - public function testParseRelativeWithTestValueSet() + public function testParseRelativeWithTestValueSet(): void { $notNow = Chronos::parse('2013-09-01 05:15:05'); Chronos::setTestNow($notNow); @@ -161,7 +161,7 @@ public function testParseRelativeWithTestValueSet() $this->assertSame('2013-09-30 05:15:05', Chronos::parse('last day of this month')->toDateTimeString()); } - public function testParseRelativeWithMinusSignsInDate() + public function testParseRelativeWithMinusSignsInDate(): void { $notNow = Chronos::parse('2013-09-01 05:15:05'); Chronos::setTestNow($notNow); @@ -170,7 +170,7 @@ public function testParseRelativeWithMinusSignsInDate() $this->assertSame('2000-10-10 00:00:00', Chronos::parse('2000-10-10')->toDateTimeString()); } - public function testParseWithTimeZone() + public function testParseWithTimeZone(): void { $notNow = Chronos::parse('2013-07-01 12:00:00', 'America/New_York'); Chronos::setTestNow($notNow); @@ -180,7 +180,7 @@ public function testParseWithTimeZone() $this->assertSame('2013-07-01T09:00:00-07:00', Chronos::parse('now', 'America/Vancouver')->toIso8601String()); } - public function testParseRelativeWithTimeZone() + public function testParseRelativeWithTimeZone(): void { $notNow = Chronos::parse('2013-07-01 12:00:00', 'America/New_York'); Chronos::setTestNow($notNow); @@ -192,7 +192,7 @@ public function testParseRelativeWithTimeZone() /** * Test parse() with relative values and timezones */ - public function testParseRelativeWithTimezoneAndTestValueSet() + public function testParseRelativeWithTimezoneAndTestValueSet(): void { $notNow = Chronos::parse('2013-07-01 12:00:00', 'America/New_York'); Chronos::setTestNow($notNow); @@ -211,12 +211,12 @@ public function testParseRelativeWithTimezoneAndTestValueSet() $this->assertSame('2013-07-01T06:30:00-05:00', Chronos::parse('06:30:00', 'America/Mexico_City')->toIso8601String()); } - public function testNullTimezone() + public function testNullTimezone(): void { $c = new Chronos('2016-01-01 00:00:00', 'Europe/Copenhagen'); Chronos::setTestNow($c); - $result = new Chronos('now', null); + $result = new Chronos('now'); $this->assertSame((new DateTimeZone('America/Toronto'))->getName(), $result->tz->getName()); $this->assertSame('2015-12-31 18:00:00', $result->format('Y-m-d H:i:s')); $this->assertSame((new DateTimeZone('Europe/Copenhagen'))->getName(), Chronos::getTestNow()->tz->getName()); @@ -225,7 +225,7 @@ public function testNullTimezone() /** * Test that setting testNow() on one class sets it on all of the chronos classes. */ - public function testSetTestNowSingular() + public function testSetTestNowSingular(): void { $c = new Chronos('2016-01-03 00:00:00', 'Europe/Copenhagen'); Chronos::setTestNow($c); @@ -233,11 +233,11 @@ public function testSetTestNowSingular() $this->assertSame($c, Chronos::getTestNow()); } - public function testWithTestNowSetsAndRestoresNull() + public function testWithTestNowSetsAndRestoresNull(): void { $this->assertNull(Chronos::getTestNow()); - $result = Chronos::withTestNow('2023-06-15 12:00:00', function () { + $result = Chronos::withTestNow('2023-06-15 12:00:00', function (): string { $this->assertNotNull(Chronos::getTestNow()); $this->assertSame('2023-06-15', Chronos::now()->format('Y-m-d')); @@ -248,12 +248,12 @@ public function testWithTestNowSetsAndRestoresNull() $this->assertNull(Chronos::getTestNow()); } - public function testWithTestNowRestoresPreviousTestNow() + public function testWithTestNowRestoresPreviousTestNow(): void { $original = new Chronos('2020-01-01 00:00:00'); Chronos::setTestNow($original); - Chronos::withTestNow('2023-06-15 12:00:00', function () { + Chronos::withTestNow('2023-06-15 12:00:00', function (): void { $this->assertSame('2023-06-15', Chronos::now()->format('Y-m-d')); }); @@ -261,14 +261,14 @@ public function testWithTestNowRestoresPreviousTestNow() $this->assertSame('2020-01-01', Chronos::now()->format('Y-m-d')); } - public function testWithTestNowNested() + public function testWithTestNowNested(): void { Chronos::setTestNow('2020-01-01 00:00:00'); - Chronos::withTestNow('2021-06-15 00:00:00', function () { + Chronos::withTestNow('2021-06-15 00:00:00', function (): void { $this->assertSame('2021-06-15', Chronos::now()->format('Y-m-d')); - Chronos::withTestNow('2022-12-25 00:00:00', function () { + Chronos::withTestNow('2022-12-25 00:00:00', function (): void { $this->assertSame('2022-12-25', Chronos::now()->format('Y-m-d')); }); @@ -278,13 +278,13 @@ public function testWithTestNowNested() $this->assertSame('2020-01-01', Chronos::now()->format('Y-m-d')); } - public function testWithTestNowRestoresOnException() + public function testWithTestNowRestoresOnException(): void { $original = new Chronos('2020-01-01 00:00:00'); Chronos::setTestNow($original); try { - Chronos::withTestNow('2023-06-15 12:00:00', function () { + Chronos::withTestNow('2023-06-15 12:00:00', function (): void { throw new RuntimeException('Test exception'); }); $this->fail('Exception should have been thrown'); @@ -295,11 +295,11 @@ public function testWithTestNowRestoresOnException() $this->assertSame($original, Chronos::getTestNow()); } - public function testWithTestNowWithChronosInstance() + public function testWithTestNowWithChronosInstance(): void { $testTime = new Chronos('2023-06-15 14:30:00'); - $result = Chronos::withTestNow($testTime, function () { + $result = Chronos::withTestNow($testTime, function (): string { return Chronos::now()->format('Y-m-d H:i:s'); }); @@ -307,11 +307,11 @@ public function testWithTestNowWithChronosInstance() $this->assertNull(Chronos::getTestNow()); } - public function testWithTestNowWithNull() + public function testWithTestNowWithNull(): void { Chronos::setTestNow('2020-01-01 00:00:00'); - Chronos::withTestNow(null, function () { + Chronos::withTestNow(null, function (): void { $this->assertNull(Chronos::getTestNow()); }); diff --git a/tests/TestCase/DebugInfoTest.php b/tests/TestCase/DebugInfoTest.php index 46ac85a9..2f449d34 100644 --- a/tests/TestCase/DebugInfoTest.php +++ b/tests/TestCase/DebugInfoTest.php @@ -19,7 +19,7 @@ class DebugInfoTest extends TestCase { - public function testDateTime() + public function testDateTime(): void { $expected = [ 'hasFixedNow' => false, @@ -31,18 +31,18 @@ public function testDateTime() $this->assertSame($expected, $chronos->__debugInfo()); } - public function testDate() + public function testDate(): void { $expected = [ 'hasFixedNow' => false, 'date' => '2001-02-03', ]; - $date = ChronosDate::create(2001, 2, 3, 10, 20, 30); + $date = ChronosDate::create(2001, 2, 3); $this->assertSame($expected, $date->__debugInfo()); } - public function testDateTimeWithNow() + public function testDateTimeWithNow(): void { $expected = [ 'hasFixedNow' => true, @@ -55,7 +55,7 @@ public function testDateTimeWithNow() $this->assertSame($expected, $chronos->__debugInfo()); } - public function testDateWithNow() + public function testDateWithNow(): void { $expected = [ 'hasFixedNow' => true, @@ -63,7 +63,7 @@ public function testDateWithNow() ]; Chronos::setTestNow(Chronos::now()); - $date = ChronosDate::create(2001, 2, 3, 10, 20, 30); + $date = ChronosDate::create(2001, 2, 3); $this->assertSame($expected, $date->__debugInfo()); } } diff --git a/tests/TestCase/TestCase.php b/tests/TestCase/TestCase.php index 688115f6..77a72fcc 100644 --- a/tests/TestCase/TestCase.php +++ b/tests/TestCase/TestCase.php @@ -21,7 +21,7 @@ abstract class TestCase extends BaseTestCase { - private $saveTz; + private string $saveTz; protected function setUp(): void { @@ -34,7 +34,7 @@ protected function setUp(): void protected function tearDown(): void { date_default_timezone_set($this->saveTz); - Chronos::setTestNow(null); + Chronos::setTestNow(); } protected function assertTime($d, $hour, $minute, $second = null, $microsecond = null) @@ -142,12 +142,12 @@ public function deprecated(Closure $callable): void $previousHandler = set_error_handler( function ($code, $message, $file, $line, $context = null) use (&$previousHandler, &$deprecation): bool { - if ($code == E_USER_DEPRECATED) { + if ($code === E_USER_DEPRECATED) { $deprecation = true; return true; } - if ($previousHandler) { + if ($previousHandler !== null) { return $previousHandler($code, $message, $file, $line, $context); }