From f5011bce685fe9f5a7a10a211af24cdc1e093f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Tue, 11 Mar 2025 17:38:43 +0100 Subject: [PATCH] Laravel 12 support (#28) * Laravel 12 support * bump larastan * phpstan fixes * remove pest() * update larastan dependency name --- .github/workflows/ci.yml | 2 +- composer.json | 12 ++++++------ phpstan.neon | 3 ++- src/PriceFormatter.php | 2 +- tests/Pest.php | 5 ----- tests/Pest/CurrencyTest.php | 4 ++-- tests/Pest/MoneyTest.php | 4 ++-- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2148426..32f10b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - laravel: [10, 11] + laravel: [10, 11, 12] steps: - uses: actions/checkout@v2 diff --git a/composer.json b/composer.json index fff9205..dd0e60d 100644 --- a/composer.json +++ b/composer.json @@ -25,15 +25,15 @@ }, "require": { "php": "^8.2", - "illuminate/support": "^10.0|^11.0", + "illuminate/support": "^10.0|^11.0|^12.0", "archtechx/helpers": "^0.3.2" }, "require-dev": { - "orchestra/testbench": "^8.0|^9.0", - "pestphp/pest": "^2.0", - "phpstan/phpstan": "^1.9.8", - "pestphp/pest-plugin-laravel": "^2.0", - "nunomaduro/larastan": "^2.4" + "orchestra/testbench": "^8.0|^9.0|^10.0", + "pestphp/pest": "^2.0|^3.7", + "phpstan/phpstan": "^1.9.8|^2.1", + "pestphp/pest-plugin-laravel": "^2.0|^3.1", + "larastan/larastan": "^2.4|^3.0" }, "extra": { "laravel": { diff --git a/phpstan.neon b/phpstan.neon index 2d7efab..a21938c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ includes: - - ./vendor/nunomaduro/larastan/extension.neon + - ./vendor/larastan/larastan/extension.neon parameters: paths: @@ -23,3 +23,4 @@ parameters: paths: - src/Currency.php - identifier: missingType.iterableValue + - identifier: unset.possiblyHookedProperty diff --git a/src/PriceFormatter.php b/src/PriceFormatter.php index 67f0a19..cb2963c 100644 --- a/src/PriceFormatter.php +++ b/src/PriceFormatter.php @@ -44,7 +44,7 @@ class PriceFormatter $formatted = ltrim($formatted, $currency->prefix()); $formatted = rtrim($formatted, $currency->suffix()); - $removeNonDigits = preg_replace('/[^\d' . preg_quote($currency->decimalSeparator()) . ']/', '', $formatted); + $removeNonDigits = preg_replace('/[^\d' . preg_quote($currency->decimalSeparator(), '/') . ']/', '', $formatted); if (! is_string($removeNonDigits)) { throw new Exception('The formatted string could not be resolved to a valid number.'); diff --git a/tests/Pest.php b/tests/Pest.php index 46ef170..9a6a482 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -4,8 +4,3 @@ use ArchTech\Money\Tests\TestCase; use Pest\TestSuite; uses(ArchTech\Money\Tests\TestCase::class)->in('Pest'); - -function pest(): TestCase -{ - return TestSuite::getInstance()->test; -} diff --git a/tests/Pest/CurrencyTest.php b/tests/Pest/CurrencyTest.php index 4d917bd..1fbea1e 100644 --- a/tests/Pest/CurrencyTest.php +++ b/tests/Pest/CurrencyTest.php @@ -5,13 +5,13 @@ use ArchTech\Money\Exceptions\InvalidCurrencyException; use ArchTech\Money\Tests\Currencies\CZK; test("a currency is invalid if it doesn't have a name", function () { - pest()->expectException(InvalidCurrencyException::class); + $this->expectException(InvalidCurrencyException::class); new Currency(rate: 2.0, code: 'CZK'); }); test("a currency is invalid if it doesn't have a code", function () { - pest()->expectException(InvalidCurrencyException::class); + $this->expectException(InvalidCurrencyException::class); new Currency(rate: 2.0, name: 'Czech Crown'); }); diff --git a/tests/Pest/MoneyTest.php b/tests/Pest/MoneyTest.php index f895818..4749196 100644 --- a/tests/Pest/MoneyTest.php +++ b/tests/Pest/MoneyTest.php @@ -170,7 +170,7 @@ test('an exception is thrown if none of the currencies match the prefix and suff currencies()->remove(USD::class); - pest()->expectException(CannotExtractCurrencyException::class); + $this->expectException(CannotExtractCurrencyException::class); Money::fromFormatted($formatted); }); @@ -178,7 +178,7 @@ test('an exception is thrown if multiple currencies are using the same prefix an currencies()->add(['code' => 'USD2', 'name' => 'USD2', 'prefix' => '$']); $money = money(1000); - pest()->expectException(CannotExtractCurrencyException::class); + $this->expectException(CannotExtractCurrencyException::class); Money::fromFormatted($money->formatted()); });