Skip to content

Commit fa6762d

Browse files
author
Hauke Ingwersen
committed
Support for laravel 8
Update Dependencies drop php7.2 apply phpcs and phpcbf update phpcs rules fixed parameter type Revert has Permission and update phpcs rules phpunit to fixed version phpunit version Phpunit version use vendor/bin/phpunit
1 parent f57a740 commit fa6762d

14 files changed

+116
-112
lines changed

.travis.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
language: php
22

33
php:
4-
- 7.2
54
- 7.3
6-
- 7.4snapshot
5+
- 7.4
76
- nightly
87

98
matrix:
109
include:
11-
- php: 7.2
10+
- php: 7.3
1211
env: COMPOSER_FLAGS="--prefer-lowest"
12+
- php: 7.4
13+
env: COMPOSER_FLAGS="--prefer-lowest"
14+
- php: 7.4
1315
allow_failures:
14-
- php: 7.4snapshot
1516
- php: nightly
1617

1718
before_script:
1819
- travis_retry composer self-update
1920
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source
2021

2122
script:
22-
- phpunit --coverage-text --coverage-clover=coverage.clover
23+
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
2324
- vendor/bin/phpcs -s
2425
- vendor/bin/phpmd config,src,tests text phpmd.xml

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
}
2020
],
2121
"require": {
22-
"php": "^7.2.5",
23-
"laravel/framework": "^6.0|^7.0"
22+
"php": ">=7.3",
23+
"laravel/framework": "^6.0|^7.0|^8.0"
2424
},
2525
"require-dev": {
26-
"orchestra/testbench": "^5.2",
27-
"phpunit/phpunit": "9.1",
26+
"orchestra/testbench": "^5.0 || ^6.0",
27+
"phpunit/phpunit": "^9.3",
2828
"phpmd/phpmd": "^2.6",
2929
"squizlabs/php_codesniffer": "^3.3",
3030
"consistence/coding-standard": "^3.8",

phpcs.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.PartialUse"/>
4242
<exclude name="SlevomatCodingStandard.Functions.TrailingCommaInCall.MissingTrailingComma"/>
4343
<exclude name="SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint.DisallowedMixedTypeHint"/>
44-
<!-- <exclude name="SlevomatCodingStandard.Types.EmptyLinesAroundTypeBraces"/> -->
4544
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing" />
4645
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification"/>
4746
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification"/>
@@ -53,11 +52,17 @@
5352
<exclude name="SlevomatCodingStandard.ControlStructures.RequireMultiLineTernaryOperator.MultiLineTernaryOperatorNotUsed"/>
5453
<exclude name="SlevomatCodingStandard.ControlStructures.ControlStructureSpacing.IncorrectLinesCountAfterControlStructure"/>
5554
<exclude name="SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators.DisallowedPostIncrementOperator"/>
55+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
56+
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint"/>
57+
<exclude name="SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint"/>
58+
<exclude name="SlevomatCodingStandard.Functions.RequireArrowFunction"/>
59+
<exclude name="SlevomatCodingStandard.Functions.DisallowArrowFunction.DisallowedArrowFunction"/>
60+
<exclude name="SlevomatCodingStandard.ControlStructures.RequireSingleLineCondition.RequiredSingleLineCondition"/>
5661
</rule>
5762

5863
<!-- exclude directories from certain rules -->
5964

60-
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingPropertyTypeHint">
65+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint">
6166
<exclude-pattern>*/tests/*</exclude-pattern>
6267
</rule>
6368
</ruleset>

src/Middlewares/RoleMiddleware.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class RoleMiddleware
1111
/**
1212
* Handle an incoming request.
1313
*
14-
* @param \Illuminate\Http\Request $request
15-
* @param \Closure $next
16-
* @param string $roles
14+
* @param \Illuminate\Http\Request $request
15+
* @param \Closure $next
16+
* @param string $roles
1717
* @return mixed
1818
*/
1919
public function handle(Request $request, Closure $next, string $roles)

src/Traits/HasPermissions.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ trait HasPermissions
1010
/**
1111
* Check if model has all permissions
1212
*
13-
* @param array|string ...$permissions
13+
* @param array|string ...$permissions
1414
* @return bool
1515
*/
1616
public function hasPermissionTo(...$permissions): bool
@@ -35,7 +35,7 @@ public function hasPermissionTo(...$permissions): bool
3535
/**
3636
* Check if model has all permissions
3737
*
38-
* @param array|string ...$permissions
38+
* @param array|string ...$permissions
3939
* @return bool
4040
*/
4141
public function hasPermission(...$permissions): bool
@@ -46,7 +46,7 @@ public function hasPermission(...$permissions): bool
4646
/**
4747
* Check if model has any permissions
4848
*
49-
* @param array|string ...$permissions
49+
* @param array|string ...$permissions
5050
* @return bool
5151
*/
5252
public function hasAnyPermission(...$permissions): bool
@@ -86,8 +86,8 @@ public function getAllPermissions(): Collection
8686
/**
8787
* Match ruleset to permission
8888
*
89-
* @param \Illuminate\Support\Collection $rules Ruleset
90-
* @param array $permission
89+
* @param \Illuminate\Support\Collection $rules Ruleset
90+
* @param array $permission
9191
* @return bool
9292
*/
9393
public function matchPermission(Collection $rules, array $permission): bool
@@ -111,8 +111,8 @@ public function matchPermission(Collection $rules, array $permission): bool
111111
/**
112112
* Match one rule to permission
113113
*
114-
* @param array $rule
115-
* @param array $permission
114+
* @param array $rule
115+
* @param array $permission
116116
* @return bool
117117
*/
118118
public function matchRuleToPermission(array $rule, array $permission): bool

src/Traits/HasRoles.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ trait HasRoles
1010
/**
1111
* Assign the role to the model
1212
*
13-
* @param string $role rolename
13+
* @param string $role rolename
1414
* @return $this
1515
*/
1616
public function assignRole(string $role)
@@ -31,7 +31,7 @@ public function assignRole(string $role)
3131
/**
3232
* Compare role with given model role
3333
*
34-
* @param string $role role name
34+
* @param string $role role name
3535
* @return bool
3636
*/
3737
public function hasRole(string $role): bool

tests/BladeTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@
77
class BladeTest extends TestCase
88
{
99

10-
protected function setUp(): void
11-
{
12-
parent::setUp();
13-
14-
$this->app['config']->set('permission.roles.admin', [
15-
'users/#',
16-
'!users/create',
17-
]);
18-
19-
$this->user = User::create(['email' => '[email protected]']);
20-
}
21-
2210
public function testPermission(): void
2311
{
2412
$this->user->assignRole('admin');
@@ -66,6 +54,18 @@ public function testUnlessRole(): void
6654
$this->assertEquals($this->renderView('unlessrole', ['role' => 'user']), 'Test');
6755
}
6856

57+
protected function setUp(): void
58+
{
59+
parent::setUp();
60+
61+
$this->app['config']->set('permission.roles.admin', [
62+
'users/#',
63+
'!users/create',
64+
]);
65+
66+
$this->user = User::create(['email' => '[email protected]']);
67+
}
68+
6969
/**
7070
* from Spatie\Permission\Test;
7171
* return compiled blade views

tests/MatchPermissionTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@
55
class MatchPermissionTest extends TestCase
66
{
77

8-
protected function setUp(): void
9-
{
10-
parent::setUp();
11-
12-
$this->permission = [
13-
'user',
14-
'edit',
15-
];
16-
$this->user = User::create(['email' => '[email protected]']);
17-
}
18-
198
public function testNoRules(): void
209
{
2110
$rules = collect([]);
@@ -62,4 +51,15 @@ public function testOverwriteRule(): void
6251
$this->assertFalse($this->user->matchPermission($rules, $this->permission));
6352
}
6453

54+
protected function setUp(): void
55+
{
56+
parent::setUp();
57+
58+
$this->permission = [
59+
'user',
60+
'edit',
61+
];
62+
$this->user = User::create(['email' => '[email protected]']);
63+
}
64+
6565
}

tests/MatchRuleToPermissionTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@
55
class MatchRuleToPermissionTest extends TestCase
66
{
77

8-
protected function setUp(): void
9-
{
10-
parent::setUp();
11-
12-
$this->permission = [
13-
'user',
14-
'edit',
15-
];
16-
$this->user = User::create(['email' => '[email protected]']);
17-
}
18-
198
public function testDirectRule(): void
209
{
2110
$rule = [
@@ -97,4 +86,15 @@ public function testShortRule(): void
9786
$this->assertFalse($this->user->matchRuleToPermission($rule, $this->permission));
9887
}
9988

89+
protected function setUp(): void
90+
{
91+
parent::setUp();
92+
93+
$this->permission = [
94+
'user',
95+
'edit',
96+
];
97+
$this->user = User::create(['email' => '[email protected]']);
98+
}
99+
100100
}

tests/MiddlewareTest.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,6 @@
1111
class MiddlewareTest extends TestCase
1212
{
1313

14-
/**
15-
* Setup the test environment.
16-
*
17-
* @return void
18-
*/
19-
protected function setUp(): void
20-
{
21-
parent::setUp();
22-
23-
$this->roleMiddleware = new RoleMiddleware($this->app);
24-
25-
$this->app['config']->set('permission.roles.admin', [
26-
'users/*',
27-
]);
28-
29-
$this->user = User::create(['email' => '[email protected]']);
30-
}
31-
3214
public function testGustCannotAccessProtectedRoute(): void
3315
{
3416
$this->assertEquals($this->runMiddleware($this->roleMiddleware, 'admin'), 403);
@@ -50,6 +32,24 @@ public function testUserCantAccessRoleIfHavenotRole(): void
5032
$this->assertEquals($this->runMiddleware($this->roleMiddleware, 'admin'), 403);
5133
}
5234

35+
/**
36+
* Setup the test environment.
37+
*
38+
* @return void
39+
*/
40+
protected function setUp(): void
41+
{
42+
parent::setUp();
43+
44+
$this->roleMiddleware = new RoleMiddleware($this->app);
45+
46+
$this->app['config']->set('permission.roles.admin', [
47+
'users/*',
48+
]);
49+
50+
$this->user = User::create(['email' => '[email protected]']);
51+
}
52+
5353
protected function runMiddleware(RoleMiddleware $middleware, string $parameter): int
5454
{
5555
try {

0 commit comments

Comments
 (0)