From a41fdafef679a0f502116a79c264d677639f98c0 Mon Sep 17 00:00:00 2001 From: Harish Kumar Date: Mon, 31 Dec 2018 02:36:35 +0530 Subject: [PATCH] Laravel 5.8 compatibility --- .travis.yml | 25 ++++++--- CHANGELOG.md | 18 ++++++ CONTRIBUTING.md | 55 +++++++++++++++++++ README.md | 24 ++++---- composer.json | 18 +++--- src/Contracts/ReactableInterface.php | 2 +- src/Contracts/ReactsInterface.php | 2 +- src/Events/OnDeleteReaction.php | 18 +++--- src/Events/OnReaction.php | 18 +++--- src/Exceptions/InvalidReactionUser.php | 2 +- src/Models/Reaction.php | 2 +- src/ReactionsServiceProvider.php | 2 +- src/Traits/Reactable.php | 12 ++-- src/Traits/Reacts.php | 12 ++-- tests/Stubs/Models/Article.php | 6 +- tests/Stubs/Models/User.php | 6 +- tests/TestCase.php | 36 ++++-------- .../Unit/InvalidReactionUserExceptionTest.php | 10 ++-- tests/Unit/ReactableReactionEventTest.php | 12 ++-- tests/Unit/ReactableScopeTest.php | 8 +-- tests/Unit/ReactableTest.php | 8 +-- tests/Unit/ReactionModelTest.php | 12 ++-- tests/Unit/ReactsModelTest.php | 8 +-- tests/Unit/ReactsReactionEventTest.php | 12 ++-- tests/database/factories/ArticleFactory.php | 2 +- tests/database/factories/UserFactory.php | 2 +- 26 files changed, 202 insertions(+), 130 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md diff --git a/.travis.yml b/.travis.yml index b3aed70..3cd0044 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,22 @@ language: php -php: - - 7.1 - - 7.2 +env: + global: + - SETUP=stable -before_script: - - composer self-update - - composer install --prefer-dist --no-interaction +matrix: + fast_finish: true + include: + - php: 7.1 + - php: 7.1 + env: SETUP=lowest + - php: 7.2 + - php: 7.2 + env: SETUP=lowest + - php: 7.3 -script: ./vendor/bin/phpunit \ No newline at end of file +install: + - if [[ $SETUP = 'stable' ]]; then travis_retry composer update --no-interaction --prefer-stable --no-suggest; fi + - if [[ $SETUP = 'lowest' ]]; then travis_retry composer update --no-interaction --prefer-lowest --prefer-stable --no-suggest; fi + +script: vendor/bin/phpunit \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b990cc4 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,18 @@ +# Changelog + +All notable changes to `permission` will be documented in this file + +## 2.1.0 - 2018-03-16 + +- Laravel 5.8 compatibility + +## 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-reactions`. + + +## 1.0.0 - 2018-07-19 + +- initial release + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..b4ae1c4 --- /dev/null +++ b/CONTRIBUTING.md @@ -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**! diff --git a/README.md b/README.md index c69d917..fa4310b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Laravel Reactions [![GitHub release](https://img.shields.io/github/release/hkp22/laravel-reactions.svg?style=flat-square)](https://github.com/hkp22/laravel-reactions) [![Travis (.org) branch](https://img.shields.io/travis/hkp22/laravel-reactions/master.svg?style=flat-square)](https://github.com/hkp22/laravel-reactions) [![StyleCI](https://github.styleci.io/repos/140428012/shield?branch=master)](https://github.styleci.io/repos/140428012) [![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/hkp22/laravel-reactions) +# Laravel Reactions [![GitHub release](https://img.shields.io/github/release/qirolab/laravel-reactions.svg?style=flat-square)](https://github.com/qirolab/laravel-reactions) [![Travis (.org) branch](https://img.shields.io/travis/qirolab/laravel-reactions/master.svg?style=flat-square)](https://github.com/qirolab/laravel-reactions) [![StyleCI](https://github.styleci.io/repos/140428012/shield?branch=master)](https://github.styleci.io/repos/140428012) [![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/qirolab/laravel-reactions) Laravel reactions package for implementing reactions (eg: like, dislike, love, emotion etc) on Eloquent models. @@ -7,7 +7,7 @@ Laravel reactions package for implementing reactions (eg: like, dislike, love, e Download package into the project using Composer. ```bash -$ composer require hkp22/laravel-reactions +$ composer require qirolab/laravel-reactions ``` ### Registering package @@ -17,7 +17,7 @@ For Laravel 5.4 or earlier releases version include the service provider within ```php 'providers' => [ - Hkp22\Laravel\Reactions\ReactionsServiceProvider::class, + Qirolab\Laravel\Reactions\ReactionsServiceProvider::class, ], ``` @@ -25,7 +25,7 @@ For Laravel 5.4 or earlier releases version include the service provider within If you want to make changes in migrations, publish them to your application first. ```bash -$ php artisan vendor:publish --provider="Hkp22\Laravel\Reactions\ReactionsServiceProvider" --tag=migrations +$ php artisan vendor:publish --provider="Qirolab\Laravel\Reactions\ReactionsServiceProvider" --tag=migrations ``` Run database migrations. @@ -36,11 +36,11 @@ $ php artisan migrate ## Usage ### Prepare Reacts (User) Model -Use `Hkp22\Laravel\Reactions\Contracts\ReactsInterface` contract in model which will perform react behavior on reactable model and implement it and use `Hkp22\Laravel\Reactions\Traits\Reacts` trait. +Use `Qirolab\Laravel\Reactions\Contracts\ReactsInterface` contract in model which will perform react behavior on reactable model and implement it and use `Qirolab\Laravel\Reactions\Traits\Reacts` trait. ```php -use Hkp22\Laravel\Reactions\Traits\Reacts; -use Hkp22\Laravel\Reactions\Contracts\ReactsInterface; +use Qirolab\Laravel\Reactions\Traits\Reacts; +use Qirolab\Laravel\Reactions\Contracts\ReactsInterface; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable implements ReactsInterface @@ -51,12 +51,12 @@ class User extends Authenticatable implements ReactsInterface ### Prepare Reactable Model -Use `Hkp22\Laravel\Reactions\Contracts\ReactableInterface` contract in model which will get reaction behavior and implement it and use `Hkp22\Laravel\Reactions\Traits\Reactable` trait. +Use `Qirolab\Laravel\Reactions\Contracts\ReactableInterface` contract in model which will get reaction behavior and implement it and use `Qirolab\Laravel\Reactions\Traits\Reactable` trait. ```php use Illuminate\Database\Eloquent\Model; -use Hkp22\Laravel\Reactions\Traits\Reactable; -use Hkp22\Laravel\Reactions\Contracts\ReactableInterface; +use Qirolab\Laravel\Reactions\Traits\Reactable; +use Qirolab\Laravel\Reactions\Contracts\ReactableInterface; class Article extends Model implements ReactableInterface { @@ -139,9 +139,9 @@ Article::whereReactedBy($user->id)->get(); ### Events -On each reaction added `\Hkp22\Laravel\Reactions\Events\OnReaction` event is fired. +On each reaction added `\Qirolab\Laravel\Reactions\Events\OnReaction` event is fired. -On each reaction removed `\Hkp22\Laravel\Reactions\Events\OnDeleteReaction` event is fired. +On each reaction removed `\Qirolab\Laravel\Reactions\Events\OnDeleteReaction` event is fired. ### Testing diff --git a/composer.json b/composer.json index 00217a2..44d7f1b 100644 --- a/composer.json +++ b/composer.json @@ -1,10 +1,10 @@ { - "name": "hkp22/laravel-reactions", + "name": "qirolab/laravel-reactions", "description": "Implement reactions (like, dislike, love, emotion etc) on Laravel Eloquent models.", "type": "library", "license": "MIT", "keywords": [ - "laravel", + "laravel", "eloquent", "love", "like", @@ -22,29 +22,29 @@ "authors": [ { "name": "Harish Kumar", - "email": "harishpra22@gmail.com" + "email": "harish.pra22@gmail.com" } ], "require": { "php": "^7.0", - "illuminate/database": "~5.5|~5.6", - "illuminate/support": "~5.5|~5.6" + "illuminate/database": "~5.5|~5.6|~5.7|~5.8", + "illuminate/support": "~5.5|~5.6|~5.7|~5.8" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.10", "mockery/mockery": "^1.0", "orchestra/database": "~3.5.0|~3.6.0", "orchestra/testbench": "~3.5.0|~3.6.0", - "phpunit/phpunit": "^6.0|^7.0" + "phpunit/phpunit": "^7.0" }, "autoload": { "psr-4": { - "Hkp22\\Laravel\\Reactions\\": "src/" + "Qirolab\\Laravel\\Reactions\\": "src/" } }, "autoload-dev": { "psr-4": { - "Hkp22\\Tests\\Laravel\\Reactions\\": "tests/" + "Qirolab\\Tests\\Laravel\\Reactions\\": "tests/" } }, "scripts": { @@ -56,7 +56,7 @@ "extra": { "laravel": { "providers": [ - "Hkp22\\Laravel\\Reactions\\ReactionsServiceProvider" + "Qirolab\\Laravel\\Reactions\\ReactionsServiceProvider" ] } }, diff --git a/src/Contracts/ReactableInterface.php b/src/Contracts/ReactableInterface.php index 8f2dadc..e8479df 100644 --- a/src/Contracts/ReactableInterface.php +++ b/src/Contracts/ReactableInterface.php @@ -1,6 +1,6 @@ publishPackageMigrations(); - $this->migratePackageTables(); - - $this->migrateUnitTestTables(); + $this->setUpDatabase(); $this->registerPackageFactories(); - // $this->registerTestMorphMaps(); - $this->registerUserModel(); } @@ -74,32 +70,24 @@ public function tearDown() protected function getPackageProviders($app) { return [ - \Hkp22\Laravel\Reactions\ReactionsServiceProvider::class, + \Qirolab\Laravel\Reactions\ReactionsServiceProvider::class, ]; } /** - * 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_07_10_000000_create_reactions_table.php'; + include_once __DIR__.'/database/migrations/2018_07_10_000000_create_users_table.php'; + include_once __DIR__.'/database/migrations/2018_07_11_000000_create_articles_table.php'; - /** - * Perform unit test database migrations. - * - * @return void - */ - protected function migrateUnitTestTables() - { - $this->loadMigrationsFrom([ - '--realpath' => realpath(__DIR__.'/database/migrations'), - ]); + (new \CreateReactionsTable())->up(); + (new \CreateUsersTable())->up(); + (new \CreateArticlesTable())->up(); } /** diff --git a/tests/Unit/InvalidReactionUserExceptionTest.php b/tests/Unit/InvalidReactionUserExceptionTest.php index 6114401..3b34ecc 100644 --- a/tests/Unit/InvalidReactionUserExceptionTest.php +++ b/tests/Unit/InvalidReactionUserExceptionTest.php @@ -1,11 +1,11 @@