From 5f42c7040738bd1fcdc243267274290da670e1a9 Mon Sep 17 00:00:00 2001 From: Mostafa Maklad Date: Sun, 15 May 2022 21:08:43 +0300 Subject: [PATCH] release support for laravel 9 --- CHANGELOG.md | 2 +- composer.json | 2 +- tests/TestCase.php | 40 ++++++++++++++++++++++------------------ tests/TestHelper.php | 3 ++- tests/TestSeeder.php | 10 ++++++---- 5 files changed, 32 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96bb5c4..29c4857 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All Notable changes to `laravel-permission-mongodb` will be documented in this file. -## 4.0.0 - 2022-02-21 +## 4.0.0 - 2022-05-15 ### Added - Support of Laravel 9.x diff --git a/composer.json b/composer.json index dc0f15b..aa523eb 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ } ], "require": { - "php": "^8.0.2", + "php": "^8.0", "illuminate/auth": "^9.0", "illuminate/container": "^9.0", "illuminate/contracts": "^9.0", diff --git a/tests/TestCase.php b/tests/TestCase.php index af5ee00..0d528bf 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -26,8 +26,8 @@ abstract class TestCase extends Orchestra */ public function tearDown(): void { - User::truncate(); - Admin::truncate(); + User::query()->truncate(); + Admin::query()->truncate(); $this->app[Role::class]::truncate(); $this->app[Permission::class]::truncate(); } @@ -53,12 +53,12 @@ public function setUp(): void $this->reloadPermissions(); $this->testUser = User::first(); - $this->testUserRole = \app(\config('permission.models.role'))->where('name', 'testRole')->first(); - $this->testUserPermission = \app(\config('permission.models.permission'))->where('name', 'edit-articles')->first(); + $this->testUserRole = app(config('permission.models.role'))->where('name', 'testRole')->first(); + $this->testUserPermission = app(config('permission.models.permission'))->where('name', 'edit-articles')->first(); $this->testAdmin = Admin::first(); - $this->testAdminRole = \app(\config('permission.models.role'))->where('name', 'testAdminRole')->first(); - $this->testAdminPermission = \app(\config('permission.models.permission'))->where('name', 'admin-permission')->first(); + $this->testAdminRole = app(config('permission.models.role'))->where('name', 'testAdminRole')->first(); + $this->testAdminPermission = app(config('permission.models.permission'))->where('name', 'admin-permission')->first(); $this->clearLogTestHandler(); @@ -70,7 +70,8 @@ public function setUp(): void * * @return array */ - protected function getPackageProviders($app): array { + protected function getPackageProviders($app): array + { return [ PermissionServiceProvider::class, MongodbServiceProvider::class, @@ -110,11 +111,11 @@ protected function getEnvironmentSetUp($app) * * @return bool */ - protected function reloadPermissions() + protected function reloadPermissions(): bool { - \app(PermissionRegistrar::class)->forgetCachedPermissions(); + app(PermissionRegistrar::class)->forgetCachedPermissions(); - return \app(PermissionRegistrar::class)->registerPermissions(); + return app(PermissionRegistrar::class)->registerPermissions(); } /** @@ -135,7 +136,7 @@ public function refreshTestAdmin() protected function clearLogTestHandler() { - \collect($this->app['log']->getLogger()->getHandlers())->filter(function ($handler) { + collect($this->app['log']->getLogger()->getHandlers())->filter(function ($handler) { return $handler instanceof TestHandler; })->first()->clear(); } @@ -156,21 +157,23 @@ protected function assertLogged($message, $level) * * @return bool */ - protected function hasLog($message, $level): bool { - return \collect($this->app['log']->getLogger()->getHandlers())->filter(function ($handler) use ( - $message, - $level - ) { + protected function hasLog($message, $level): bool + { + return collect($this->app['log']->getLogger()->getHandlers())->filter(function ($handler) use ( + $message, + $level + ) { return $handler instanceof TestHandler && $handler->hasRecordThatContains($message, $level); })->count() > 0; } /** * @param $message + * @param $level */ protected function assertLogMessage($message, $level) { - if (\config('permission.log_registration_exception')) { + if (config('permission.log_registration_exception')) { $this->assertLogged($message, $level); } else { $this->assertNotLogged($message, $level); @@ -179,10 +182,11 @@ protected function assertLogMessage($message, $level) /** * @param $message + * @param $role_permission */ protected function assertShowPermission($message, $role_permission) { - if (\config('permission.display_permission_in_exception')) { + if (config('permission.display_permission_in_exception')) { $this->assertContains($role_permission, $message); } else { $this->assertStringNotContainsString($role_permission, $message); diff --git a/tests/TestHelper.php b/tests/TestHelper.php index 1aa0971..751b164 100644 --- a/tests/TestHelper.php +++ b/tests/TestHelper.php @@ -18,7 +18,8 @@ class TestHelper * * @return int */ - public function testMiddleware(string $middleware, object $parameter): int { + public function testMiddleware(string $middleware, object $parameter): int + { try { return $middleware->handle(new Request(), function () { return (new Response())->setContent(''); diff --git a/tests/TestSeeder.php b/tests/TestSeeder.php index fa134bd..21e965c 100644 --- a/tests/TestSeeder.php +++ b/tests/TestSeeder.php @@ -7,18 +7,21 @@ use Maklad\Permission\Models\Permission; use Maklad\Permission\Models\Role; -class TestSeeder extends Seeder { +class TestSeeder extends Seeder +{ private Application $app; - public function __construct(Application $app) { + public function __construct(Application $app) + { $this->app = $app; } /** * Run the database seeds. */ - public function run() { + public function run() + { User::create(['email' => 'test@user.com']); Admin::create(['email' => 'admin@user.com']); $this->app[Role::class]->create(['name' => 'testRole']); @@ -29,5 +32,4 @@ public function run() { $this->app[Permission::class]->create(['name' => 'edit-categories']); $this->app[Permission::class]->create(['name' => 'admin-permission', 'guard_name' => 'admin']); } - }