From 0fcffb765ac568f8a65babd332437d8017c1dd43 Mon Sep 17 00:00:00 2001 From: Ant Weedon Date: Fri, 3 Jan 2025 06:29:01 +0000 Subject: [PATCH 1/4] Add support for Carbon 3 --- composer.json | 2 +- src/Carbon/Types/Generator.php | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 46c0dbc..a2f7ba5 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "require": { "php": "^7.1 || ^8.0", "simple-cli/simple-cli": "^1.1", - "nesbot/carbon": "^2.20" + "nesbot/carbon": "^2.20 || ^3.0" }, "require-dev": { "phpunit/phpunit": "^7.5 || ^8.2" diff --git a/src/Carbon/Types/Generator.php b/src/Carbon/Types/Generator.php index 0e52959..8e6dcfa 100644 --- a/src/Carbon/Types/Generator.php +++ b/src/Carbon/Types/Generator.php @@ -3,6 +3,7 @@ namespace Carbon\Types; use Carbon\Carbon; +use Carbon\FactoryImmutable; use Closure; use ReflectionClass; use ReflectionException; @@ -51,11 +52,17 @@ protected function getMethods($boots) $this->runBoot($boot); } - $c = new ReflectionClass(Carbon::now()); - $macros = $c->getProperty('globalMacros'); - $macros->setAccessible(true); + if (method_exists(FactoryImmutable::class, 'getDefaultInstance')) { + // Carbon 3 + return FactoryImmutable::getDefaultInstance()->getSettings()['macros'] ?? []; + } else { + // Carbon 2 + $c = new ReflectionClass(Carbon::now()); + $macros = $c->getProperty('globalMacros'); + $macros->setAccessible(true); - return $macros->getValue(); + return $macros->getValue(); + } } /** From 7cc72c32e2c2299ba3df71c758ef46262af13109 Mon Sep 17 00:00:00 2001 From: Bastien Miclo Date: Fri, 3 Jan 2025 17:19:59 +0100 Subject: [PATCH 2/4] Drop support for Carbon < 2.72.6 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a2f7ba5..2d711af 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "require": { "php": "^7.1 || ^8.0", "simple-cli/simple-cli": "^1.1", - "nesbot/carbon": "^2.20 || ^3.0" + "nesbot/carbon": "^2.72.6 || ^3.0" }, "require-dev": { "phpunit/phpunit": "^7.5 || ^8.2" From e2dc805bdec56a3c4e28eaa64adcf86de92501b8 Mon Sep 17 00:00:00 2001 From: Bastien Miclo Date: Fri, 3 Jan 2025 17:22:55 +0100 Subject: [PATCH 3/4] Set PHPUnit version for PHP >= 8.1 --- .github/workflows/tests.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index df57d94..191f780 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -39,6 +39,10 @@ jobs: path: ~/.composer/cache key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.setup }}-composer-${{ hashFiles('**/composer.lock') }} + - name: Set PHPUnit version + if: matrix.php >= 8.1 + run: composer require "phpunit/phpunit:^8.2" --no-update + - name: Install Dependencies run: composer update --prefer-dist --prefer-${{ matrix.setup }} --no-interaction --no-suggest From ae0f78e0022477a6a35637fbbed371b4ce3297e0 Mon Sep 17 00:00:00 2001 From: Bastien Miclo Date: Fri, 3 Jan 2025 17:24:13 +0100 Subject: [PATCH 4/4] Upgrade PHPUnit --- .github/workflows/tests.yaml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 191f780..54445c7 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -41,7 +41,7 @@ jobs: - name: Set PHPUnit version if: matrix.php >= 8.1 - run: composer require "phpunit/phpunit:^8.2" --no-update + run: composer require "phpunit/phpunit:^8.5.41" --no-update - name: Install Dependencies run: composer update --prefer-dist --prefer-${{ matrix.setup }} --no-interaction --no-suggest diff --git a/composer.json b/composer.json index 2d711af..a1650e1 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "nesbot/carbon": "^2.72.6 || ^3.0" }, "require-dev": { - "phpunit/phpunit": "^7.5 || ^8.2" + "phpunit/phpunit": "^7.5.20 || ^8.5.41" }, "autoload": { "psr-4": {