From 02e5b3c62f3a4ca95105c9abfd92910a2011d76e Mon Sep 17 00:00:00 2001 From: KieranLProctor Date: Thu, 23 May 2024 18:23:50 +0100 Subject: [PATCH 01/20] feat: added uuid compatibility --- .phpunit.cache/test-results | 2 +- config/config.php | 11 +++++++++++ database/migrations/create_bans_table.php | 4 +--- phpunit.xml.dist | 2 +- src/Banhammer.php | 4 ++-- src/BanhammerServiceProvider.php | 10 ++++------ src/Events/ModelWasBanned.php | 3 +-- src/IP.php | 8 ++++---- src/Observers/BanObserver.php | 8 ++++---- src/Traits/Bannable.php | 2 +- 10 files changed, 30 insertions(+), 24 deletions(-) diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results index 72ac2cc..9bb82c8 100644 --- a/.phpunit.cache/test-results +++ b/.phpunit.cache/test-results @@ -1 +1 @@ -{"version":1,"defects":[],"times":{"Mchev\\Banhammer\\Tests\\Unit\\IPBannedMiddlewareTest::it_blocks_the_banned_ip":0.002,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_with_metas":0.003,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_unbanned":0.003,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_banned":0.003,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_multiple_ip_are_banned":0.002,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_can_be_created":0.05,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_from_non_blocked_country":0.001,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_blocks_request_from_blocked_country":0.001,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_when_cache_is_present":0.007,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_when_country_check_fails":0.023}} \ No newline at end of file +{"version":1,"defects":{"Mchev\\Banhammer\\Tests\\Unit\\IPBannedMiddlewareTest::it_blocks_the_banned_ip":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_banned":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_with_metas":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_multiple_ip_are_banned":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_can_be_created":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_unbanned":8},"times":{"Mchev\\Banhammer\\Tests\\Unit\\IPBannedMiddlewareTest::it_blocks_the_banned_ip":0.001,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_with_metas":0,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_unbanned":0,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_banned":0.021,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_multiple_ip_are_banned":0,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_can_be_created":0,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_from_non_blocked_country":0.007,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_blocks_request_from_blocked_country":0.001,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_when_cache_is_present":0,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_when_country_check_fails":0.006}} \ No newline at end of file diff --git a/config/config.php b/config/config.php index 200ff27..c84b709 100644 --- a/config/config.php +++ b/config/config.php @@ -14,6 +14,17 @@ 'table' => 'bans', + /* + |-------------------------------------------------------------------------- + | Model Name + |-------------------------------------------------------------------------- + | + | Specify the model which you want to use as your Ban model. + | + */ + + 'model' => \Mchev\Banhammer\Models\Ban::class, + /* |-------------------------------------------------------------------------- | Where to Redirect Banned Users diff --git a/database/migrations/create_bans_table.php b/database/migrations/create_bans_table.php index 6b75882..0ce7977 100644 --- a/database/migrations/create_bans_table.php +++ b/database/migrations/create_bans_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. */ @@ -20,7 +19,6 @@ public function up(): void $table->timestamp('expired_at')->nullable(); $table->softDeletes(); $table->timestamps(); - $table->index('ip'); $table->index('expired_at'); }); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0bc1b47..3e30d06 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ - + tests diff --git a/src/Banhammer.php b/src/Banhammer.php index 3c25c63..f2f1b02 100644 --- a/src/Banhammer.php +++ b/src/Banhammer.php @@ -9,12 +9,12 @@ class Banhammer { public static function unbanExpired(): void { - Ban::expired()->delete(); + config('ban.model')::expired()->delete(); Cache::put('banned-ips', IP::banned()->pluck('ip')->toArray()); } public static function clear(): void { - Ban::onlyTrashed()->forceDelete(); + config('ban.model')::onlyTrashed()->forceDelete(); } } diff --git a/src/BanhammerServiceProvider.php b/src/BanhammerServiceProvider.php index 6bda4c1..babf3f3 100644 --- a/src/BanhammerServiceProvider.php +++ b/src/BanhammerServiceProvider.php @@ -21,9 +21,7 @@ class BanhammerServiceProvider extends ServiceProvider */ public function boot(): void { - $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); - - Ban::observe(BanObserver::class); + config('ban.model')::observe(BanObserver::class); $router = $this->app->make(Router::class); $router->aliasMiddleware('auth.banned', AuthBanned::class); @@ -41,9 +39,9 @@ public function boot(): void ], 'banhammer-config'); // Publishing migrations - // $this->publishes([ - // __DIR__.'/../database/migrations' => database_path('migrations'), - // ], 'banhammer-migrations'); + $this->publishes([ + __DIR__.'/../database/migrations' => database_path('migrations'), + ], 'banhammer-migrations'); // Registering package commands. $this->commands([ diff --git a/src/Events/ModelWasBanned.php b/src/Events/ModelWasBanned.php index 8c51193..638ba01 100644 --- a/src/Events/ModelWasBanned.php +++ b/src/Events/ModelWasBanned.php @@ -3,11 +3,10 @@ namespace Mchev\Banhammer\Events; use Illuminate\Contracts\Queue\ShouldQueue; -use Mchev\Banhammer\Models\Ban; class ModelWasBanned implements ShouldQueue { - public function __construct(public $model, public Ban $ban) + public function __construct(public $model, public $ban) { } } diff --git a/src/IP.php b/src/IP.php index d4bd12b..7bde569 100644 --- a/src/IP.php +++ b/src/IP.php @@ -14,7 +14,7 @@ public static function ban(string|array $ips, array $metas = [], string $date = foreach ((array) $ips as $ip) { if (! in_array($ip, $bannedIps)) { - Ban::create([ + config('ban.model')::create([ 'ip' => $ip, 'metas' => count($metas) ? $metas : null, 'expired_at' => $date, @@ -26,20 +26,20 @@ public static function ban(string|array $ips, array $metas = [], string $date = public static function unban(string|array $ips): void { $ips = (array) $ips; - Ban::whereIn('ip', $ips)->delete(); + config('ban.model')::whereIn('ip', $ips)->delete(); Cache::put('banned-ips', self::banned()->pluck('ip')->toArray()); } public static function isBanned(string $ip): bool { - return Ban::where('ip', $ip) + return config('ban.model')::where('ip', $ip) ->notExpired() ->exists(); } public static function banned(): Builder { - return Ban::whereNotNull('ip') + return config('ban.model')::whereNotNull('ip') ->with('createdBy') ->notExpired(); } diff --git a/src/Observers/BanObserver.php b/src/Observers/BanObserver.php index 5923ecb..d71fcd6 100644 --- a/src/Observers/BanObserver.php +++ b/src/Observers/BanObserver.php @@ -10,7 +10,7 @@ class BanObserver { - public function creating(Ban $ban): void + public function creating($ban): void { $user = auth()->user(); if ($user && is_null($ban->created_by_type) && is_null($ban->created_by_id)) { @@ -21,19 +21,19 @@ public function creating(Ban $ban): void } } - public function created(Ban $ban): void + public function created($ban): void { event(new ModelWasBanned($ban->bannable(), $ban)); $this->updateCachedIps($ban); } - public function deleted(Ban $ban): void + public function deleted($ban): void { event(new ModelWasUnbanned($ban->bannable())); $this->updateCachedIps($ban); } - public function updateCachedIps(Ban $ban): void + public function updateCachedIps($ban): void { if ($ban->ip) { Cache::put('banned-ips', IP::banned()->pluck('ip')->unique()->toArray()); diff --git a/src/Traits/Bannable.php b/src/Traits/Bannable.php index 4b6f95f..6b57c9b 100644 --- a/src/Traits/Bannable.php +++ b/src/Traits/Bannable.php @@ -13,7 +13,7 @@ trait Bannable */ public function bans(): MorphMany { - return $this->morphMany(Ban::class, 'bannable'); + return $this->morphMany(config('ban.model'), 'bannable'); } /** From 653780ed7c4a17e6dffa20ead6e9a1a968830832 Mon Sep 17 00:00:00 2001 From: KieranLProctor Date: Thu, 23 May 2024 18:27:41 +0100 Subject: [PATCH 02/20] fix: added composer repository --- composer.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c5b3fd2..faa0aab 100644 --- a/composer.json +++ b/composer.json @@ -55,5 +55,12 @@ } }, "minimum-stability": "dev", - "prefer-stable": true + "prefer-stable": true, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/KieranLProctor/banhammer", + "no-api": true + } + ] } From 8015685034dc4a3a4a93008c021c28d41040dda8 Mon Sep 17 00:00:00 2001 From: KieranLProctor Date: Thu, 23 May 2024 18:30:17 +0100 Subject: [PATCH 03/20] fix: last commit was wrong project --- composer.json | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/composer.json b/composer.json index faa0aab..c5b3fd2 100644 --- a/composer.json +++ b/composer.json @@ -55,12 +55,5 @@ } }, "minimum-stability": "dev", - "prefer-stable": true, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/KieranLProctor/banhammer", - "no-api": true - } - ] + "prefer-stable": true } From d95632f7e66509b5e8474ed5fddf36ebdbe3a137 Mon Sep 17 00:00:00 2001 From: KieranLProctor Date: Fri, 24 May 2024 01:36:39 +0100 Subject: [PATCH 04/20] refactor: updated the documentation --- CHANGELOG.md | 4 ++++ README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91c6c09..23e11c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `banhammer` will be documented in this file. +## v2.3.0 - 2024-05-24 + +- Added UUID support + ## v2.2.0 - 2024-03-12 - Laravel 11 support diff --git a/README.md b/README.md index 809f660..5f5a094 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,12 @@ php artisan vendor:publish --tag="banhammer-config" It is possible to define the table name and the fallback_url in the `config/ban.php` file. +You can publish the migration files with: + +```bash +php artisan vendor:publish --tag="banhammer-migrations" +``` + ## Upgrading To 2.0 from 1.x To upgrade to Banhammer version 2.0, follow these simple steps: @@ -108,6 +114,45 @@ class User extends Authenticatable ``` > You can add the Bannable trait on as many models as you want (Team, Group, User, etc.). +## Using UUIDs + +To use UUIDs make sure you publish and edit the migration files. + +You will then need to make a model that extends `Mchev\Banhammer\Models\Ban`: + +```php + Although most of the methods needed are already available from the base model, you can add any additional methods here. + +Finally update the published `ban.php` config file to load the model you have created: + +```diff + /* + |-------------------------------------------------------------------------- + | Model Name + |-------------------------------------------------------------------------- + | + | Specify the model which you want to use as your Ban model. + | + */ + +- 'model' => \Mchev\Banhammer\Models\Ban::class, ++ 'model' => \App\Models\YouBanClass::class, +``` + ### Ban / Unban Simple ban From 98542acc06b1610ab90177050b3ac72d9fd0b34b Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 07:47:26 +0200 Subject: [PATCH 05/20] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 5f5a094..9db0cd4 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,11 @@ class User extends Authenticatable To use UUIDs make sure you publish and edit the migration files. +```diff +- $table->id(); ++ $table->uuid('id'); +``` + You will then need to make a model that extends `Mchev\Banhammer\Models\Ban`: ```php From fbc1db5285d05f5a1ee0f6d8c2657422fa68f88d Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 08:36:28 +0200 Subject: [PATCH 06/20] Update README.md --- README.md | 118 +++++++++++++++++++++++++++--------------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 9db0cd4..627b054 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,14 @@ Banned models can have an expiration date and will be automatically unbanned usi - [Scheduler](#scheduler) - [Events](#events) - [Miscellaneous](#misc) -6. [Testing](#testing) -7. [Changelog](#changelog) -8. [Roadmap / Todo](#roadmap--todo) -9. [Contributing](#contributing) -10. [Security Vulnerabilities](#security-vulnerabilities) -11. [Credits](#credits) -12. [License](#license) +6. [UUIDs](#uuids) +7. [Testing](#testing) +8. [Changelog](#changelog) +9. [Roadmap / Todo](#roadmap--todo) +10. [Contributing](#contributing) +11. [Security Vulnerabilities](#security-vulnerabilities) +12. [Credits](#credits) +13. [License](#license) ## Version Compatibility @@ -48,9 +49,12 @@ You can install the package via composer: composer require mchev/banhammer ``` -Then run the migrations with: +Then publish and run the migrations with: + +> To use UUIDs see [UUIDs](#uuids) ```bash +php artisan vendor:publish --tag="banhammer-migrations" php artisan migrate ``` @@ -60,13 +64,7 @@ You can publish the config file with: php artisan vendor:publish --tag="banhammer-config" ``` -It is possible to define the table name and the fallback_url in the `config/ban.php` file. - -You can publish the migration files with: - -```bash -php artisan vendor:publish --tag="banhammer-migrations" -``` +It is possible to define the table name, the model and the fallback_url in the `config/ban.php` file. ## Upgrading To 2.0 from 1.x @@ -114,50 +112,6 @@ class User extends Authenticatable ``` > You can add the Bannable trait on as many models as you want (Team, Group, User, etc.). -## Using UUIDs - -To use UUIDs make sure you publish and edit the migration files. - -```diff -- $table->id(); -+ $table->uuid('id'); -``` - -You will then need to make a model that extends `Mchev\Banhammer\Models\Ban`: - -```php - Although most of the methods needed are already available from the base model, you can add any additional methods here. - -Finally update the published `ban.php` config file to load the model you have created: - -```diff - /* - |-------------------------------------------------------------------------- - | Model Name - |-------------------------------------------------------------------------- - | - | Specify the model which you want to use as your Ban model. - | - */ - -- 'model' => \Mchev\Banhammer\Models\Ban::class, -+ 'model' => \App\Models\YouBanClass::class, -``` - ### Ban / Unban Simple ban @@ -387,6 +341,52 @@ Or you can use the command: php artisan banhammer:clear ``` +## UUIDs + +To use UUIDs make sure you publish and edit the migration files. + +```bash +php artisan vendor:publish --tag="banhammer-migrations" +``` + +```diff +- $table->id(); ++ $table->uuid('id'); +``` + +You will then need to make a model that extends `Mchev\Banhammer\Models\Ban`: + +```php + Although most of the methods needed are already available from the base model, you can add any additional methods here. + +Finally update the published `ban.php` config file to load the model you have created: + +```diff + /* + |-------------------------------------------------------------------------- + | Model Name + |-------------------------------------------------------------------------- + | + | Specify the model which you want to use as your Ban model. + | + */ + +- 'model' => \Mchev\Banhammer\Models\Ban::class, ++ 'model' => \App\Models\YouBanClass::class, +``` + ## Testing ```bash From f72f7d2b71cc35b82ea521a2dae5c801905a8c76 Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 08:57:57 +0200 Subject: [PATCH 07/20] Updating TestCase to publish migrations before running --- .phpunit.cache/test-results | 2 +- tests/TestCase.php | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results index 9bb82c8..f83af4e 100644 --- a/.phpunit.cache/test-results +++ b/.phpunit.cache/test-results @@ -1 +1 @@ -{"version":1,"defects":{"Mchev\\Banhammer\\Tests\\Unit\\IPBannedMiddlewareTest::it_blocks_the_banned_ip":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_banned":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_with_metas":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_multiple_ip_are_banned":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_can_be_created":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_unbanned":8},"times":{"Mchev\\Banhammer\\Tests\\Unit\\IPBannedMiddlewareTest::it_blocks_the_banned_ip":0.001,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_with_metas":0,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_unbanned":0,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_banned":0.021,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_multiple_ip_are_banned":0,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_can_be_created":0,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_from_non_blocked_country":0.007,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_blocks_request_from_blocked_country":0.001,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_when_cache_is_present":0,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_when_country_check_fails":0.006}} \ No newline at end of file +{"version":1,"defects":{"Mchev\\Banhammer\\Tests\\Unit\\IPBannedMiddlewareTest::it_blocks_the_banned_ip":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_banned":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_with_metas":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_multiple_ip_are_banned":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_can_be_created":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_unbanned":8},"times":{"Mchev\\Banhammer\\Tests\\Unit\\IPBannedMiddlewareTest::it_blocks_the_banned_ip":0.002,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_with_metas":0.003,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_unbanned":0.002,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_banned":0.002,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_multiple_ip_are_banned":0.013,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_can_be_created":0.001,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_from_non_blocked_country":0.008,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_blocks_request_from_blocked_country":0.021,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_when_cache_is_present":0.001,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_when_country_check_fails":0.001}} \ No newline at end of file diff --git a/tests/TestCase.php b/tests/TestCase.php index fe7d3f3..744d4df 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,6 +7,13 @@ abstract class TestCase extends Orchestra { + + protected function setUp(): void + { + parent::setUp(); + $this->publishAndRunMigrations(); + } + protected function getEnvironmentSetUp($app): void { // Load the .env file @@ -21,4 +28,18 @@ protected function getPackageProviders($app): array 'Mchev\Banhammer\BanhammerServiceProvider', ]; } + + protected function publishAndRunMigrations(): void + { + // Publish the package migrations + $this->artisan('vendor:publish', [ + '--provider' => 'Mchev\Banhammer\BanhammerServiceProvider', + '--tag' => 'banhammer-migrations', + '--force' => true, + ])->run(); + + // Run the migrations + $this->artisan('migrate', ['--database' => 'testing'])->run(); + } + } From fc5f1e4b7791697b5c874dae2770b132a5fc61b3 Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 09:31:20 +0200 Subject: [PATCH 08/20] Updated workflow --- .github/workflows/run-tests.yml | 4 ++++ .gitignore | 1 + .phpunit.cache/test-results | 1 - tests/TestCase.php | 23 +---------------------- 4 files changed, 6 insertions(+), 23 deletions(-) delete mode 100644 .phpunit.cache/test-results diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 6606896..5dfd1c4 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -56,5 +56,9 @@ jobs: composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:>=2.62.1" --no-interaction --no-update composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress + - name: Publish migrations + run: | + php artisan vendor:publish --provider="Mchev\Banhammer\BanhammerServiceProvider" --tag="banhammer-migrations" --force + - name: Execute tests run: vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index 83c9b9f..8054c8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .idea .phpunit.result.cache +.phpunit.cache build composer.lock coverage diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results deleted file mode 100644 index f83af4e..0000000 --- a/.phpunit.cache/test-results +++ /dev/null @@ -1 +0,0 @@ -{"version":1,"defects":{"Mchev\\Banhammer\\Tests\\Unit\\IPBannedMiddlewareTest::it_blocks_the_banned_ip":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_banned":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_with_metas":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_multiple_ip_are_banned":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_can_be_created":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_unbanned":8},"times":{"Mchev\\Banhammer\\Tests\\Unit\\IPBannedMiddlewareTest::it_blocks_the_banned_ip":0.002,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_with_metas":0.003,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_unbanned":0.002,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_banned":0.002,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_multiple_ip_are_banned":0.013,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_can_be_created":0.001,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_from_non_blocked_country":0.008,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_blocks_request_from_blocked_country":0.021,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_when_cache_is_present":0.001,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_when_country_check_fails":0.001}} \ No newline at end of file diff --git a/tests/TestCase.php b/tests/TestCase.php index 744d4df..bb83b22 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,13 +7,6 @@ abstract class TestCase extends Orchestra { - - protected function setUp(): void - { - parent::setUp(); - $this->publishAndRunMigrations(); - } - protected function getEnvironmentSetUp($app): void { // Load the .env file @@ -28,18 +21,4 @@ protected function getPackageProviders($app): array 'Mchev\Banhammer\BanhammerServiceProvider', ]; } - - protected function publishAndRunMigrations(): void - { - // Publish the package migrations - $this->artisan('vendor:publish', [ - '--provider' => 'Mchev\Banhammer\BanhammerServiceProvider', - '--tag' => 'banhammer-migrations', - '--force' => true, - ])->run(); - - // Run the migrations - $this->artisan('migrate', ['--database' => 'testing'])->run(); - } - -} +} \ No newline at end of file From a174a0f73c9080b03b1474088f0ff2a4cf92ff11 Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 09:36:31 +0200 Subject: [PATCH 09/20] Trying to fix tests --- .github/workflows/run-tests.yml | 4 ---- tests/TestCase.php | 11 +++++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 5dfd1c4..6606896 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -56,9 +56,5 @@ jobs: composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:>=2.62.1" --no-interaction --no-update composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress - - name: Publish migrations - run: | - php artisan vendor:publish --provider="Mchev\Banhammer\BanhammerServiceProvider" --tag="banhammer-migrations" --force - - name: Execute tests run: vendor/bin/phpunit diff --git a/tests/TestCase.php b/tests/TestCase.php index bb83b22..25ed42b 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -21,4 +21,15 @@ protected function getPackageProviders($app): array 'Mchev\Banhammer\BanhammerServiceProvider', ]; } + + /** + * run package database migrations. + */ + protected function setUp(): void + { + parent::setUp(); + $this->loadMigrationsFrom(__DIR__ . '/migrations'); + $this->loadMigrationsFrom(dirname(__DIR__) . '/migrations'); + } + } \ No newline at end of file From 1600f4073264373043633ffde53b6ae2de3c7da2 Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 09:41:57 +0200 Subject: [PATCH 10/20] Trying to fix tests --- tests/TestCase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 25ed42b..8f6d247 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -28,8 +28,8 @@ protected function getPackageProviders($app): array protected function setUp(): void { parent::setUp(); - $this->loadMigrationsFrom(__DIR__ . '/migrations'); - $this->loadMigrationsFrom(dirname(__DIR__) . '/migrations'); + $this->loadMigrationsFrom(__DIR__ . '../migrations'); + $this->loadMigrationsFrom(dirname(__DIR__) . '../migrations'); } } \ No newline at end of file From 4e499b4ee83fd18f605d57982e3b81c7c4d33c6e Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 09:48:41 +0200 Subject: [PATCH 11/20] Change migrations path --- tests/TestCase.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 8f6d247..2371609 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -23,13 +23,14 @@ protected function getPackageProviders($app): array } /** - * run package database migrations. + * Run package database migrations. */ protected function setUp(): void { parent::setUp(); - $this->loadMigrationsFrom(__DIR__ . '../migrations'); - $this->loadMigrationsFrom(dirname(__DIR__) . '../migrations'); + $this->loadMigrationsFrom([ + '--path' => realpath(__DIR__.'/../database/migrations'), + ]); } } \ No newline at end of file From a6abf53da574e4d049ef6dd44bad48dbf626b99a Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 10:16:33 +0200 Subject: [PATCH 12/20] RefreshDatabase on TestCase --- CHANGELOG.md | 5 +++-- tests/TestCase.php | 8 +++++--- tests/Unit/BlockByCountryMiddlewareTest.php | 1 + tests/Unit/IPBanTest.php | 2 -- tests/Unit/IPBannedMiddlewareTest.php | 2 -- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23e11c4..b13ac11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ All notable changes to `banhammer` will be documented in this file. ## v2.3.0 - 2024-05-24 -- Added UUID support +- Added UUID support @KieranLProctor +- Added Configurable model support @KieranLProctor ## v2.2.0 - 2024-03-12 @@ -26,7 +27,7 @@ This new version introduce the block by country middleware ## v1.2.0 - 2023-03-02 -- Adding Metas (cutom properties) to bans. +- Adding Metas (cutom properties) to bans. @mepsd - You may have to run `php artisan migrate` if you are upgrading from v1.1.x ## v1.1.5 - 2023-02-21 diff --git a/tests/TestCase.php b/tests/TestCase.php index 2371609..a993074 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,10 +3,14 @@ namespace Mchev\Banhammer\Tests; use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables; +use Illuminate\Foundation\Testing\RefreshDatabase; use Orchestra\Testbench\TestCase as Orchestra; abstract class TestCase extends Orchestra { + + use RefreshDatabase; + protected function getEnvironmentSetUp($app): void { // Load the .env file @@ -28,9 +32,7 @@ protected function getPackageProviders($app): array protected function setUp(): void { parent::setUp(); - $this->loadMigrationsFrom([ - '--path' => realpath(__DIR__.'/../database/migrations'), - ]); + $this->loadMigrationsFrom(database_path('migrations')); } } \ No newline at end of file diff --git a/tests/Unit/BlockByCountryMiddlewareTest.php b/tests/Unit/BlockByCountryMiddlewareTest.php index 33cb479..f45be21 100644 --- a/tests/Unit/BlockByCountryMiddlewareTest.php +++ b/tests/Unit/BlockByCountryMiddlewareTest.php @@ -12,6 +12,7 @@ class BlockByCountryMiddlewareTest extends TestCase { + /** @var BlockByCountry */ private $middleware; diff --git a/tests/Unit/IPBanTest.php b/tests/Unit/IPBanTest.php index 19e1108..4835009 100644 --- a/tests/Unit/IPBanTest.php +++ b/tests/Unit/IPBanTest.php @@ -2,14 +2,12 @@ namespace Mchev\Banhammer\Tests\Unit; -use Illuminate\Foundation\Testing\RefreshDatabase; use Mchev\Banhammer\IP; use Mchev\Banhammer\Models\Ban; use Mchev\Banhammer\Tests\TestCase; class IPBanTest extends TestCase { - use RefreshDatabase; public $ip = '127.0.0.1'; diff --git a/tests/Unit/IPBannedMiddlewareTest.php b/tests/Unit/IPBannedMiddlewareTest.php index 024b314..a51b0ac 100644 --- a/tests/Unit/IPBannedMiddlewareTest.php +++ b/tests/Unit/IPBannedMiddlewareTest.php @@ -2,7 +2,6 @@ namespace Mchev\Banhammer\Tests\Unit; -use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Http\Request; use Mchev\Banhammer\Exceptions\BanhammerException; use Mchev\Banhammer\IP; @@ -11,7 +10,6 @@ class IPBannedMiddlewareTest extends TestCase { - use RefreshDatabase; /** @test */ public function it_blocks_the_banned_ip() From 68102e8b621596765e4063d99e1127a2c64aa832 Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 10:18:03 +0200 Subject: [PATCH 13/20] RefreshDatabase --- tests/TestCase.php | 3 --- tests/Unit/BlockByCountryMiddlewareTest.php | 3 +++ tests/Unit/IPBanTest.php | 2 ++ tests/Unit/IPBannedMiddlewareTest.php | 2 ++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index a993074..b4c7d32 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,14 +3,11 @@ namespace Mchev\Banhammer\Tests; use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables; -use Illuminate\Foundation\Testing\RefreshDatabase; use Orchestra\Testbench\TestCase as Orchestra; abstract class TestCase extends Orchestra { - use RefreshDatabase; - protected function getEnvironmentSetUp($app): void { // Load the .env file diff --git a/tests/Unit/BlockByCountryMiddlewareTest.php b/tests/Unit/BlockByCountryMiddlewareTest.php index f45be21..3bef508 100644 --- a/tests/Unit/BlockByCountryMiddlewareTest.php +++ b/tests/Unit/BlockByCountryMiddlewareTest.php @@ -4,6 +4,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Cache; +use Illuminate\Foundation\Testing\RefreshDatabase; use Mchev\Banhammer\Exceptions\BanhammerException; use Mchev\Banhammer\Middleware\BlockByCountry; use Mchev\Banhammer\Services\IpApiService; @@ -12,6 +13,8 @@ class BlockByCountryMiddlewareTest extends TestCase { + + use RefreshDatabase; /** @var BlockByCountry */ private $middleware; diff --git a/tests/Unit/IPBanTest.php b/tests/Unit/IPBanTest.php index 4835009..19e1108 100644 --- a/tests/Unit/IPBanTest.php +++ b/tests/Unit/IPBanTest.php @@ -2,12 +2,14 @@ namespace Mchev\Banhammer\Tests\Unit; +use Illuminate\Foundation\Testing\RefreshDatabase; use Mchev\Banhammer\IP; use Mchev\Banhammer\Models\Ban; use Mchev\Banhammer\Tests\TestCase; class IPBanTest extends TestCase { + use RefreshDatabase; public $ip = '127.0.0.1'; diff --git a/tests/Unit/IPBannedMiddlewareTest.php b/tests/Unit/IPBannedMiddlewareTest.php index a51b0ac..024b314 100644 --- a/tests/Unit/IPBannedMiddlewareTest.php +++ b/tests/Unit/IPBannedMiddlewareTest.php @@ -2,6 +2,7 @@ namespace Mchev\Banhammer\Tests\Unit; +use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Http\Request; use Mchev\Banhammer\Exceptions\BanhammerException; use Mchev\Banhammer\IP; @@ -10,6 +11,7 @@ class IPBannedMiddlewareTest extends TestCase { + use RefreshDatabase; /** @test */ public function it_blocks_the_banned_ip() From a074bea8d48d31dd36b4e5c2302f5b9a75de5570 Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 10:23:33 +0200 Subject: [PATCH 14/20] Pint --- database/migrations/create_bans_table.php | 3 ++- src/Banhammer.php | 1 - src/BanhammerServiceProvider.php | 7 +++---- src/Exceptions/BanhammerException.php | 2 +- src/IP.php | 3 +-- src/Observers/BanObserver.php | 1 - tests/TestCase.php | 6 ++---- tests/Unit/BlockByCountryMiddlewareTest.php | 3 +-- 8 files changed, 10 insertions(+), 16 deletions(-) diff --git a/database/migrations/create_bans_table.php b/database/migrations/create_bans_table.php index 0ce7977..99ff97e 100644 --- a/database/migrations/create_bans_table.php +++ b/database/migrations/create_bans_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ /** * Run the migrations. */ diff --git a/src/Banhammer.php b/src/Banhammer.php index f2f1b02..cdbbfa6 100644 --- a/src/Banhammer.php +++ b/src/Banhammer.php @@ -3,7 +3,6 @@ namespace Mchev\Banhammer; use Illuminate\Support\Facades\Cache; -use Mchev\Banhammer\Models\Ban; class Banhammer { diff --git a/src/BanhammerServiceProvider.php b/src/BanhammerServiceProvider.php index babf3f3..d80b76f 100644 --- a/src/BanhammerServiceProvider.php +++ b/src/BanhammerServiceProvider.php @@ -11,7 +11,6 @@ use Mchev\Banhammer\Middleware\BlockByCountry; use Mchev\Banhammer\Middleware\IPBanned; use Mchev\Banhammer\Middleware\LogoutBanned; -use Mchev\Banhammer\Models\Ban; use Mchev\Banhammer\Observers\BanObserver; class BanhammerServiceProvider extends ServiceProvider @@ -39,9 +38,9 @@ public function boot(): void ], 'banhammer-config'); // Publishing migrations - $this->publishes([ - __DIR__.'/../database/migrations' => database_path('migrations'), - ], 'banhammer-migrations'); + $this->publishes([ + __DIR__.'/../database/migrations' => database_path('migrations'), + ], 'banhammer-migrations'); // Registering package commands. $this->commands([ diff --git a/src/Exceptions/BanhammerException.php b/src/Exceptions/BanhammerException.php index 019a60a..21ad698 100644 --- a/src/Exceptions/BanhammerException.php +++ b/src/Exceptions/BanhammerException.php @@ -10,7 +10,7 @@ class BanhammerException extends HttpException { - public function __construct($message = null, Exception $previous = null, $code = 0) + public function __construct($message = null, ?Exception $previous = null, $code = 0) { parent::__construct(403, $message, $previous, [], $code); } diff --git a/src/IP.php b/src/IP.php index 7bde569..9794d20 100644 --- a/src/IP.php +++ b/src/IP.php @@ -4,11 +4,10 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Facades\Cache; -use Mchev\Banhammer\Models\Ban; class IP { - public static function ban(string|array $ips, array $metas = [], string $date = null): void + public static function ban(string|array $ips, array $metas = [], ?string $date = null): void { $bannedIps = self::getBannedIPsFromCache(); diff --git a/src/Observers/BanObserver.php b/src/Observers/BanObserver.php index d71fcd6..c429cb7 100644 --- a/src/Observers/BanObserver.php +++ b/src/Observers/BanObserver.php @@ -6,7 +6,6 @@ use Mchev\Banhammer\Events\ModelWasBanned; use Mchev\Banhammer\Events\ModelWasUnbanned; use Mchev\Banhammer\IP; -use Mchev\Banhammer\Models\Ban; class BanObserver { diff --git a/tests/TestCase.php b/tests/TestCase.php index b4c7d32..5d3a4c8 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,7 +7,6 @@ abstract class TestCase extends Orchestra { - protected function getEnvironmentSetUp($app): void { // Load the .env file @@ -29,7 +28,6 @@ protected function getPackageProviders($app): array protected function setUp(): void { parent::setUp(); - $this->loadMigrationsFrom(database_path('migrations')); + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); } - -} \ No newline at end of file +} diff --git a/tests/Unit/BlockByCountryMiddlewareTest.php b/tests/Unit/BlockByCountryMiddlewareTest.php index 3bef508..a884249 100644 --- a/tests/Unit/BlockByCountryMiddlewareTest.php +++ b/tests/Unit/BlockByCountryMiddlewareTest.php @@ -2,9 +2,9 @@ namespace Mchev\Banhammer\Tests\Unit; +use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Http\Request; use Illuminate\Support\Facades\Cache; -use Illuminate\Foundation\Testing\RefreshDatabase; use Mchev\Banhammer\Exceptions\BanhammerException; use Mchev\Banhammer\Middleware\BlockByCountry; use Mchev\Banhammer\Services\IpApiService; @@ -13,7 +13,6 @@ class BlockByCountryMiddlewareTest extends TestCase { - use RefreshDatabase; /** @var BlockByCountry */ From 91a10cb3885ac5711ea62e84234ebf0cabbcc355 Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 10:55:22 +0200 Subject: [PATCH 15/20] Changing publishable names --- README.md | 8 +++--- phpunit.xml.dist | 5 +--- phpunit.xml.dist.bak | 48 -------------------------------- src/BanhammerServiceProvider.php | 4 +-- tests/TestCase.php | 7 ++--- 5 files changed, 9 insertions(+), 63 deletions(-) delete mode 100644 phpunit.xml.dist.bak diff --git a/README.md b/README.md index 627b054..43f4256 100644 --- a/README.md +++ b/README.md @@ -54,14 +54,14 @@ Then publish and run the migrations with: > To use UUIDs see [UUIDs](#uuids) ```bash -php artisan vendor:publish --tag="banhammer-migrations" +php artisan vendor:publish --provider="Mchev\Banhammer\BanhammerServiceProvider" --tag="migrations" php artisan migrate ``` You can publish the config file with: ```bash -php artisan vendor:publish --tag="banhammer-config" +php artisan vendor:publish --provider="Mchev\Banhammer\BanhammerServiceProvider" --tag="config" ``` It is possible to define the table name, the model and the fallback_url in the `config/ban.php` file. @@ -90,7 +90,7 @@ composer update mchev/banhammer - Backup your previous configuration file located at `config/ban.php`. - Force republish the new configuration using the command: ```bash - php artisan vendor:publish --tag="banhammer-config" --force + php artisan vendor:publish --provider="Mchev\Banhammer\BanhammerServiceProvider" --tag="config" --force ``` - Review the new configuration file and make any necessary edits. @@ -346,7 +346,7 @@ php artisan banhammer:clear To use UUIDs make sure you publish and edit the migration files. ```bash -php artisan vendor:publish --tag="banhammer-migrations" +php artisan vendor:publish --provider="Mchev\Banhammer\BanhammerServiceProvider" --tag="migrations" ``` ```diff diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3e30d06..018b709 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,10 @@ - + tests - - - diff --git a/phpunit.xml.dist.bak b/phpunit.xml.dist.bak deleted file mode 100644 index c7b5079..0000000 --- a/phpunit.xml.dist.bak +++ /dev/null @@ -1,48 +0,0 @@ - - - - - tests - - - - - ./src - - - - - - - - - - - - - - - - - - - - diff --git a/src/BanhammerServiceProvider.php b/src/BanhammerServiceProvider.php index d80b76f..c665f96 100644 --- a/src/BanhammerServiceProvider.php +++ b/src/BanhammerServiceProvider.php @@ -35,12 +35,12 @@ public function boot(): void // Publishing the config. $this->publishes([ __DIR__.'/../config/config.php' => config_path('ban.php'), - ], 'banhammer-config'); + ], 'config'); // Publishing migrations $this->publishes([ __DIR__.'/../database/migrations' => database_path('migrations'), - ], 'banhammer-migrations'); + ], 'migrations'); // Registering package commands. $this->commands([ diff --git a/tests/TestCase.php b/tests/TestCase.php index 5d3a4c8..234c8b1 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -22,12 +22,9 @@ protected function getPackageProviders($app): array ]; } - /** - * Run package database migrations. - */ - protected function setUp(): void + protected function defineDatabaseMigrations() { - parent::setUp(); + $this->loadLaravelMigrations(); $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); } } From 7a35781b0efff2d2c4def7e886237e54b6b4c123 Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 11:13:01 +0200 Subject: [PATCH 16/20] Clean phpunit.xml.dist --- phpunit.xml.dist | 35 ++++++++++----------- tests/Unit/BlockByCountryMiddlewareTest.php | 2 -- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 018b709..bbed36a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,22 +1,21 @@ - - - - tests - - - - - - - - - - - - + + + + tests/Unit + + + tests/Feature + + + - ./src + src - + + + + + + diff --git a/tests/Unit/BlockByCountryMiddlewareTest.php b/tests/Unit/BlockByCountryMiddlewareTest.php index a884249..7215fd5 100644 --- a/tests/Unit/BlockByCountryMiddlewareTest.php +++ b/tests/Unit/BlockByCountryMiddlewareTest.php @@ -15,10 +15,8 @@ class BlockByCountryMiddlewareTest extends TestCase { use RefreshDatabase; - /** @var BlockByCountry */ private $middleware; - /** @var IpApiService|\Mockery\MockInterface */ private $ipApiService; protected function setUp(): void From 02cf2588800ba260e367ebee532f0cb97741b0a2 Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 11:15:39 +0200 Subject: [PATCH 17/20] Remove feature testsuite --- phpunit.xml.dist | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bbed36a..5514b4c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,9 +4,6 @@ tests/Unit - - tests/Feature - From d0dc7814cb9dd9a5ab2f7bce21e2ae876bc78674 Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 11:28:31 +0200 Subject: [PATCH 18/20] Update github workflow --- .github/workflows/run-tests.yml | 41 ++++++++++++++------------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 6606896..5d5ccf9 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -11,50 +11,43 @@ jobs: test: runs-on: ubuntu-latest strategy: - fail-fast: true + fail-fast: false matrix: php: [8.3, 8.2, 8.1, 8.0] - laravel: [11.*, 10.*, 9.*] + laravel: ["^11.0", "^10.0", "^9.0"] dependency-version: [prefer-lowest, prefer-stable] include: - - laravel: 11.* - testbench: ^9.0 - - laravel: 10.* - testbench: ^8.0 - - laravel: 9.* - testbench: ^7.0 + - laravel: "^11.0" + testbench: 9.* + - laravel: "^10.0" + testbench: 8.* + - laravel: "^9.0" + testbench: 7.* exclude: - - laravel: 9.* - php: 8.3 - - laravel: 10.* + - laravel: "^11.0" + php: 8.1 + - laravel: "^11.0" php: 8.0 - - laravel: 11.* + - laravel: "^10.0" php: 8.0 - - laravel: 11.* - php: 8.1 - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv coverage: none - - name: Setup problem matchers - run: | - echo "::add-matcher::${{ runner.tool_cache }}/php.json" - echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:>=2.62.1" --no-interaction --no-update - composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "symfony/console:>=4.3.4" "mockery/mockery:^1.3.2" "nesbot/carbon:>=2.62.1" --no-interaction --no-update + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction - name: Execute tests run: vendor/bin/phpunit From 733ca491f3d39afe469d18d43456f41a2b70c3ac Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 11:52:44 +0200 Subject: [PATCH 19/20] Not loading laravel migration --- tests/TestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 234c8b1..f46da50 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -24,7 +24,7 @@ protected function getPackageProviders($app): array protected function defineDatabaseMigrations() { - $this->loadLaravelMigrations(); + // $this->loadLaravelMigrations(); $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); } } From a1ba14c6e8660c948881de6a335a84734b08b8a5 Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 24 May 2024 12:08:56 +0200 Subject: [PATCH 20/20] Prefer stable only on dependency version --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 5d5ccf9..7605e6a 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -15,7 +15,7 @@ jobs: matrix: php: [8.3, 8.2, 8.1, 8.0] laravel: ["^11.0", "^10.0", "^9.0"] - dependency-version: [prefer-lowest, prefer-stable] + dependency-version: [prefer-stable] include: - laravel: "^11.0" testbench: 9.*