Skip to content

Commit 5f42c70

Browse files
committed
release support for laravel 9
1 parent bc1cf2c commit 5f42c70

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All Notable changes to `laravel-permission-mongodb` will be documented in this file.
44

5-
## 4.0.0 - 2022-02-21
5+
## 4.0.0 - 2022-05-15
66

77
### Added
88
- Support of Laravel 9.x

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131
],
3232
"require": {
33-
"php": "^8.0.2",
33+
"php": "^8.0",
3434
"illuminate/auth": "^9.0",
3535
"illuminate/container": "^9.0",
3636
"illuminate/contracts": "^9.0",

tests/TestCase.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ abstract class TestCase extends Orchestra
2626
*/
2727
public function tearDown(): void
2828
{
29-
User::truncate();
30-
Admin::truncate();
29+
User::query()->truncate();
30+
Admin::query()->truncate();
3131
$this->app[Role::class]::truncate();
3232
$this->app[Permission::class]::truncate();
3333
}
@@ -53,12 +53,12 @@ public function setUp(): void
5353
$this->reloadPermissions();
5454

5555
$this->testUser = User::first();
56-
$this->testUserRole = \app(\config('permission.models.role'))->where('name', 'testRole')->first();
57-
$this->testUserPermission = \app(\config('permission.models.permission'))->where('name', 'edit-articles')->first();
56+
$this->testUserRole = app(config('permission.models.role'))->where('name', 'testRole')->first();
57+
$this->testUserPermission = app(config('permission.models.permission'))->where('name', 'edit-articles')->first();
5858

5959
$this->testAdmin = Admin::first();
60-
$this->testAdminRole = \app(\config('permission.models.role'))->where('name', 'testAdminRole')->first();
61-
$this->testAdminPermission = \app(\config('permission.models.permission'))->where('name', 'admin-permission')->first();
60+
$this->testAdminRole = app(config('permission.models.role'))->where('name', 'testAdminRole')->first();
61+
$this->testAdminPermission = app(config('permission.models.permission'))->where('name', 'admin-permission')->first();
6262

6363
$this->clearLogTestHandler();
6464

@@ -70,7 +70,8 @@ public function setUp(): void
7070
*
7171
* @return array
7272
*/
73-
protected function getPackageProviders($app): array {
73+
protected function getPackageProviders($app): array
74+
{
7475
return [
7576
PermissionServiceProvider::class,
7677
MongodbServiceProvider::class,
@@ -110,11 +111,11 @@ protected function getEnvironmentSetUp($app)
110111
*
111112
* @return bool
112113
*/
113-
protected function reloadPermissions()
114+
protected function reloadPermissions(): bool
114115
{
115-
\app(PermissionRegistrar::class)->forgetCachedPermissions();
116+
app(PermissionRegistrar::class)->forgetCachedPermissions();
116117

117-
return \app(PermissionRegistrar::class)->registerPermissions();
118+
return app(PermissionRegistrar::class)->registerPermissions();
118119
}
119120

120121
/**
@@ -135,7 +136,7 @@ public function refreshTestAdmin()
135136

136137
protected function clearLogTestHandler()
137138
{
138-
\collect($this->app['log']->getLogger()->getHandlers())->filter(function ($handler) {
139+
collect($this->app['log']->getLogger()->getHandlers())->filter(function ($handler) {
139140
return $handler instanceof TestHandler;
140141
})->first()->clear();
141142
}
@@ -156,21 +157,23 @@ protected function assertLogged($message, $level)
156157
*
157158
* @return bool
158159
*/
159-
protected function hasLog($message, $level): bool {
160-
return \collect($this->app['log']->getLogger()->getHandlers())->filter(function ($handler) use (
161-
$message,
162-
$level
163-
) {
160+
protected function hasLog($message, $level): bool
161+
{
162+
return collect($this->app['log']->getLogger()->getHandlers())->filter(function ($handler) use (
163+
$message,
164+
$level
165+
) {
164166
return $handler instanceof TestHandler && $handler->hasRecordThatContains($message, $level);
165167
})->count() > 0;
166168
}
167169

168170
/**
169171
* @param $message
172+
* @param $level
170173
*/
171174
protected function assertLogMessage($message, $level)
172175
{
173-
if (\config('permission.log_registration_exception')) {
176+
if (config('permission.log_registration_exception')) {
174177
$this->assertLogged($message, $level);
175178
} else {
176179
$this->assertNotLogged($message, $level);
@@ -179,10 +182,11 @@ protected function assertLogMessage($message, $level)
179182

180183
/**
181184
* @param $message
185+
* @param $role_permission
182186
*/
183187
protected function assertShowPermission($message, $role_permission)
184188
{
185-
if (\config('permission.display_permission_in_exception')) {
189+
if (config('permission.display_permission_in_exception')) {
186190
$this->assertContains($role_permission, $message);
187191
} else {
188192
$this->assertStringNotContainsString($role_permission, $message);

tests/TestHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class TestHelper
1818
*
1919
* @return int
2020
*/
21-
public function testMiddleware(string $middleware, object $parameter): int {
21+
public function testMiddleware(string $middleware, object $parameter): int
22+
{
2223
try {
2324
return $middleware->handle(new Request(), function () {
2425
return (new Response())->setContent('<html></html>');

tests/TestSeeder.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
use Maklad\Permission\Models\Permission;
88
use Maklad\Permission\Models\Role;
99

10-
class TestSeeder extends Seeder {
10+
class TestSeeder extends Seeder
11+
{
1112

1213
private Application $app;
1314

14-
public function __construct(Application $app) {
15+
public function __construct(Application $app)
16+
{
1517
$this->app = $app;
1618
}
1719

1820
/**
1921
* Run the database seeds.
2022
*/
21-
public function run() {
23+
public function run()
24+
{
2225
User::create(['email' => 'test@user.com']);
2326
Admin::create(['email' => 'admin@user.com']);
2427
$this->app[Role::class]->create(['name' => 'testRole']);
@@ -29,5 +32,4 @@ public function run() {
2932
$this->app[Permission::class]->create(['name' => 'edit-categories']);
3033
$this->app[Permission::class]->create(['name' => 'admin-permission', 'guard_name' => 'admin']);
3134
}
32-
3335
}

0 commit comments

Comments
 (0)