Skip to content

Commit 786d69e

Browse files
authored
Merge pull request #454 from cakephp/php-8.4
Fix error on PHP 8.4
2 parents 96a3d2d + d5fef65 commit 786d69e

File tree

4 files changed

+70
-14
lines changed

4 files changed

+70
-14
lines changed

.github/workflows/ci.yml

+50-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,56 @@ permissions:
1515

1616
jobs:
1717
testsuite:
18-
uses: cakephp/.github/.github/workflows/[email protected]
19-
secrets: inherit
18+
runs-on: ubuntu-22.04
19+
continue-on-error: ${{ matrix.unstable }}
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
php-version: ['8.1']
24+
dependencies: [highest]
25+
unstable: [false]
26+
include:
27+
- php-version: '8.1'
28+
dependencies: lowest
29+
unstable: false
30+
- php-version: '8.2'
31+
dependencies: highest
32+
unstable: false
33+
- php-version: '8.3'
34+
dependencies: highest
35+
unstable: false
36+
- php-version: '8.4'
37+
dependencies: highest
38+
unstable: true
39+
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- name: Setup PHP
44+
uses: shivammathur/setup-php@v2
45+
with:
46+
php-version: ${{ matrix.php-version }}
47+
extensions: mbstring, intl
48+
ini-values: zend.assertions=1
49+
coverage: pcov
50+
51+
- name: Composer install
52+
uses: ramsey/composer-install@v2
53+
with:
54+
dependency-versions: ${{ matrix.dependencies }}
55+
composer-options: ${{ matrix.composer-options }}
56+
57+
- name: Run PHPUnit
58+
run: |
59+
if [[ ${{ matrix.php-version }} == '8.1' && ${{ matrix.dependencies }} == 'highest' ]]; then
60+
export CODECOVERAGE=1 && vendor/bin/phpunit --display-deprecations --display-warnings --display-incomplete --display-skipped --coverage-clover=coverage.xml
61+
else
62+
vendor/bin/phpunit --display-deprecations --display-warnings
63+
fi
64+
65+
- name: Code Coverage Report
66+
if: success() && matrix.php-version == '8.1' && matrix.dependencies == 'highest'
67+
uses: codecov/codecov-action@v3
2068

2169
cs-stan:
2270
uses: cakephp/.github/.github/workflows/[email protected]

phpstan.neon

+4
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ parameters:
77
- src/
88
ignoreErrors:
99
- identifier: missingType.iterableValue
10+
-
11+
message: "#^Call to an undefined static method DateTimeImmutable\\:\\:createFromTimestamp\\(\\)\\.$#"
12+
count: 1
13+
path: src/Chronos.php

src/Chronos.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -736,13 +736,15 @@ public static function createFromArray(array $values): static
736736
/**
737737
* Create an instance from a timestamp
738738
*
739-
* @param int $timestamp The timestamp to create an instance from.
739+
* @param float|int $timestamp The timestamp to create an instance from.
740740
* @param \DateTimeZone|string|null $timezone The DateTimeZone object or timezone name the new instance should use.
741741
* @return static
742742
*/
743-
public static function createFromTimestamp(int $timestamp, DateTimeZone|string|null $timezone = null): static
743+
public static function createFromTimestamp(float|int $timestamp, DateTimeZone|string|null $timezone = null): static
744744
{
745-
return static::now($timezone)->setTimestamp($timestamp);
745+
$instance = PHP_VERSION_ID >= 80400 ? parent::createFromTimestamp($timestamp) : new static('@' . $timestamp);
746+
747+
return $timezone ? $instance->setTimezone($timezone) : $instance;
746748
}
747749

748750
/**

tests/TestCase/DateTime/CreateFromTimestampTest.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ class CreateFromTimestampTest extends TestCase
2424
public function testCreateReturnsDatingInstance()
2525
{
2626
$d = Chronos::createFromTimestamp(Chronos::create(1975, 5, 21, 22, 32, 5)->timestamp);
27-
$this->assertDateTime($d, 1975, 5, 21, 22, 32, 5);
27+
$this->assertDateTime($d, 1975, 5, 22, 2, 32, 5);
28+
$this->assertSame('+00:00', $d->tzName);
2829
}
2930

30-
public function testCreateFromTimestampUsesDefaultTimezone()
31+
public function testCreateFromTimestampUsesUTC()
3132
{
3233
$d = Chronos::createFromTimestamp(0);
3334

34-
// We know Toronto is -5 since no DST in Jan
35-
$this->assertSame(1969, $d->year);
36-
$this->assertSame(-5 * 3600, $d->offset);
35+
$this->assertSame(1970, $d->year);
36+
$this->assertSame(0, $d->offset);
37+
$this->assertSame('+00:00', $d->tzName);
3738
}
3839

3940
public function testCreateFromTimestampWithDateTimeZone()
@@ -45,9 +46,10 @@ public function testCreateFromTimestampWithDateTimeZone()
4546

4647
public function testCreateFromTimestampWithString()
4748
{
48-
$d = Chronos::createFromTimestamp(0, 'UTC');
49-
$this->assertDateTime($d, 1970, 1, 1, 0, 0, 0);
50-
$this->assertSame(0, $d->offset);
51-
$this->assertSame('UTC', $d->tzName);
49+
$d = Chronos::createFromTimestamp(0, 'America/Toronto');
50+
// We know Toronto is -5 since no DST in Jan
51+
$this->assertSame(1969, $d->year);
52+
$this->assertSame(-5 * 3600, $d->offset);
53+
$this->assertSame('America/Toronto', $d->tzName);
5254
}
5355
}

0 commit comments

Comments
 (0)