Skip to content

Commit

Permalink
Merge pull request #75 from httpoz/feature/laravel-8-upgrade
Browse files Browse the repository at this point in the history
Laravel 8
  • Loading branch information
httpoz authored Mar 20, 2021
2 parents dfc884e + 8e27e87 commit 9b967b6
Show file tree
Hide file tree
Showing 19 changed files with 248 additions and 251 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ site/
vendor/
/.phpintel
/build
.phpunit.result.cache

# hack
composer.lock
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ language: php
dist: trusty

php:
- 7.2
- 8.0

matrix:
fast_finish: true
allow_failures:
- php: 7.2
- php: 8.0

before_script:
- travis_retry composer self-update
Expand Down
17 changes: 10 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
}],
"minimum-stability": "dev",
"require": {
"php": "^7.2.5",
"illuminate/support": "~7.0",
"illuminate/cache": "~7.0"
"php": "^7.3|^8.0",
"illuminate/cache": "^8.0",
"illuminate/support": "^8.0"
},
"require-dev": {
"orchestra/database": "^5.0",
"orchestra/testbench": "^5.0",
"phpunit/phpunit": "~8.0"
"orchestra/database": "^6.0",
"orchestra/testbench": "^6.0",
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": {
"HttpOz\\Roles\\": "src/"
"HttpOz\\Roles\\": "src/",
"HttpOz\\Roles\\Database\\Factories\\": "database/factories/"
}
},
"autoload-dev": {
Expand All @@ -31,6 +32,8 @@
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
Expand Down
2 changes: 1 addition & 1 deletion config/roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
|
| Here you can enable cache and change the period for which cache should
| remember the roles. Time should be in seconds, refer to official docs
| https://laravel.com/docs/5.8/cache.
| https://laravel.com/docs/8.x/cache.
*/

'cache' => [
Expand Down
35 changes: 0 additions & 35 deletions database/factories/ModelFactory.php

This file was deleted.

18 changes: 18 additions & 0 deletions database/factories/RoleFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
namespace HttpOz\Roles\Database\Factories;

use HttpOz\Roles\Models\Role;
use Illuminate\Database\Eloquent\Factories\Factory;

Class RoleFactory extends Factory {
protected $model = Role::class;

public function definition(): array
{
return [
'name' => 'Admin',
'slug' => 'admin',
'group' => 'system.admin'
];
}
}
20 changes: 20 additions & 0 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace HttpOz\Roles\Database\Factories;

use HttpOz\Roles\Tests\Stubs\User;
use Illuminate\Database\Eloquent\Factories\Factory;

class UserFactory extends Factory
{
protected $model = User::class;

public function definition(): array
{
return [
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
'password' => $this->faker->password,
'remember_token' => $this->faker->uuid,
];
}
}
61 changes: 27 additions & 34 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>

<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
<logging>
<log type="coverage-html" target="./build/coverage"/>
<log type="coverage-clover" target="./build/logs/clover.xml"/>
<log type="testdox-html" target="./build/logstestdox.html"/>
</logging>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<clover outputFile="./build/logs/clover.xml"/>
<html outputDirectory="./build/coverage"/>
</report>
</coverage>
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
<logging>
<testdoxHtml outputFile="./build/logstestdox.html"/>
</logging>
</phpunit>
17 changes: 3 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,8 @@ Powerful package for handling roles in Laravel
[![Latest Stable Version](https://poser.pugx.org/httpoz/roles/v/stable.svg)](https://packagist.org/packages/httpoz/roles)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/307f89bf-52b1-4d2e-9a62-350d1f5de141/small.png)](https://insight.sensiolabs.com/projects/307f89bf-52b1-4d2e-9a62-350d1f5de141)

|Laravel Version |Roles Version |
|--------|----------|
| 5.3.* | [Roles 1.4.x](https://github.com/httpoz/roles/tree/v1.4.0) |
| 5.4.* | [Roles 2.3.x](https://github.com/httpoz/roles/tree/v2.0.0) |
| 5.5.* | [Roles 3.0.x](https://github.com/httpoz/roles/tree/v3.0.0) |
| 5.6.* | [Roles 3.1.x](https://github.com/httpoz/roles/tree/v3.1.0) |
| 5.7.* | [Roles 3.2.x](https://github.com/httpoz/roles/tree/v3.2.0) |
| 5.8.* | [Roles 3.3.x](https://github.com/httpoz/roles/tree/v3.3.0) |
| 6.x | [Roles 4.x](https://github.com/httpoz/roles/tree/v4.0.0) |
| 7.x | Roles 5.x

#### History
This project was largely inspired by Roman's [romanbican/roles](https://github.com/romanbican/roles/) Laravel package. However at the time Laravel 5.3 was released his package was not actively maintained. I have ommitted permissions in this package in favour of Laravel's [Authorization](https://laravel.com/docs/6.x/authorization). I intend to keep this package as simple and minimal as is possible.
#### Previous Versions
For Previous versions please see the [releases page](https://github.com/httpoz/roles/releases)

- [Installation](#installation)
- [Composer](#composer)
Expand All @@ -45,7 +34,7 @@ This package is very easy to set up. There are only couple of steps.
### Composer
Add the package to your project via composer.
```bash
composer require httpoz/roles:^v5.0
composer require httpoz/roles:^v8.0
```

### Config File And Migrations
Expand Down
9 changes: 8 additions & 1 deletion src/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
namespace HttpOz\Roles\Models;


use HttpOz\Roles\Database\Factories\RoleFactory;
use HttpOz\Roles\Traits\Sluggable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

use HttpOz\Roles\Traits\RoleHasRelations;
use HttpOz\Roles\Contracts\RoleHasRelations as RoleHasRelationsContract;

class Role extends Model implements RoleHasRelationsContract {

use Sluggable, RoleHasRelations;
use Sluggable, RoleHasRelations, HasFactory;

/**
* The attributes that are mass assignable.
Expand Down Expand Up @@ -42,4 +44,9 @@ public static function findBySlug($slug) {
return self::where('slug', $slug)->first();
}

protected static function newFactory()
{
return new RoleFactory();
}

}
21 changes: 7 additions & 14 deletions src/RolesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@ class RolesServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->publishes([
__DIR__ . '/../config/roles.php' => config_path('roles.php')
], 'config');

$stub = __DIR__ . '/../database/migrations/';
$target = database_path('migrations').'/';

$this->publishes([
$stub.'create_roles_table.php' => $target . '2016_09_04_000000_create_roles_table.php',
$stub.'create_role_user_table.php' => $target . '2016_09_04_100000_create_role_user_table.php'
], 'migrations');
// Load migrations
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations/');

$this->publishes([
__DIR__.'/../resources/views' => base_path('resources/views/vendor'),
], 'views');
// publish config file
$this->publishes([__DIR__ . '/../config/roles.php' => config_path('roles.php')], 'config');

// publish views
$this->loadViewsFrom(__DIR__.'/../resources/views', 'roles');

$this->registerBladeExtensions();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/CreateRoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CreateRoleTest extends TestCase
*/
public function testCanCreateRole()
{
$adminRole = factory(Role::class)->create([
$adminRole = Role::factory()->create([
'name' => 'Admin',
'slug' => 'admin',
'description' => 'Custodians of the system.',
Expand Down
11 changes: 2 additions & 9 deletions tests/Feature/RoleMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@
use HttpOz\Roles\Tests\Stubs\User;
use HttpOz\Roles\Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class RoleMiddlewareTest extends TestCase
{

use DatabaseMigrations;

/**
* A basic test example.
*
* @return void
*/
public function testForbiddenRoleRoute()
{
$createdUser = factory(User::class)->create();
$createdRole = factory(Role::class)->create([
$createdUser = User::factory()->create();
$createdRole = Role::factory()->create([
'name' => 'Admin',
'slug' => 'admin',
]);
Expand All @@ -37,9 +34,5 @@ public function testForbiddenRoleRoute()

$this->assertEquals($createdRole->id, $foundRole->id);
$this->assertEquals($createdUser->name, $foundUser->name);

/*$this->get('/admin/users')
->assertStatus(200)
->assertSee('I am an admin.');*/
}
}
7 changes: 2 additions & 5 deletions tests/Feature/UserRoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@

use HttpOz\Roles\Tests\Stubs\User;
use \HttpOz\Roles\Models\Role;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use HttpOz\Roles\Tests\TestCase;

class UserRoleTest extends TestCase
{

use DatabaseMigrations;

public function testUserHasRoleOnAttach()
{
$admin = factory(User::class)->create();
$role = factory(Role::class)->create();
$admin = User::factory()->create();
$role = Role::factory()->create();

$adminRole = Role::findBySlug('admin');
$user = User::find(1);
Expand Down
13 changes: 11 additions & 2 deletions tests/Stubs/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@

namespace HttpOz\Roles\Tests\Stubs;

use HttpOz\Roles\Database\Factories\UserFactory;
use \HttpOz\Roles\Traits\HasRole;
use \HttpOz\Roles\Contracts\HasRole as HasRoleContract;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Eloquent;

class User extends Eloquent implements HasRoleContract
{

use HasRole;
use HasRole, HasFactory;

/**
* Get the name of the unique identifier for the user.
*
* @return array
*/
public function getAuthIdentifiersName()
public function getAuthIdentifiersName(): array
{
return ['email', 'username'];
}



protected static function newFactory()
{
return new UserFactory();
}
}
Loading

0 comments on commit 9b967b6

Please sign in to comment.