Skip to content

Commit

Permalink
[1.x] Adds tests regarding carbon instances (#82)
Browse files Browse the repository at this point in the history
* Adds tests regarding carbon instances

* Fixes matrix laravel name

* Uses setTestNow
  • Loading branch information
nunomaduro committed Jan 26, 2024
1 parent ebe4d98 commit d715a63
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,22 @@ jobs:
fail-fast: true
matrix:
php: [7.3, 7.4, '8.0', 8.1, 8.2, 8.3]

name: PHP ${{ matrix.php }}
laravel: [8, 9, 10, 11]
exclude:
- php: 7.3
laravel: [9, 10, 11]
- php: 7.4
laravel: [9, 10, 11]
- php: 8.0
laravel: [10, 11]
- php: 8.1
laravel: [8, 11]
- php: 8.2
laravel: 8
- php: 8.3
laravel: 8

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

steps:
- name: Checkout code
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
"php": "^7.3|^8.0"
},
"require-dev": {
"nesbot/carbon": "^2.61",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0",
"nesbot/carbon": "^2.61|^3.0",
"pestphp/pest": "^1.21.3",
"phpstan/phpstan": "^1.8.2",
"symfony/var-dumper": "^5.4.11"
"symfony/var-dumper": "^5.4.11|^6.2.0|^7.0.0"
},
"autoload": {
"psr-4": {
Expand Down
15 changes: 15 additions & 0 deletions tests/SerializerPhp81Test.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Support\Carbon;
use Tests\Fixtures\Model;
use Tests\Fixtures\ModelAttribute;
use Tests\Fixtures\RegularClass;
Expand Down Expand Up @@ -681,6 +682,20 @@ public function getClosure()
expect(s($f1)())->toBeInstanceOf(RegularClass::class);
})->with('serializers');

test('carbon serialization', function () {
$now = Carbon::createFromDate(2011, 1, 1);

Carbon::setTestNow($now);

$startDate = Carbon::now();

$f1 = fn () => $startDate;

expect(s($f1)())
->toBeInstanceOf(Carbon::class)
->format('Y-m-d')->toBe('2011-01-01');
})->with('serializers');

class ClassWithBackedEnumProperty
{
public SerializerGlobalBackedEnum $enum = SerializerGlobalBackedEnum::Admin;
Expand Down

0 comments on commit d715a63

Please sign in to comment.