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
103 changes: 29 additions & 74 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,105 +6,60 @@ on:
branches:
- master

env:
default_php: 8.4

jobs:
coding-standards:
name: Coding Standards
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
- uses: actions/[email protected]
- uses: shivammathur/[email protected]
with:
php-version: 8.4
php-version: ${{ env.default_php }}
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run the linter
run: composer lint

- name: Check coding standards
run: composer cs-check
- uses: ramsey/composer-install@v3
- run: composer lint
- run: composer cs-check

static-analysis:
name: Static Analysis
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
- uses: actions/[email protected]
- uses: shivammathur/[email protected]
with:
coverage: none
php-version: 8.4

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer update --no-interaction --no-progress --prefer-dist

- name: Run static analysis
run: php vendor/bin/phpstan analyse
php-version: ${{ env.default_php }}
- uses: ramsey/composer-install@v3
- run: php vendor/bin/phpstan analyse

unit-tests:
name: Unit Tests
runs-on: ubuntu-latest

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

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
- uses: actions/[email protected]
- uses: shivammathur/[email protected]
with:
php-version: "${{ matrix.php-versions }}"
coverage: xdebug
- uses: ramsey/composer-install@v3
- run: ./vendor/bin/phpunit
- uses: codecov/codecov-action@v1

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
rector:
runs-on: ubuntu-latest
name: Run Rector on PHP
steps:
- uses: actions/[email protected]
- uses: shivammathur/[email protected]
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist --optimize-autoloader

- name: Run unit tests
run: ./vendor/bin/phpunit

