Skip to content

Commit

Permalink
Updating the package to support Laravel 7.x (#32)
Browse files Browse the repository at this point in the history
* Updating the package to support Laravel 7.x

* Update run-tests.yml
  • Loading branch information
arcanedev-maroc committed Mar 11, 2020
1 parent e5dd4f1 commit d6765d2
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-laravel-6.x-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
key: dependencies-laravel-7.x-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -20,7 +20,7 @@ This Laravel Notes will allow you to add a notes system into your Laravel projec
* Easy setup & configuration.
* Well documented & IDE Friendly.
* Well tested with maximum code quality.
* Laravel `5.1` to `6.x` are supported.
* Laravel `5.1` to `7.x` are supported.
* Made with :heart: & :coffee:.

## Table of contents
Expand All @@ -42,7 +42,7 @@ If you discover any security related issues, please email arcanedev.maroc@gmail.
- [ARCANEDEV][link-author]
- [All Contributors][link-contributors]

[badge_laravel]: https://img.shields.io/badge/For%20Laravel-5.1%20to%206.x-orange.svg?style=flat-square
[badge_laravel]: https://img.shields.io/badge/For%20Laravel-5.1%20to%207.x-orange.svg?style=flat-square
[badge_license]: https://img.shields.io/packagist/l/arcanedev/laravel-notes.svg?style=flat-square
[badge_build]: https://img.shields.io/github/workflow/status/ARCANEDEV/LaravelNotes/run-tests?style=flat-square
[badge_coverage]: https://img.shields.io/scrutinizer/coverage/g/ARCANEDEV/LaravelNotes.svg?style=flat-square
Expand Down
2 changes: 1 addition & 1 deletion _docs/0-Home.md
Expand Up @@ -8,7 +8,7 @@ This Laravel Notes will allow you to add a notes system into your Laravel projec
* Easy setup & configuration.
* Well documented & IDE Friendly.
* Well tested with maximum code quality.
* Laravel `5.1` to `6.x` are supported.
* Laravel `5.1` to `7.x` are supported.
* Made with :heart: & :coffee:.

## Table of contents
Expand Down
3 changes: 3 additions & 0 deletions _docs/1-Installation-and-Setup.md
Expand Up @@ -10,6 +10,7 @@

| Laravel Notes | Laravel |
|:-----------------------------------------|:---------------------------------------------------------------------------------------|
| ![Laravel Notes v7.x][laravel_notes_7_x] | ![Laravel v7.x][laravel_7_x] |
| ![Laravel Notes v6.x][laravel_notes_6_x] | ![Laravel v6.x][laravel_6_x] |
| ![Laravel Notes v5.x][laravel_notes_5_x] | ![Laravel v5.8][laravel_5_8] |
| ![Laravel Notes v4.x][laravel_notes_4_x] | ![Laravel v5.7][laravel_5_7] |
Expand All @@ -18,6 +19,7 @@
| ![Laravel Notes v1.x][laravel_notes_1_x] | ![Laravel v5.4][laravel_5_4] |
| ![Laravel Notes v0.x][laravel_notes_0_x] | ![Laravel v5.1][laravel_5_1] ![Laravel v5.2][laravel_5_2] ![Laravel v5.3][laravel_5_3] |

[laravel_7_x]: https://img.shields.io/badge/v7.x-supported-brightgreen.svg?style=flat-square "Laravel v7.x"
[laravel_6_x]: https://img.shields.io/badge/v6.x-supported-brightgreen.svg?style=flat-square "Laravel v6.x"
[laravel_5_8]: https://img.shields.io/badge/v5.8-supported-brightgreen.svg?style=flat-square "Laravel v5.8"
[laravel_5_7]: https://img.shields.io/badge/v5.7-supported-brightgreen.svg?style=flat-square "Laravel v5.7"
Expand All @@ -28,6 +30,7 @@
[laravel_5_2]: https://img.shields.io/badge/v5.2-supported-brightgreen.svg?style=flat-square "Laravel v5.2"
[laravel_5_1]: https://img.shields.io/badge/v5.1-supported-brightgreen.svg?style=flat-square "Laravel v5.1"

[laravel_notes_7_x]: https://img.shields.io/badge/version-7.x-blue.svg?style=flat-square "LaravelNotes v7.x"
[laravel_notes_6_x]: https://img.shields.io/badge/version-6.x-blue.svg?style=flat-square "LaravelNotes v6.x"
[laravel_notes_5_x]: https://img.shields.io/badge/version-5.x-blue.svg?style=flat-square "LaravelNotes v5.x"
[laravel_notes_4_x]: https://img.shields.io/badge/version-4.x-blue.svg?style=flat-square "LaravelNotes v4.x"
Expand Down
4 changes: 2 additions & 2 deletions _docs/2-Configuration.md
Expand Up @@ -30,8 +30,8 @@ return [
*/

'authors' => [
'table' => config('auth.table', 'users'),
'model' => config('auth.model', App\User::class),
'table' => 'users',
'model' => App\User::class,
],

'notes' => [
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Expand Up @@ -14,13 +14,13 @@
"type": "library",
"license": "MIT",
"require": {
"php": "^7.2.0",
"arcanedev/support": "^5.1"
"php": "^7.2.5",
"arcanedev/support": "^7.0"
},
"require-dev": {
"orchestra/testbench": "^4.6",
"orchestra/testbench": "^5.0",
"mockery/mockery": "^1.3.1",
"phpunit/phpunit": "^8.4|^9.0"
"phpunit/phpunit": "^8.5|^9.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions config/notes.php
Expand Up @@ -19,8 +19,8 @@
*/

'authors' => [
'table' => config('auth.table', 'users'),
'model' => config('auth.model', App\User::class),
'table' => 'users',
'model' => App\User::class,
],

'notes' => [
Expand Down
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use Arcanedev\LaravelNotes\Bases\Migration;
use Arcanedev\LaravelNotes\Database\Migration;
use Illuminate\Database\Schema\Blueprint;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Bases/Migration.php → src/Database/Migration.php
Expand Up @@ -2,14 +2,14 @@

declare(strict_types=1);

namespace Arcanedev\LaravelNotes\Bases;
namespace Arcanedev\LaravelNotes\Database;

use Arcanedev\Support\Database\Migration as BaseMigration;

/**
* Class Migration
*
* @package Arcanedev\LaravelMessenger\Bases
* @package Arcanedev\LaravelNotes\Database
* @author ARCANEDEV <arcanedev.maroc@gmail.com>
*/
abstract class Migration extends BaseMigration
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Note.php
Expand Up @@ -4,7 +4,7 @@

namespace Arcanedev\LaravelNotes\Models;

use Arcanedev\Support\Database\Model;
use Arcanedev\Support\Database\PrefixedModel;
use Illuminate\Support\Arr;

/**
Expand All @@ -24,7 +24,7 @@
* @property \Illuminate\Database\Eloquent\Model author
* @property \Illuminate\Database\Eloquent\Model noteable
*/
class Note extends Model
class Note extends PrefixedModel
{
/* -----------------------------------------------------------------
| Properties
Expand Down
76 changes: 47 additions & 29 deletions tests/Models/NoteTest.php
Expand Up @@ -16,7 +16,6 @@
*/
class NoteTest extends TestCase
{

/* -----------------------------------------------------------------
| Tests [Has One Note]
| -----------------------------------------------------------------
Expand All @@ -25,8 +24,7 @@ class NoteTest extends TestCase
/** @test */
public function it_can_create_a_note(): void
{
/** @var Post $post */
$post = $this->factory->create(Post::class);
$post = $this->createPost();

static::assertNull($post->note);

Expand All @@ -44,8 +42,7 @@ public function it_can_create_a_note(): void
/** @test */
public function it_should_create_single_note_for_has_one_note_trait(): void
{
/** @var Post $post */
$post = $this->factory->create(Post::class);
$post = $this->createPost();

static::assertNull($post->note);

Expand All @@ -71,12 +68,8 @@ public function it_should_create_single_note_for_has_one_note_trait(): void
/** @test */
public function it_can_create_with_author(): void
{
/**
* @var User $user
* @var Post $post
*/
$user = $this->factory->create(User::class);
$post = $this->factory->create(Post::class);
$user = $this->createUser();
$post = $this->createPost();

$note = $post->createNote($content = 'Hello world #1', $user);

Expand All @@ -93,8 +86,7 @@ public function it_can_create_with_author(): void
/** @test */
public function it_can_update_note(): void
{
/** @var Post $post */
$post = $this->factory->create(Post::class);
$post = $this->createPost();

static::assertNull($post->note);

Expand All @@ -120,8 +112,7 @@ public function it_can_update_note(): void
/** @test */
public function it_can_reverse_relation(): void
{
/** @var Post $post */
$post = $this->factory->create(Post::class);
$post = $this->createPost();

static::assertNull($post->note);

Expand All @@ -140,8 +131,7 @@ public function it_can_reverse_relation(): void
/** @test */
public function it_can_add_note(): void
{
/** @var User $user */
$user = $this->factory->create(User::class);
$user = $this->createUser();

static::assertCount(0, $user->notes);

Expand All @@ -154,8 +144,7 @@ public function it_can_add_note(): void
/** @test */
public function it_can_add_note_without_get_current_author_id_method(): void
{
/** @var \Arcanedev\LaravelNotes\Tests\Stubs\Models\UserWithAuthorId $user */
$user = $this->factory->create(UserWithAuthorId::class);
$user = $this->createUserWithAuthorId();

static::assertCount(0, $user->notes);

Expand All @@ -168,8 +157,7 @@ public function it_can_add_note_without_get_current_author_id_method(): void
/** @test */
public function it_can_find_note_by_its_id(): void
{
/** @var User $user */
$user = $this->factory->create(User::class);
$user = $this->createUser();

$created = $user->createNote($content = 'Hello world #1');
$note = $user->findNote($created->id);
Expand All @@ -180,8 +168,7 @@ public function it_can_find_note_by_its_id(): void
/** @test */
public function it_can_retrieve_authored_notes(): void
{
/** @var \Arcanedev\LaravelNotes\Tests\Stubs\Models\User $user */
$user = $this->factory->create(User::class);
$user = $this->createUser();

static::assertCount(0, $user->notes);
static::assertCount(0, $user->authoredNotes);
Expand All @@ -196,12 +183,8 @@ public function it_can_retrieve_authored_notes(): void
/** @test */
public function it_must_retrieve_authored_notes_foreach_owner(): void
{
/**
* @var \Arcanedev\LaravelNotes\Tests\Stubs\Models\User $userOne
* @var \Arcanedev\LaravelNotes\Tests\Stubs\Models\User $userTwo
*/
$userOne = $this->factory->create(UserWithAuthorId::class);
$userTwo = $this->factory->create(UserWithAuthorId::class);
$userOne = $this->createUserWithAuthorId();
$userTwo = $this->createUserWithAuthorId();

$userOne->createNote('Hello World #1');
$userOne->createNote('Hello World #2', $userTwo);
Expand All @@ -212,4 +195,39 @@ public function it_must_retrieve_authored_notes_foreach_owner(): void
static::assertCount(0, $userTwo->notes);
static::assertCount(1, $userTwo->authoredNotes);
}

/* -----------------------------------------------------------------
| Other Methods
| -----------------------------------------------------------------
*/

/**
* Create a post.
*
* @return \Arcanedev\LaravelNotes\Tests\Stubs\Models\Post|mixed
*/
protected function createPost()
{
return factory(Post::class)->create();
}

/**
* Create a user.
*
* @return \Arcanedev\LaravelNotes\Tests\Stubs\Models\User|mixed
*/
protected function createUser()
{
return factory(User::class)->create();
}

/**
* Create a user with author id associated.
*
* @return \Arcanedev\LaravelNotes\Tests\Stubs\Models\UserWithAuthorId|mixed
*/
protected function createUserWithAuthorId()
{
return factory(UserWithAuthorId::class)->create();
}
}
4 changes: 2 additions & 2 deletions tests/Stubs/Models/Post.php
Expand Up @@ -5,7 +5,7 @@
namespace Arcanedev\LaravelNotes\Tests\Stubs\Models;

use Arcanedev\LaravelNotes\Traits\HasOneNote;
use Arcanedev\Support\Database\Model;
use Arcanedev\Support\Database\PrefixedModel;
use Illuminate\Support\Arr;

/**
Expand All @@ -18,7 +18,7 @@
* @property string title
* @property string content
*/
class Post extends Model
class Post extends PrefixedModel
{
/* -----------------------------------------------------------------
| Traits
Expand Down
4 changes: 2 additions & 2 deletions tests/Stubs/Models/User.php
Expand Up @@ -5,7 +5,7 @@
namespace Arcanedev\LaravelNotes\Tests\Stubs\Models;

use Arcanedev\LaravelNotes\Traits\{AuthoredNotes, HasManyNotes};
use Arcanedev\Support\Database\Model;
use Arcanedev\Support\Database\PrefixedModel;
use Illuminate\Support\Arr;

/**
Expand All @@ -16,7 +16,7 @@
*
* @property int id
*/
class User extends Model
class User extends PrefixedModel
{
/* -----------------------------------------------------------------
| Traits
Expand Down
17 changes: 4 additions & 13 deletions tests/TestCase.php
Expand Up @@ -4,8 +4,8 @@

namespace Arcanedev\LaravelNotes\Tests;

use Arcanedev\LaravelNotes\Tests\Stubs\Models\User;
use Orchestra\Testbench\TestCase as BaseTestCase;
use Illuminate\Database\Eloquent\Factory as ModelFactory;

/**
* Class TestCase
Expand Down Expand Up @@ -33,7 +33,7 @@ public function setUp(): void
parent::setUp();

$this->migrate();
$this->loadFactories();
$this->withFactories(__DIR__.'/fixtures/factories');
}

/**
Expand All @@ -58,10 +58,10 @@ protected function getPackageProviders($app): array
protected function getEnvironmentSetUp($app): void
{
// Laravel App Configs
$app['config']->set('auth.model', Stubs\Models\User::class);
$app['config']->set('auth.model', User::class);

// Laravel Messenger Configs
$app['config']->set('notes.authors.model', Stubs\Models\User::class);
$app['config']->set('notes.authors.model', User::class);
}

/* -----------------------------------------------------------------
Expand All @@ -83,13 +83,4 @@ protected function migrate(): void
$this->loadMigrationsFrom($path);
}
}

/**
* Load Model Factories.
*/
private function loadFactories(): void
{
$this->factory = $this->app->make(ModelFactory::class);
$this->factory->load(__DIR__.'/fixtures/factories');
}
}
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use Arcanedev\LaravelNotes\Bases\Migration;
use Arcanedev\LaravelNotes\Database\Migration;
use Illuminate\Database\Schema\Blueprint;

/**
Expand Down

0 comments on commit d6765d2

Please sign in to comment.