Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for CarbonInterval and CarbonPeriod #3055

Merged
merged 3 commits into from
Jul 21, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/phpmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
include:
- php: 8.1
- php: 8.3

steps:
- name: Checkout the code
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
include:
- php: 8.1
- php: 8.3

steps:
- name: Checkout the code
Expand Down
13 changes: 10 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ parameters:
- '#should return (\S*)(static|\$this)\(Carbon\\CarbonImmutable\)(\|null)? but returns Carbon\\Carbon(Immutable|Interface)(\|null)?\.$#'
- '#should return (\S*)\$this\(Carbon\\CarbonInterval\)(\|null)? but returns static\(Carbon\\CarbonInterval\)(\|null)?\.$#'
- '#should return (\S*)static\(Carbon\\CarbonInterval\)(\|null)? but returns Carbon\\CarbonInterval(\|null)?\.$#'
- '#^Access to an undefined property DatePeriod::\$include_end_date\.$#'
- '#^Call to an undefined method DatePeriod::[a-zA-Z]+\(\)\.$#'
- '#^Call to an undefined method DateInterval::(spec|optimize)\(\)\.$#'
- '#^Property Carbon\\Carbon::\$timezone \(Carbon\\CarbonTimeZone\) does not accept string\.$#'
- '#^Method class@anonymous/tests/Carbon/TestingAidsTest\.php:\d+::modify\(\) should return class@anonymous/tests/Carbon/TestingAidsTest\.php:\d+ but returns \(DateTimeImmutable\|false\)\.$#'
Expand Down Expand Up @@ -58,9 +56,18 @@ parameters:
paths:
- tests/CarbonImmutable/GettersTest.php
-
message: '#^Access to an undefined property Carbon\\CarbonInterval::\$tz_?name\.$#'
message: '#^Access to an undefined property Carbon\\CarbonInterval::\$tz_?[Nn]ame\.$#'
paths:
- tests/CarbonInterval/GettersTest.php
- tests/CarbonInterval/SettersTest.php
-
message: '#^Access to an undefined property Carbon\\CarbonPeriod::\$(include)?(Start|End)Date\.$#'
paths:
- tests/CarbonPeriod/GettersTest.php
-
message: '#^Access to protected property Carbon\\CarbonPeriod::\$endDate\.$#'
paths:
- tests/CarbonPeriod/GettersTest.php
-
message: '#^Cannot access property \$locale on Carbon\\CarbonPeriod\|string\.$#'
paths:
Expand Down
20 changes: 20 additions & 0 deletions tests/CarbonInterval/GettersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Carbon\Carbon;
use Carbon\CarbonInterval;
use Carbon\Translator;
use DateTimeZone;
use InvalidArgumentException;
use Tests\AbstractTestCase;

Expand Down Expand Up @@ -121,4 +122,23 @@ public function testDebugInfo()
's' => 10,
], $ci->__debugInfo());
}

public function testGetTimezone()
{
$this->assertNull(CarbonInterval::day()->tzName);
$this->assertSame(
'America/New_York',
CarbonInterval::day()->setTimezone('America/New_York')->tzName,
);
$this->assertSame(
'America/New_York',
CarbonInterval::day()->setTimezone(
new DateTimeZone('America/New_York'),
)->tzName,
);
$this->assertSame(
'+05:00',
CarbonInterval::day()->setTimezone(5)->tzName,
);
}
}
Loading
Loading