Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.4
coverage: none

- name: Get composer cache directory
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: 8.2
php-version: 8.4

- name: Get composer cache directory
id: composer-cache
Expand All @@ -77,7 +77,7 @@ jobs:

strategy:
matrix:
php-versions: ['8.0', '8.1', '8.2']
php-versions: ['8.3', '8.4']

steps:
- name: Checkout code
Expand All @@ -104,7 +104,7 @@ jobs:
run: composer install --no-interaction --no-progress --prefer-dist --optimize-autoloader

- name: Run unit tests
run: ./vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml --coverage-text
run: ./vendor/bin/phpunit

- name: Publish coverage report to Codecov
uses: codecov/codecov-action@v1
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "pauci/datetime",
"description": "Enhanced DateTime, DateTimeImmutable and DateInterval objects",
"version": "0.7.0",
"type": "library",
"keywords": [
"datetime",
Expand All @@ -22,7 +23,7 @@
"issues": "https://github.com/pauci/datetime/issues"
},
"require": {
"php": "^8.0 || ^8.1 || ^8.2",
"php": "^8.3 || ^8.4",
"ext-json": "*",
"psr/clock": "^1.0"
},
Expand All @@ -31,7 +32,8 @@
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^11.0.0",
"rector/rector": "^1.2",
"squizlabs/php_codesniffer": "^3.7"
},
"suggest": {
Expand All @@ -57,12 +59,16 @@
"check": [
"@lint",
"@cs-check",
"@rector",
"@stan",
"@test"
],
"lint": "parallel-lint src tests",
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"rector": "rector -n -vv",
"rector:clear": "rector -n --clear-cache -vv",
"rector:fix": "rector -vv",
"stan": "phpstan analyse --no-progress",
"test": "phpunit",
"test-coverage": "phpunit --coverage-clover clover.xml"
Expand Down
7 changes: 6 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="./tests/bootstrap.php" colors="true">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
bootstrap="./tests/bootstrap.php"
colors="true"
>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
Expand Down
14 changes: 14 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use Rector\CodingStyle;
use Rector\Config\RectorConfig;
use Rector\Privatization;

return RectorConfig::configure()
->withPhpSets(php83: true)
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);
8 changes: 4 additions & 4 deletions src/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function now(): DateTimeInterface
/**
* @throws Exception
*/
public static function fromString(string $time, DateTimeZone $timezone = null): static
public static function fromString(string $time, ?DateTimeZone $timezone = null): static
{
$dateTime = parent::createFromInterface(new \DateTime($time, $timezone));
\assert($dateTime instanceof static);
Expand All @@ -53,7 +53,7 @@ public static function fromString(string $time, DateTimeZone $timezone = null):
/**
* @throws Exception
*/
public static function fromTimestamp(int $timestamp, DateTimeZone $timezone = null): static
public static function fromTimestamp(int $timestamp, ?DateTimeZone $timezone = null): static
{
$dateTime = static::createFromFormat('U', (string) $timestamp);
\assert(false !== $dateTime);
Expand All @@ -63,7 +63,7 @@ public static function fromTimestamp(int $timestamp, DateTimeZone $timezone = nu
: $dateTime->inDefaultTimezone();
}

public static function fromFloatTimestamp(float $timestamp, DateTimeZone $timezone = null): static
public static function fromFloatTimestamp(float $timestamp, ?DateTimeZone $timezone = null): static
{
$integer = floor($timestamp);
$fract = fmod($timestamp, 1);
Expand All @@ -83,7 +83,7 @@ public static function fromFloatTimestamp(float $timestamp, DateTimeZone $timezo
public static function createFromFormat(
string $format,
string $datetime,
DateTimeZone $timezone = null
?DateTimeZone $timezone = null
): static|false {
return parent::createFromFormat($format, $datetime, $timezone);
}
Expand Down
5 changes: 1 addition & 4 deletions src/FrozenClock.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@

class FrozenClock implements ClockInterface
{
private DateTime $now;

public function __construct(DateTime $now = null)
public function __construct(private DateTime $now = new DateTime())
{
$this->now = $now ?? new DateTime();
}

public function set(DateTime $now): void
Expand Down
4 changes: 2 additions & 2 deletions tests/src/DateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ public function testModify(): void

public function testModifyFailed(): void
{
$this->expectError();
$this->expectErrorMessage('DateTimeImmutable::modify(): Failed to parse time string (foo) at position 0 (f): The timezone could not be found in the database');
self::expectExceptionMessage('Failed to parse time string (foo) at position 0 (f): The timezone could not be found in the database');

$dateTime = DateTime::fromString('2016-05-12 22:37:46+02:00');

$dateTime->modify('foo');
}

Expand Down
3 changes: 1 addition & 2 deletions tests/src/FrozenClockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public function testItFailsToModify(): void
{
$clock = new FrozenClock();

$this->expectError();
$this->expectErrorMessage('DateTimeImmutable::modify(): Failed to parse time string (foo) at position 0 (f): The timezone could not be found in the database');
self::expectExceptionMessage('DateTimeImmutable::modify(): Failed to parse time string (foo) at position 0 (f): The timezone could not be found in the database');

$clock->modify('foo');
}
Expand Down
Loading