Skip to content

Commit

Permalink
Laravel 12 Support
Browse files Browse the repository at this point in the history
  • Loading branch information
erikn69 committed Feb 5, 2025
1 parent 7e5e100 commit dab247a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 47 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ jobs:
matrix:
os: [ubuntu-latest]
php: [8.4, 8.3, 8.2, 8.1, 8.0]
laravel: [11.*, 10.*, 9.*, 8.*]
laravel: [12.*, 11.*, 10.*, 9.*, 8.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 12.*
testbench: 10.*
- laravel: 11.*
testbench: 9.*
- laravel: 10.*
Expand All @@ -22,6 +24,10 @@ jobs:
- laravel: 8.*
testbench: ^6.23
exclude:
- laravel: 12.*
php: 8.1
- laravel: 12.*
php: 8.0
- laravel: 11.*
php: 8.1
- laravel: 11.*
Expand Down Expand Up @@ -50,7 +56,7 @@ jobs:

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:>=2.62.1" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:>=2.72.6" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Execute tests
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
],
"require": {
"php": "^8.0",
"illuminate/contracts": "^8.0|^9.0|^10.0|^11.0",
"illuminate/encryption": "^8.0|^9.0|^10.0|^11.0",
"illuminate/http": "^8.0|^9.0|^10.0|^11.0",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0",
"illuminate/validation": "^8.0|^9.0|^10.0|^11.0",
"illuminate/contracts": "^8.0|^9.0|^10.0|^11.0|^12.0",
"illuminate/encryption": "^8.0|^9.0|^10.0|^11.0|^12.0",
"illuminate/http": "^8.0|^9.0|^10.0|^11.0|^12.0",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0|^12.0",
"illuminate/validation": "^8.0|^9.0|^10.0|^11.0|^12.0",
"nesbot/carbon": "^2.0|^3.0",
"spatie/laravel-package-tools": "^1.9",
"symfony/http-foundation": "^5.1.2|^6.0|^7.0"
},
"require-dev": {
"livewire/livewire": "^2.10|^3.0",
"orchestra/testbench": "^6.23|^7.0|^8.0|^9.0",
"pestphp/pest-plugin-livewire": "^1.0|^2.1",
"phpunit/phpunit": "^9.6|^10.5",
"orchestra/testbench": "^6.23|^7.0|^8.0|^9.0|^10.0",
"pestphp/pest-plugin-livewire": "^1.0|^2.1|^3.0",
"phpunit/phpunit": "^9.6|^10.5|^11.5",
"spatie/pest-plugin-snapshots": "^1.1|^2.1",
"spatie/phpunit-snapshot-assertions": "^4.2|^5.1",
"spatie/test-time": "^1.2.1"
Expand Down
11 changes: 6 additions & 5 deletions tests/HoneypotLivewireComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
->call('submit')
->assertOk();

it('works if honeypot is disabled')
->tap(fn () => config()->set('honeypot.enabled', false))
->livewire(LivewireHoneypotConfiguredComponent::class)
->call('submit')
->assertOk();
it('works if honeypot is disabled', function () {
config()->set('honeypot.enabled', false);
$this->livewire(LivewireHoneypotConfiguredComponent::class)
->call('submit')
->assertOk();
});

test('permission denied if request is done too early', function () {
Event::fake();
Expand Down
22 changes: 11 additions & 11 deletions tests/HoneypotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
expect(app(Honeypot::class)->toArray()['enabled'])->toBeTrue();
});

test('honeypot setup returns enabled false if false is in config')
->tap(fn () => config()->set('honeypot.enabled', false))
->expect(fn () => app(Honeypot::class)->toArray()['enabled'])
->toBeFalse();
test('honeypot setup returns enabled false if false is in config', function () {
config()->set('honeypot.enabled', false);
expect(app(Honeypot::class)->toArray()['enabled'])
->toBeFalse();
});

test('honeypot setup returns correct `name_field_name` when randomize name field name is `false`')
->tap(function () {
config()->set('honeypot.name_field_name', 'test_field');
config()->set('honeypot.randomize_name_field_name', false);
})
->expect(fn () => app(Honeypot::class)->toArray()['nameFieldName'])
->toEqual('test_field');
test('honeypot setup returns correct `name_field_name` when randomize name field name is `false`', function () {
config()->set('honeypot.name_field_name', 'test_field');
config()->set('honeypot.randomize_name_field_name', false);
expect(app(Honeypot::class)->toArray()['nameFieldName'])
->toEqual('test_field');
});

test(
'honeypot setup returns correct `name_field_name` when randomize name field name is `true`',
Expand Down
46 changes: 25 additions & 21 deletions tests/ProtectAgainstSpamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,31 @@
})->middleware(ProtectAgainstSpam::class);
});

test('requests that not use the honeypot fields succeed without random name')
->tap(fn () => config()->set('honeypot.randomize_name_field_name', false))
->post('test')
->assertPassedSpamProtection();

test('requests that do not use the honeypot fields succeed with random name')
->tap(fn () => config()->set('honeypot.randomize_name_field_name', true))
->post('test')
->assertPassedSpamProtection();

test('requests that do not use the honeypot fields do not succeed without random name when missing fields enabled')
->tap(fn () => config()->set('honeypot.randomize_name_field_name', false))
->tap(fn () => config()->set('honeypot.honeypot_fields_required_for_all_forms', true))
->post('test')
->assertDidNotPassSpamProtection();

test('requests that do not use the honeypot fields do not succeed with random name when missing fields enabled')
->tap(fn () => config()->set('honeypot.randomize_name_field_name', true))
->tap(fn () => config()->set('honeypot.honeypot_fields_required_for_all_forms', true))
->post('test')
->assertDidNotPassSpamProtection();
test('requests that not use the honeypot fields succeed without random name', function () {
config()->set('honeypot.randomize_name_field_name', false);
$this->post('test')
->assertPassedSpamProtection();
});

test('requests that do not use the honeypot fields succeed with random name', function () {
config()->set('honeypot.randomize_name_field_name', true);
$this->post('test')
->assertPassedSpamProtection();
});

test('requests that do not use the honeypot fields do not succeed without random name when missing fields enabled', function () {
config()->set('honeypot.randomize_name_field_name', false);
config()->set('honeypot.honeypot_fields_required_for_all_forms', true);
$this->post('test')
->assertDidNotPassSpamProtection();
});

test('requests that do not use the honeypot fields do not succeed with random name when missing fields enabled', function () {
config()->set('honeypot.randomize_name_field_name', true);
config()->set('honeypot.honeypot_fields_required_for_all_forms', true);
$this->post('test')
->assertDidNotPassSpamProtection();
});

test('requests that post an empty value for the honeypot name field do succeed', function () {
$nameField = config('honeypot.name_field_name');
Expand Down

0 comments on commit dab247a

Please sign in to comment.