diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index 67e66c6..1a13177 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -13,7 +13,7 @@ jobs: - name: Dependabot metadata id: metadata - uses: dependabot/fetch-metadata@v2.0.0 + uses: dependabot/fetch-metadata@v2.4.0 with: github-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml index c958238..82c33c7 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -14,14 +14,14 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v6 with: ref: ${{ github.head_ref }} - name: Fix PHP code style issues - uses: aglipanci/laravel-pint-action@2.3.1 + uses: aglipanci/laravel-pint-action@2.6 - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v7 with: commit_message: Fix styling diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 6ee75f8..1b1bfc0 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -11,12 +11,12 @@ jobs: name: phpstan runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' coverage: none - name: Install composer dependencies diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 8648cd3..80c7bf4 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -2,9 +2,17 @@ name: run-tests on: push: - branches: [main] + branches: + - main + - 1.x + - 2.x + - 3.x pull_request: - branches: [main] + branches: + - main + - 1.x + - 2.x + - 3.x jobs: test: @@ -28,7 +36,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml index 8c12ba9..e687dad 100644 --- a/.github/workflows/update-changelog.yml +++ b/.github/workflows/update-changelog.yml @@ -13,7 +13,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v6 with: ref: main @@ -24,7 +24,7 @@ jobs: release-notes: ${{ github.event.release.body }} - name: Commit updated CHANGELOG - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v7 with: branch: main commit_message: Update CHANGELOG diff --git a/composer.json b/composer.json index 3c7a2c2..aaabfdb 100644 --- a/composer.json +++ b/composer.json @@ -20,24 +20,23 @@ } ], "require": { - "php": "^8.2", - "coderflex/laravel-turnstile": "^2.0", - "illuminate/contracts": "^11.0 || ^12.0", + "php": "^8.2|^8.3|^8.4", + "coderflex/laravel-turnstile": "^1.0|^2.0", + "illuminate/contracts": "^10.0|^11.0|^12.0", "spatie/laravel-package-tools": "^1.14.0" }, "require-dev": { "filament/filament": "^4.0", + "larastan/larastan": "^2.8|^3.0", "laravel/pint": "^1.0", - "nunomaduro/collision": "^8.0", - "nunomaduro/larastan": "^3.0", - "orchestra/testbench": "^10.0", - "pestphp/pest": "^3.0", - "pestphp/pest-plugin-arch": "^3.0", - "pestphp/pest-plugin-laravel": "^3.0", - "pestphp/pest-plugin-livewire": "^3.0", + "nunomaduro/collision": "^7.0|^8.0", + "orchestra/testbench": "^8.0|^9.0|^10.0", + "pestphp/pest": "^2.0|^3.7", + "pestphp/pest-plugin-arch": "^2.0|^3.0", + "pestphp/pest-plugin-livewire": "^2.0|^3.0", "phpstan/extension-installer": "^1.1", - "phpstan/phpstan-deprecation-rules": "^2.0", - "phpstan/phpstan-phpunit": "^2.0" + "phpstan/phpstan-deprecation-rules": "^1.0|^2.0", + "phpstan/phpstan-phpunit": "^1.0|^2.0" }, "autoload": { "psr-4": { diff --git a/resources/views/components/turnstile.blade.php b/resources/views/components/turnstile.blade.php index 9f1319c..7d7c809 100644 --- a/resources/views/components/turnstile.blade.php +++ b/resources/views/components/turnstile.blade.php @@ -9,48 +9,60 @@ -
{ + let options = { + sitekey: '{{config('turnstile.turnstile_site_key')}}', + theme: '{{ $theme }}', + size: '{{ $size }}', + language: '{{ $language }}', callback: function (token) { $wire.set('{{ $statePath }}', token) }, - - errorCallback: function () { + 'error-callback': function () { $wire.set('{{ $statePath }}', null) - }, + } } - window.onloadTurnstileCallback = () => { - turnstile.render($refs.turnstile, options) + // Render widget when Turnstile API is ready + const renderWidget = () => { + if (!window.turnstile || !$refs.turnstile || widgetId !== null) { + return; + } + + widgetId = turnstile.render($refs.turnstile, options); } - resetCaptcha = () => { - turnstile.reset($refs.turnstile) + // Called when Turnstile API loads + window.onTurnstileLoad = () => { + renderWidget(); } - })()" - > -
-
-
- + // If API already loaded (on re-render), render immediately + if (window.turnstile) { + renderWidget(); + } - @push('scripts') - - @endpush -
\ No newline at end of file + + // Cleanup when component is destroyed + return () => { + if (widgetId !== null && window.turnstile) { + turnstile.remove(widgetId); + widgetId = null; + } + } + })()" + > +
+ + diff --git a/src/Forms/Components/Turnstile.php b/src/Forms/Components/Turnstile.php index 57ba8f8..399e761 100644 --- a/src/Forms/Components/Turnstile.php +++ b/src/Forms/Components/Turnstile.php @@ -15,7 +15,7 @@ class Turnstile extends Field protected string $size = 'normal'; - protected string $language = 'en-US'; + protected string $language = 'en-us'; protected function setUp(): void { @@ -51,26 +51,17 @@ public function language(string $language): static return $this; } - /** - * @return string - */ - public function getTheme() + public function getTheme(): string { return $this->evaluate($this->theme); } - /** - * @return string - */ - public function getSize() + public function getSize(): string { return $this->evaluate($this->size); } - /** - * @return string - */ - public function getLanguage() + public function getLanguage(): string { return $this->evaluate($this->language); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 0686c58..a70fc4f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -34,19 +34,25 @@ protected function setUp(): void config()->set('app.key', '6rE9Nz59bGRbeMATftriyQjrpF7DcOQm'); $this->setCurrentFilamentPanel(); + + // Ensure DataStore is fresh for each test + // The issue was that Livewire's DataStore singleton (which holds component state) was not being correctly reset between tests in this environment, causing state persistence failures. + $this->app->forgetInstance(\Livewire\Mechanisms\DataStore::class); + $this->app->singleton(\Livewire\Mechanisms\DataStore::class); } protected function getPackageProviders($app) { return [ + LivewireServiceProvider::class, ActionsServiceProvider::class, BladeCaptureDirectiveServiceProvider::class, BladeHeroiconsServiceProvider::class, BladeIconsServiceProvider::class, FilamentServiceProvider::class, FormsServiceProvider::class, + \Filament\Schemas\SchemasServiceProvider::class, InfolistsServiceProvider::class, - LivewireServiceProvider::class, NotificationsServiceProvider::class, SupportServiceProvider::class, TablesServiceProvider::class,