Skip to content

Commit

Permalink
complete wiring of laravel 8 update
Browse files Browse the repository at this point in the history
  • Loading branch information
httpoz committed Mar 19, 2021
1 parent bbaa50c commit 8e27e87
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 194 deletions.
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"minimum-stability": "dev",
"require": {
"php": "^7.3|^8.0",
"illuminate/support": "~8.0",
"illuminate/cache": "~8.0"
"illuminate/cache": "^8.0",
"illuminate/support": "^8.0"
},
"require-dev": {
"orchestra/database": "^6.0",
Expand All @@ -22,7 +22,8 @@
},
"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
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>
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
8 changes: 8 additions & 0 deletions tests/Stubs/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand All @@ -21,4 +22,11 @@ public function getAuthIdentifiersName(): array
{
return ['email', 'username'];
}



protected static function newFactory()
{
return new UserFactory();
}
}
17 changes: 10 additions & 7 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace HttpOz\Roles\Tests;

use HttpOz\Roles\Models\Role;
use HttpOz\Roles\RolesServiceProvider;
use HttpOz\Roles\Tests\Stubs\User;
use Illuminate\Foundation\Application;
use Orchestra\Database\ConsoleServiceProvider;
use Orchestra\Testbench\TestCase as Orchestra;

class TestCase extends Orchestra
Expand All @@ -15,21 +19,20 @@ public function setUp(): void
parent::setUp();
$this->loadLaravelMigrations(['--database' => 'testbench']);
$this->setUpDatabase($this->app);

$this->withFactories(__DIR__ . '/../database/factories');
}

protected function getPackageProviders($app)
protected function getPackageProviders($app): array
{
return [
\Orchestra\Database\ConsoleServiceProvider::class
RolesServiceProvider::class,
ConsoleServiceProvider::class
];
}

/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @param Application $app
* @return void
*/
public function getEnvironmentSetUp($app)
Expand All @@ -50,7 +53,7 @@ public function getEnvironmentSetUp($app)
'expiry' => 20160,
],
'models' => [
'role' => \HttpOz\Roles\Models\Role::class
'role' => Role::class
],
'pretend' => [
'enabled' => false,
Expand All @@ -64,7 +67,7 @@ public function getEnvironmentSetUp($app)
/**
* Set up the database.
*
* @param \Illuminate\Foundation\Application $app
* @param Application $app
*/
protected function setUpDatabase($app)
{
Expand Down
Loading

0 comments on commit 8e27e87

Please sign in to comment.