From d715a63f39ba076acf8be1e4a0901acdcc92228b Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 26 Jan 2024 17:22:21 +0000 Subject: [PATCH] [1.x] Adds tests regarding carbon instances (#82) * Adds tests regarding carbon instances * Fixes matrix laravel name * Uses setTestNow --- .github/workflows/tests.yml | 18 ++++++++++++++++-- composer.json | 5 +++-- tests/SerializerPhp81Test.php | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index aaab5ef5..77587de5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/composer.json b/composer.json index 7142366b..d2d94f62 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/tests/SerializerPhp81Test.php b/tests/SerializerPhp81Test.php index 3add007c..8e517451 100644 --- a/tests/SerializerPhp81Test.php +++ b/tests/SerializerPhp81Test.php @@ -1,5 +1,6 @@ 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;