Skip to content

Commit b8f55cb

Browse files
authored
Merge branch 'master' into l11-compatibility
2 parents 560d004 + 56eb5cb commit b8f55cb

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jeremykenedy/laravel-roles",
3-
"description": "A Powerful package for handling roles and permissions in Laravel. Supports Laravel 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 6.0, 7.0, 8.0 and 9.0.",
3+
"description": "A Powerful package for handling roles and permissions in Laravel. Supports Laravel 5.3 up to 11.",
44
"keywords": [
55
"laravel-roles",
66
"laravel-permissions",
@@ -24,16 +24,16 @@
2424
}
2525
],
2626
"require": {
27-
"php": "^7.2|^8.0.2|^8.1",
27+
"php": "^7.2|^8.0|^8.1|^8.2|^8.3",
2828
"laravel/framework": "5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.*|7.*|8.*|^9.0|^10.0|^11.0",
29-
"eklundkristoffer/seedster": "^7.0",
30-
"laravel/helpers": "^1.5"
29+
"eklundkristoffer/seedster": "^8.0",
30+
"laravel/helpers": "^1.7"
3131
},
3232
"require-dev": {
3333
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0",
34-
"laravel/tinker": "^2.7",
34+
"laravel/tinker": "^2.9",
3535
"illuminate/support": "^8.5|^9.0|^10.0|^11.0",
36-
"laravel/laravel": "^8.0|^9.0|^10.0"
36+
"laravel/laravel": "^8.0|^9.0|^10.0|^11.0"
3737
},
3838
"autoload": {
3939
"psr-4": {

tests/Feature/NPlusOneQueriesTest.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ class NPlusOneQueriesTest extends TestCase
1515
protected $seed = true;
1616

1717
protected $usersCount = 10;
18-
protected $rolesCount = 3;
19-
protected $permissionsCount = 4;
18+
/**
19+
* @var int in case UsersTableSeeder seeds your users,
20+
* please indicate their number here
21+
*/
22+
protected $usersCountCorrection = 0;
23+
protected $rolesCount = 3; //correct according to your data
24+
protected $permissionsCount = 4; //correct according to your data
2025

2126
protected $queries = 0;
2227

@@ -27,7 +32,7 @@ protected function setUp(): void
2732
$this->assertEquals($this->rolesCount, config('roles.models.role')::count());
2833
$this->assertEquals($this->permissionsCount, config('roles.models.permission')::count());
2934

30-
DB::listen(function (QueryExecuted $query) {
35+
DB::listen(function(QueryExecuted $query) {
3136
$this->queries++;
3237
});
3338
}
@@ -38,27 +43,28 @@ public function canPreloadRolesOnCollection(): void
3843
$roleIds = config('roles.models.role')::pluck('id');
3944

4045
User::factory($this->usersCount)->create()
41-
->each(function (User $user) use ($roleIds) {
46+
->each(function(User $user) use ($roleIds) {
4247
$user->roles()->attach($roleIds);
4348
});
44-
$this->assertEquals($this->usersCount, User::count());
49+
$this->assertEquals($this->usersCount, User::count() - $this->usersCountCorrection);
4550

4651
$this->queries = 0;
4752

4853
// without eager load
4954
$users = User::get();
5055
$this->assertQueries(1);
5156

52-
$users->each(function (User $user) {
57+
$users->each(function(User $user) {
5358
$user->getRoles();
5459
});
60+
$this->queries = $this->queries - $this->usersCountCorrection;
5561
$this->assertQueries($this->usersCount);
5662

5763
// with eager load
5864
$users = User::with('roles')->get();
5965
$this->assertQueries(2);
6066

61-
$users->each(function (User $user) {
67+
$users->each(function(User $user) {
6268
$user->getRoles();
6369
});
6470
$this->assertQueries(0);
@@ -136,33 +142,33 @@ public function canPreloadPermissionsOnCollection(): void
136142
$roleIds = config('roles.models.role')::pluck('id');
137143

138144
User::factory($this->usersCount)->create()
139-
->each(function (User $user) use ($roleIds) {
145+
->each(function(User $user) use ($roleIds) {
140146
$user->roles()->attach($roleIds);
141147
});
142-
$this->assertEquals($this->usersCount, User::count());
148+
$this->assertEquals($this->usersCount, User::count() - $this->usersCountCorrection);
143149

144150
$this->queries = 0;
145151

146152
// without eager load
147153
$users = User::get();
148154
$this->assertQueries(1);
149155

150-
$users->each(function (User $user) {
156+
$users->each(function(User $user) {
151157
$user->getPermissions();
152158
});
153159
// rolePermissions(+getRoles) + userPermissions
154-
$this->assertQueries($this->usersCount * 3);
160+
$this->assertQueries(($this->usersCount + $this->usersCountCorrection) * 3);
155161

156162
// with eager load
157163
// TODO: 'rolePermissions' relation
158164
$users = User::with('roles', 'userPermissions')->get();
159165
$this->assertQueries(3);
160166

161-
$users->each(function (User $user) {
167+
$users->each(function(User $user) {
162168
$user->getPermissions();
163169
});
164170
// TODO: optimize via relations: userPermissions and rolePermissions
165-
$this->assertQueries(20);
171+
$this->assertQueries(20 + $this->usersCountCorrection * 2);
166172
// $this->assertQueries(0);
167173
}
168174

0 commit comments

Comments
 (0)