- name: Publish coverage report to Codecov
uses: codecov/codecov-action@v1
php-version: ${{ env.default_php }}
tools: composer
- uses: ramsey/composer-install@v3
- run: composer rector
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^11.0.0",
"rector/rector": "^1.2",
"squizlabs/php_codesniffer": "^3.7"
"phpstan/extension-installer": "^1.4.3",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^12.0",
"rector/rector": "^2.0",
"squizlabs/php_codesniffer": "^4.0"
},
"suggest": {
"pauci/datetime-doctrine": "Allows the use of pauci/datetime value objects as Doctrine field types."
Expand Down
10 changes: 2 additions & 8 deletions src/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ public static function now(): DateTimeInterface
*/
public static function fromString(string $time, ?DateTimeZone $timezone = null): static
{
$dateTime = parent::createFromInterface(new \DateTime($time, $timezone));
\assert($dateTime instanceof static);

return $dateTime;
return parent::createFromInterface(new \DateTime($time, $timezone));
}

/**
Expand Down Expand Up @@ -100,10 +97,7 @@ public static function createFromMutable(\DateTime $object): static
#[\Override]
public static function createFromInterface(\DateTimeInterface $object): static
{
$dateTime = parent::createFromInterface($object);
\assert($dateTime instanceof static);

return $dateTime;
return parent::createFromInterface($object);
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/FrozenClock.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public function set(DateTime $now): void
public function modify(string $modifier): void
{
$now = $this->now->modify($modifier);
\assert($now instanceof DateTime);

$this->now = $now;
}
Expand Down
6 changes: 1 addition & 5 deletions tests/src/DateIntervalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function testFromDateInterval(string $intervalSpec, array $parts): void
{
$interval = DateInterval::fromDateInterval(new \DateInterval($intervalSpec));

self::assertInstanceOf(DateInterval::class, $interval);

self::assertEquals($parts[0], $interval->y);
self::assertEquals($parts[1], $interval->m);
self::assertEquals($parts[2], $interval->d);
Expand All @@ -57,9 +55,7 @@ public function testFromDateIntervalBetweenWinterAndDst(): void

$interval = DateInterval::fromDateInterval($phpInterval);

$expected = PHP_VERSION_ID >= 80100 ? 'P2M30DT23H' : 'P3MT-1H';

self::assertEquals($expected, (string) $interval);
self::assertEquals('P2M30DT23H', (string) $interval);
}

/**
Expand Down
11 changes: 0 additions & 11 deletions tests/src/DateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function testFromString(): void
{
$dateTime = DateTime::fromString('2017-12-02 02:20:03');

self::assertInstanceOf(DateTime::class, $dateTime);
self::assertEquals('2017-12-02T02:20:03+01:00', (string) $dateTime);
}

Expand Down Expand Up @@ -83,7 +82,6 @@ public function testCreateFromMutable(): void
{
$dateTime = DateTime::createFromMutable(new \DateTime('2016-05-16 14:09:10'));

self::assertInstanceOf(DateTime::class, $dateTime);
self::assertEquals('2016-05-16T14:09:10+02:00', (string) $dateTime);

$dateTime = DateTime::createFromMutable(new \DateTime('2016-05-16 14:09:10-04:00'));
Expand Down Expand Up @@ -120,7 +118,6 @@ public function testCreateFromInterface(): void
$phpDateTime = new \DateTime('2016-05-16 14:32:51.678991');
$dateTime = DateTime::createFromInterface($phpDateTime);

self::assertInstanceOf(DateTime::class, $dateTime);
self::assertEquals('2016-05-16T14:32:51.678991+02:00', (string) $dateTime);
}

Expand Down Expand Up @@ -154,7 +151,6 @@ public function testAdd(): void

$dateTime2 = $dateTime1->add($interval);

self::assertInstanceOf(DateTime::class, $dateTime2);
self::assertEquals('2016-05-13T22:37:46+02:00', (string) $dateTime2);

// Immutability check
Expand All @@ -168,7 +164,6 @@ public function testSub(): void

$dateTime2 = $dateTime1->sub($interval);

self::assertInstanceOf(DateTime::class, $dateTime2);
self::assertEquals('2016-05-11T22:37:46+02:00', (string) $dateTime2);

// Immutability check
Expand All @@ -180,7 +175,6 @@ public function testModify(): void
$dateTime1 = DateTime::fromString('2016-05-12 22:37:46+02:00');
$dateTime2 = $dateTime1->modify('+1 day');

self::assertInstanceOf(DateTime::class, $dateTime2);
self::assertEquals('2016-05-13T22:37:46+02:00', (string) $dateTime2);

// Immutability check
Expand All @@ -201,7 +195,6 @@ public function testSetDate(): void
$dateTime1 = DateTime::fromString('2016-05-12 22:37:46+02:00');
$dateTime2 = $dateTime1->setDate(2011, 10, 22);

self::assertInstanceOf(DateTime::class, $dateTime2);
self::assertEquals('2011-10-22T22:37:46+02:00', (string) $dateTime2);

// Immutability check
Expand All @@ -213,7 +206,6 @@ public function testSetISODate(): void
$dateTime1 = DateTime::fromString('2016-05-12 22:37:46+02:00');
$dateTime2 = $dateTime1->setISODate(2011, 42, 6);

self::assertInstanceOf(DateTime::class, $dateTime2);
self::assertEquals('2011-10-22T22:37:46+02:00', (string) $dateTime2);

// Immutability check
Expand All @@ -225,7 +217,6 @@ public function testSetTime(): void
$dateTime1 = DateTime::fromString('2016-05-12 22:37:46.123456+02:00');
$dateTime2 = $dateTime1->setTime(12, 10, 15, 98765);

self::assertInstanceOf(DateTime::class, $dateTime2);
self::assertEquals('2016-05-12T12:10:15.098765+02:00', (string) $dateTime2);

// Immutability check
Expand All @@ -237,7 +228,6 @@ public function testSetTimestamp(): void
$dateTime1 = DateTime::fromString('2016-05-12 22:37:46+02:00');
$dateTime2 = $dateTime1->setTimestamp(1463490311);

self::assertInstanceOf(DateTime::class, $dateTime2);
self::assertEquals('2016-05-17T15:05:11+02:00', (string) $dateTime2);

// Immutability check
Expand All @@ -249,7 +239,6 @@ public function testSetTimezone(): void
$dateTime1 = DateTime::fromString('2016-05-12 22:37:46+02:00');
$dateTime2 = $dateTime1->setTimezone(new \DateTimeZone('America/New_York'));

self::assertInstanceOf(DateTime::class, $dateTime2);
self::assertEquals('2016-05-12T16:37:46-04:00', (string) $dateTime2);

// Immutability check
Expand Down