Skip to content

Commit

Permalink
Laravel 5.8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
hkp22 committed Mar 20, 2019
1 parent de23eaf commit 7f868cc
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 54 deletions.
15 changes: 12 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@ language: php
php:
- 7.1
- 7.2
- 7.3

env:
matrix:
- COMPOSER_FLAGS=""

before_script:
- composer self-update
- composer install --prefer-dist --no-interaction
- travis_retry composer self-update
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source

script:
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

script: ./vendor/bin/phpunit
after_script:
- php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Changelog

All notable changes to `laravel-bannable` will be documented in this file

## 2.1.0 - 2019-03-20

- Laravel 5.8 compatibility
- `forbidBannedUser` route middleware alias is removed. To protect routes, register `Qirolab\Laravel\Bannable\Middleware\ForbidBannedUser` middleware in `$routeMiddleware` array of `app/Http/Kernel.php` file.

## 2.0.0 - 2018-12-31

- package namespace changed from Hkp22 to Qirolab.
- package vendor name changed from hkp22 to qirolab. Now to install this package required new command to run `composer require qirolab/laravel-bannable`.


## 1.0.0 - 2018-07-10

- initial release

55 changes: 55 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Contributing

Contributions are **welcome** and will be fully **credited**.

Please read and understand the contribution guide before creating an issue or pull request.

## Etiquette

This project is open source, and as such, the maintainers give their free time to build and maintain the source code
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
extremely unfair for them to suffer abuse or anger for their hard work.

Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
world that developers are civilized and selfless people.

It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.

## Viability

When requesting or submitting new features, first consider whether it might be useful to others. Open
source projects are used by many developers, who may have entirely different needs to your own. Think about
whether or not your feature is likely to be used by other users of the project.

## Procedure

Before filing an issue:

- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
- Check to make sure your feature suggestion isn't already present within the project.
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
- Check the pull requests tab to ensure that the feature isn't already in progress.

Before submitting a pull request:

- Check the codebase to ensure that your feature doesn't already exist.
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.

## Requirements

If the project maintainer has any additional requirements, you will find them listed here.

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.

**Happy coding**!
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ On model entity ban `\Qirolab\Laravel\Bannable\Events\ModelWasBanned` event is f
On model entity unban `\Qirolab\Laravel\Bannable\Events\ModelWasUnbanned` event is fired.

## Middleware
This package has `forbidBannedUser` route middleware to restrict banned users to go to protected routes.
To prevent banned users to go to protected routes `Qirolab\Laravel\Bannable\Middleware\ForbidBannedUser` middleware is created.

```php
Route::get('/dashboard', 'DashboardController@index')->middleware('forbidBannedUser');
```
Register it in $routeMiddleware array of app/Http/Kernel.php file:

protected $routeMiddleware = [
'isBannedUser' => \Qirolab\Laravel\Bannable\Middleware\ForbidBannedUser::class,
]
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
}
],
"require": {
"php": "^5.6|^7.0",
"illuminate/database": "~5.1.20|~5.2|~5.3|~5.4|~5.5|~5.6",
"illuminate/events": "~5.1.20|~5.2|~5.3|~5.4|~5.5|~5.6",
"illuminate/support": "~5.1.20|~5.2|~5.3|~5.4|~5.5|~5.6"
"php" : ">=7.0",
"illuminate/database": "~5.1.20|~5.2|~5.3|~5.4|~5.5|~5.6|~5.7|~5.8",
"illuminate/events": "~5.1.20|~5.2|~5.3|~5.4|~5.5|~5.6|~5.7|~5.8",
"illuminate/support": "~5.1.20|~5.2|~5.3|~5.4|~5.5|~5.6|~5.7|~5.8"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 0 additions & 12 deletions src/BannableServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Support\ServiceProvider;
use Qirolab\Laravel\Bannable\Models\Ban;
use Qirolab\Laravel\Bannable\Observers\BanObserver;
use Qirolab\Laravel\Bannable\Middleware\ForbidBannedUser;

class BannableServiceProvider extends ServiceProvider
{
Expand All @@ -28,7 +27,6 @@ public function boot()
*/
public function register()
{
$this->registerMiddleware();
}

/**
Expand Down Expand Up @@ -58,14 +56,4 @@ protected function registerObservers()
{
$this->app->make(Ban::class)->observe(new BanObserver);
}

/**
* Register middleware.
*
* @return void
*/
protected function registerMiddleware()
{
$this->app['router']->aliasMiddleware('forbidBannedUser', ForbidBannedUser::class);
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/BannableTraitNotUsed.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct($message = null, $code = 0, Exception $previous = nu
$class = "'".get_class($message)."'";
}

$message = "'Hkp22\Laravel\Bannable\Traits\Bannable' trait is not used in {$class} model.";
$message = "'Qirolab\Laravel\Bannable\Traits\Bannable' trait is not used in {$class} model.";

parent::__construct($message, $code, $previous);
}
Expand Down
44 changes: 30 additions & 14 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ protected function setUp()

$this->publishPackageMigrations();

$this->migratePackageTables();
// $this->migratePackageTables();

$this->migrateUnitTestTables();
// $this->migrateUnitTestTables();

$this->setUpDatabase();

$this->registerPackageFactories();
}
Expand Down Expand Up @@ -87,28 +89,42 @@ private function setDefaultUserModel($app)
}

