Skip to content

Commit

Permalink
release support for laravel 9
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafamaklad committed May 15, 2022
1 parent bc1cf2c commit 5f42c70
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}
],
"require": {
"php": "^8.0.2",
"php": "^8.0",
"illuminate/auth": "^9.0",
"illuminate/container": "^9.0",
"illuminate/contracts": "^9.0",
Expand Down
40 changes: 22 additions & 18 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();

Expand All @@ -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,
Expand Down Expand Up @@ -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();
}

/**
Expand All @@ -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();
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion tests/TestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<html></html>');
Expand Down
10 changes: 6 additions & 4 deletions tests/TestSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '[email protected]']);
Admin::create(['email' => '[email protected]']);
$this->app[Role::class]->create(['name' => 'testRole']);
Expand All @@ -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']);
}

}

0 comments on commit 5f42c70

Please sign in to comment.