/**
* Perform package database migrations.
* Set up the database.
*
* @return void
*/
protected function migratePackageTables()
protected function setUpDatabase()
{
$this->loadMigrationsFrom([
'--realpath' => database_path('migrations'),
]);
include_once __DIR__.'/../migrations/2018_06_25_000000_create_bans_table.php';
include_once __DIR__.'/database/migrations/2018_06_25_000000__create_user_table.php';

(new \CreateBansTable())->up();
(new \CreateUserTable())->up();
}

/**
* Perform unit test database migrations.
* Perform package database migrations.
*
* @return void
*/
protected function migrateUnitTestTables()
{
$this->loadMigrationsFrom([
'--realpath' => realpath(__DIR__.'/database/migrations'),
]);
}
// protected function migratePackageTables()
// {
// $this->loadMigrationsFrom([
// '--realpath' => database_path('migrations'),
// ]);
// }

// /**
// * Perform unit test database migrations.
// *
// * @return void
// */
// protected function migrateUnitTestTables()
// {
// $this->loadMigrationsFrom([
// '--realpath' => realpath(__DIR__.'/database/migrations'),
// ]);
// }

/**
* Register package related model factories.
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/BanMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function it_redirected_back_to_banned_user()

$user->ban();

$this->actingAs($user->refresh());
$this->actingAs($user->fresh());

$request = Request::create('/test', 'GET');

Expand Down
8 changes: 2 additions & 6 deletions tests/Unit/BanObserverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ public function it_can_set_banned_flag_to_owner_model_on_create()

$user->bans()->create([]);

$user->refresh();

$this->assertNotNull($user->banned_at);
$this->assertNotNull($user->fresh()->banned_at);
}

/** @test */
Expand Down Expand Up @@ -57,8 +55,6 @@ public function it_can_unset_banned_flag_to_owner_model_on_delete()

$user->unban();

$user->refresh();

$this->assertNull($user->banned_at);
$this->assertNull($user->fresh()->banned_at);
}
}
12 changes: 3 additions & 9 deletions tests/Unit/BannableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public function model_can_ban()

$user->ban();

$user->refresh();

$this->assertNotNull($user->banned_at);
$this->assertNotNull($user->fresh()->banned_at);
}

/** @test */
Expand Down Expand Up @@ -92,10 +90,8 @@ public function model_can_soft_delete_ban_on_unban()

$user->unban();

$user->refresh();

// without Trash
$this->assertCount(0, $user->bans);
$this->assertCount(0, $user->fresh()->bans);

// with Trash
$this->assertCount(1, $user->bans()->withTrashed()->get());
Expand Down Expand Up @@ -152,11 +148,9 @@ public function model_can_ban_via_ban_relation_create()

$ban = $user->bans()->create();

$user->refresh();

$this->assertInstanceOf(Ban::class, $ban);

$this->assertTrue($user->isBanned());
$this->assertTrue($user->fresh()->isBanned());
}

/** @test */
Expand Down

0 comments on commit 7f868cc

Please sign in to comment.