From 622c4e9b568da1d85958dc91e3cac0a420902657 Mon Sep 17 00:00:00 2001 From: Viacheslav Ostrovskiy Date: Wed, 4 Sep 2019 00:41:56 +0300 Subject: [PATCH 1/4] Cleanup --- src/BelongsTo.php | 8 ++- src/BelongsToMany.php | 8 ++- src/Concerns/HasBelongsToEvents.php | 7 +++ src/Concerns/HasBelongsToManyEvents.php | 7 +++ src/Concerns/HasManyEvents.php | 7 +++ src/Concerns/HasMorphManyEvents.php | 7 +++ src/Concerns/HasMorphOneEvents.php | 7 +++ src/Concerns/HasMorphToEvents.php | 7 +++ src/Concerns/HasMorphToManyEvents.php | 7 +++ src/Concerns/HasMorphedByManyEvents.php | 7 +++ src/Concerns/HasOneEvents.php | 7 +++ src/HasMany.php | 5 ++ src/HasOne.php | 5 ++ src/MorphMany.php | 5 ++ src/MorphOne.php | 5 ++ src/MorphTo.php | 8 ++- src/MorphToMany.php | 8 ++- src/MorphedByMany.php | 8 ++- src/RelationshipEventsServiceProvider.php | 5 ++ src/Traits/HasDispatchableEvents.php | 7 +++ src/Traits/HasEventDispatcher.php | 5 ++ src/Traits/HasOneOrManyMethods.php | 9 +++- src/Traits/HasRelationshipObservables.php | 55 +++++++++++--------- tests/Feature/HasMorphToEventsTest.php | 12 ++--- tests/Feature/HasMorphToManyEventsTest.php | 16 +++--- tests/Feature/HasMorphedByManyEventsTest.php | 28 +++++----- tests/Feature/HasOneEventsTest.php | 12 ++--- tests/Stubs/Address.php | 3 +- tests/Stubs/Comment.php | 3 +- tests/Stubs/Post.php | 3 +- tests/Stubs/Profile.php | 3 +- tests/Stubs/Role.php | 6 ++- tests/Stubs/Tag.php | 6 ++- tests/Stubs/User.php | 3 +- tests/TestCase.php | 3 +- 35 files changed, 226 insertions(+), 76 deletions(-) diff --git a/src/BelongsTo.php b/src/BelongsTo.php index 266744c..ed4965b 100644 --- a/src/BelongsTo.php +++ b/src/BelongsTo.php @@ -4,9 +4,15 @@ use Chelout\RelationshipEvents\Contracts\EventDispatcher; use Chelout\RelationshipEvents\Traits\HasEventDispatcher; -use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo as BelongsToBase; +/** + * Class BelongsTo + * + * @package Chelout\RelationshipEvents + * + * @property-read \Chelout\RelationshipEvents\Concerns\HasBelongsToEvents $parent + */ class BelongsTo extends BelongsToBase implements EventDispatcher { use HasEventDispatcher; diff --git a/src/BelongsToMany.php b/src/BelongsToMany.php index d38a02f..20a8f19 100644 --- a/src/BelongsToMany.php +++ b/src/BelongsToMany.php @@ -4,9 +4,15 @@ use Chelout\RelationshipEvents\Contracts\EventDispatcher; use Chelout\RelationshipEvents\Traits\HasEventDispatcher; -use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany as BelongsToManyBase; +/** + * Class BelongsToMany + * + * @package Chelout\RelationshipEvents + * + * @property-read \Chelout\RelationshipEvents\Concerns\HasBelongsToManyEvents $parent + */ class BelongsToMany extends BelongsToManyBase implements EventDispatcher { use HasEventDispatcher; diff --git a/src/Concerns/HasBelongsToEvents.php b/src/Concerns/HasBelongsToEvents.php index 61d475a..4d98fd2 100644 --- a/src/Concerns/HasBelongsToEvents.php +++ b/src/Concerns/HasBelongsToEvents.php @@ -6,6 +6,13 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +/** + * Trait HasBelongsToEvents + * + * @package Chelout\RelationshipEvents\Concerns + * + * @mixin \Chelout\RelationshipEvents\Traits\HasDispatchableEvents + */ trait HasBelongsToEvents { /** diff --git a/src/Concerns/HasBelongsToManyEvents.php b/src/Concerns/HasBelongsToManyEvents.php index d9f7015..0c10d11 100644 --- a/src/Concerns/HasBelongsToManyEvents.php +++ b/src/Concerns/HasBelongsToManyEvents.php @@ -7,6 +7,13 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +/** + * Trait HasBelongsToManyEvents + * + * @package Chelout\RelationshipEvents\Concerns + * + * @mixin \Chelout\RelationshipEvents\Traits\HasDispatchableEvents + */ trait HasBelongsToManyEvents { /** diff --git a/src/Concerns/HasManyEvents.php b/src/Concerns/HasManyEvents.php index 73ea12b..988a58e 100644 --- a/src/Concerns/HasManyEvents.php +++ b/src/Concerns/HasManyEvents.php @@ -6,6 +6,13 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +/** + * Trait HasManyEvents + * + * @package Chelout\RelationshipEvents\Concerns + * + * @mixin \Chelout\RelationshipEvents\Traits\HasDispatchableEvents + */ trait HasManyEvents { /** diff --git a/src/Concerns/HasMorphManyEvents.php b/src/Concerns/HasMorphManyEvents.php index d325974..b47b2a7 100644 --- a/src/Concerns/HasMorphManyEvents.php +++ b/src/Concerns/HasMorphManyEvents.php @@ -6,6 +6,13 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +/** + * Trait HasMorphManyEvents + * + * @package Chelout\RelationshipEvents\Concerns + * + * @mixin \Chelout\RelationshipEvents\Traits\HasDispatchableEvents + */ trait HasMorphManyEvents { /** diff --git a/src/Concerns/HasMorphOneEvents.php b/src/Concerns/HasMorphOneEvents.php index 68e5db6..b5908ae 100644 --- a/src/Concerns/HasMorphOneEvents.php +++ b/src/Concerns/HasMorphOneEvents.php @@ -6,6 +6,13 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +/** + * Trait HasMorphOneEvents + * + * @package Chelout\RelationshipEvents\Concerns + * + * @mixin \Chelout\RelationshipEvents\Traits\HasDispatchableEvents + */ trait HasMorphOneEvents { /** diff --git a/src/Concerns/HasMorphToEvents.php b/src/Concerns/HasMorphToEvents.php index 7654d06..853da3b 100644 --- a/src/Concerns/HasMorphToEvents.php +++ b/src/Concerns/HasMorphToEvents.php @@ -6,6 +6,13 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +/** + * Trait HasMorphToEvents + * + * @package Chelout\RelationshipEvents\Concerns + * + * @mixin \Chelout\RelationshipEvents\Traits\HasDispatchableEvents + */ trait HasMorphToEvents { /** diff --git a/src/Concerns/HasMorphToManyEvents.php b/src/Concerns/HasMorphToManyEvents.php index ec83dff..b600b09 100644 --- a/src/Concerns/HasMorphToManyEvents.php +++ b/src/Concerns/HasMorphToManyEvents.php @@ -7,6 +7,13 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +/** + * Trait HasMorphToManyEvents + * + * @package Chelout\RelationshipEvents\Concerns + * + * @mixin \Chelout\RelationshipEvents\Traits\HasDispatchableEvents + */ trait HasMorphToManyEvents { /** diff --git a/src/Concerns/HasMorphedByManyEvents.php b/src/Concerns/HasMorphedByManyEvents.php index a74963a..989467e 100644 --- a/src/Concerns/HasMorphedByManyEvents.php +++ b/src/Concerns/HasMorphedByManyEvents.php @@ -7,6 +7,13 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +/** + * Trait HasMorphedByManyEvents + * + * @package Chelout\RelationshipEvents\Concerns + * + * @mixin \Chelout\RelationshipEvents\Traits\HasDispatchableEvents + */ trait HasMorphedByManyEvents { /** diff --git a/src/Concerns/HasOneEvents.php b/src/Concerns/HasOneEvents.php index d0b0746..fa06577 100644 --- a/src/Concerns/HasOneEvents.php +++ b/src/Concerns/HasOneEvents.php @@ -6,6 +6,13 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +/** + * Trait HasOneEvents + * + * @package Chelout\RelationshipEvents\Concerns + * + * @mixin \Chelout\RelationshipEvents\Traits\HasDispatchableEvents + */ trait HasOneEvents { /** diff --git a/src/HasMany.php b/src/HasMany.php index 4db157a..fda73a8 100644 --- a/src/HasMany.php +++ b/src/HasMany.php @@ -7,6 +7,11 @@ use Chelout\RelationshipEvents\Traits\HasOneOrManyMethods; use Illuminate\Database\Eloquent\Relations\HasMany as HasManyBase; +/** + * Class HasMany + * + * @package Chelout\RelationshipEvents + */ class HasMany extends HasManyBase implements EventDispatcher { use HasEventDispatcher; diff --git a/src/HasOne.php b/src/HasOne.php index 2bd3493..4bfccf1 100644 --- a/src/HasOne.php +++ b/src/HasOne.php @@ -7,6 +7,11 @@ use Chelout\RelationshipEvents\Traits\HasOneOrManyMethods; use Illuminate\Database\Eloquent\Relations\HasOne as HasOneBase; +/** + * Class HasOne + * + * @package Chelout\RelationshipEvents + */ class HasOne extends HasOneBase implements EventDispatcher { use HasEventDispatcher; diff --git a/src/MorphMany.php b/src/MorphMany.php index b48038e..c395854 100644 --- a/src/MorphMany.php +++ b/src/MorphMany.php @@ -8,6 +8,11 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphMany as MorphManyBase; +/** + * Class MorphMany + * + * @package Chelout\RelationshipEvents + */ class MorphMany extends MorphManyBase implements EventDispatcher { use HasEventDispatcher; diff --git a/src/MorphOne.php b/src/MorphOne.php index 789de87..441ba59 100644 --- a/src/MorphOne.php +++ b/src/MorphOne.php @@ -7,6 +7,11 @@ use Chelout\RelationshipEvents\Traits\HasOneOrManyMethods; use Illuminate\Database\Eloquent\Relations\MorphOne as MorphOneBase; +/** + * Class MorphOne + * + * @package Chelout\RelationshipEvents + */ class MorphOne extends MorphOneBase implements EventDispatcher { use HasEventDispatcher; diff --git a/src/MorphTo.php b/src/MorphTo.php index bfb0779..7ebaf1b 100644 --- a/src/MorphTo.php +++ b/src/MorphTo.php @@ -4,9 +4,15 @@ use Chelout\RelationshipEvents\Contracts\EventDispatcher; use Chelout\RelationshipEvents\Traits\HasEventDispatcher; -use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphTo as MorphToBase; +/** + * Class MorphTo + * + * @package Chelout\RelationshipEvents + * + * @property-read \Chelout\RelationshipEvents\Concerns\HasMorphToEvents $parent + */ class MorphTo extends MorphToBase implements EventDispatcher { use HasEventDispatcher; diff --git a/src/MorphToMany.php b/src/MorphToMany.php index b398216..cbea875 100644 --- a/src/MorphToMany.php +++ b/src/MorphToMany.php @@ -4,9 +4,15 @@ use Chelout\RelationshipEvents\Contracts\EventDispatcher; use Chelout\RelationshipEvents\Traits\HasEventDispatcher; -use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphToMany as MorphToManyBase; +/** + * Class MorphToMany + * + * @package Chelout\RelationshipEvents + * + * @property-read \Chelout\RelationshipEvents\Concerns\HasMorphToManyEvents $parent + */ class MorphToMany extends MorphToManyBase implements EventDispatcher { use HasEventDispatcher; diff --git a/src/MorphedByMany.php b/src/MorphedByMany.php index eaa1cd3..983f068 100644 --- a/src/MorphedByMany.php +++ b/src/MorphedByMany.php @@ -4,9 +4,15 @@ use Chelout\RelationshipEvents\Contracts\EventDispatcher; use Chelout\RelationshipEvents\Traits\HasEventDispatcher; -use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphToMany as MorphToManyBase; +/** + * Class MorphedByMany + * + * @package Chelout\RelationshipEvents + * + * @property-read \Chelout\RelationshipEvents\Concerns\HasMorphedByManyEvents $parent + */ class MorphedByMany extends MorphToManyBase implements EventDispatcher { use HasEventDispatcher; diff --git a/src/RelationshipEventsServiceProvider.php b/src/RelationshipEventsServiceProvider.php index fbc6d2b..30e42af 100644 --- a/src/RelationshipEventsServiceProvider.php +++ b/src/RelationshipEventsServiceProvider.php @@ -4,6 +4,11 @@ use Illuminate\Support\ServiceProvider; +/** + * Class RelationshipEventsServiceProvider + * + * @package Chelout\RelationshipEvents + */ class RelationshipEventsServiceProvider extends ServiceProvider { /** diff --git a/src/Traits/HasDispatchableEvents.php b/src/Traits/HasDispatchableEvents.php index e50a182..b8e0d83 100644 --- a/src/Traits/HasDispatchableEvents.php +++ b/src/Traits/HasDispatchableEvents.php @@ -2,6 +2,13 @@ namespace Chelout\RelationshipEvents\Traits; +/** + * Trait HasDispatchableEvents + * + * @package Chelout\RelationshipEvents\Traits + * + * @mixin \Illuminate\Database\Eloquent\Concerns\HasEvents + */ trait HasDispatchableEvents { /** diff --git a/src/Traits/HasEventDispatcher.php b/src/Traits/HasEventDispatcher.php index f5c6b89..aa59b2d 100644 --- a/src/Traits/HasEventDispatcher.php +++ b/src/Traits/HasEventDispatcher.php @@ -4,6 +4,11 @@ use Illuminate\Contracts\Events\Dispatcher; +/** + * Trait HasEventDispatcher + * + * @package Chelout\RelationshipEvents\Traits + */ trait HasEventDispatcher { /** diff --git a/src/Traits/HasOneOrManyMethods.php b/src/Traits/HasOneOrManyMethods.php index 5abc034..dec89e7 100644 --- a/src/Traits/HasOneOrManyMethods.php +++ b/src/Traits/HasOneOrManyMethods.php @@ -5,6 +5,13 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; +/** + * Trait HasOneOrManyMethods + * + * @package Chelout\RelationshipEvents\Traits + * + * @property-read \Illuminate\Database\Eloquent\Model $related + */ trait HasOneOrManyMethods { /** @@ -16,7 +23,7 @@ trait HasOneOrManyMethods */ public function create(array $attributes = []) { - return tap($this->related->newInstance($attributes), function ($instance) { + return tap($this->related->newInstance($attributes), function (Model $instance) { $this->fireModelRelationshipEvent('creating', $instance); $this->setForeignAttributesForCreate($instance); diff --git a/src/Traits/HasRelationshipObservables.php b/src/Traits/HasRelationshipObservables.php index 6946be2..ffe75f5 100644 --- a/src/Traits/HasRelationshipObservables.php +++ b/src/Traits/HasRelationshipObservables.php @@ -5,6 +5,13 @@ use ReflectionClass; use ReflectionMethod; +/** + * Trait HasRelationshipObservables + * + * @package Chelout\RelationshipEvents\Traits + * + * @mixin \Illuminate\Database\Eloquent\Concerns\HasEvents + */ trait HasRelationshipObservables { /** @@ -21,40 +28,26 @@ public static function bootHasRelationshipObservables() { $methods = collect( class_uses(static::class) - ) - ->filter(function ($trait) { - return starts_with($trait, 'Chelout\RelationshipEvents\Concerns'); - }) - ->flatMap(function ($trait) { - $trait = new ReflectionClass($trait); - $methods = $trait->getMethods(ReflectionMethod::IS_PUBLIC); + )->filter(function ($trait) { + return Str::startsWith($trait, 'Chelout\RelationshipEvents\Concerns'); + })->flatMap(function ($trait) { + $trait = new ReflectionClass($trait); + $methods = $trait->getMethods(ReflectionMethod::IS_PUBLIC); - return collect($methods)->filter(function ($method) { - return $method->isStatic(); - }) - ->map(function ($method) { - return $method->name; - }); - }) - ->toArray(); + return collect($methods)->filter(function (ReflectionMethod $method) { + return $method->isStatic(); + })->map(function ($method) { + return $method->name; + }); + })->toArray(); static::mergeRelationshipObservables($methods); } - /** - * Get relationship observables. - * - * @return array - */ - public static function getRelationshipObservables(): array - { - return static::$relationshipObservables; - } - /** * Merge relationship observables. * - * @param array $relationshipObservables + * @param array $relationshipObservables * * @return void */ @@ -80,4 +73,14 @@ public function getObservableEvents() $this->observables ); } + + /** + * Get relationship observables. + * + * @return array + */ + public static function getRelationshipObservables(): array + { + return static::$relationshipObservables; + } } diff --git a/tests/Feature/HasMorphToEventsTest.php b/tests/Feature/HasMorphToEventsTest.php index 5ba5a14..a4d72eb 100644 --- a/tests/Feature/HasMorphToEventsTest.php +++ b/tests/Feature/HasMorphToEventsTest.php @@ -28,13 +28,13 @@ public function it_fires_morphToAssociating_and_morphToAssociated() Event::assertDispatched( 'eloquent.morphToAssociating: ' . Comment::class, - function ($e, $callback) use ($post, $comment) { + function ($event, $callback) use ($post, $comment) { return $callback[0] == 'Chelout\RelationshipEvents\Tests\Stubs\Post' && $callback[1]->is($comment) && $callback[2]->is($post); } ); Event::assertDispatched( 'eloquent.morphToAssociated: ' . Comment::class, - function ($e, $callback) use ($post, $comment) { + function ($event, $callback) use ($post, $comment) { return $callback[0] == 'Chelout\RelationshipEvents\Tests\Stubs\Post' && $callback[1]->is($comment) && $callback[2]->is($post); } ); @@ -52,13 +52,13 @@ public function it_fires_morphToDissociating_and_morphToDissociated() Event::assertDispatched( 'eloquent.morphToDissociating: ' . Comment::class, - function ($e, $callback) use ($post, $comment) { + function ($event, $callback) use ($post, $comment) { return $callback[0] == 'Chelout\RelationshipEvents\Tests\Stubs\Post' && $callback[1]->is($comment) && $callback[2]->is($post); } ); Event::assertDispatched( 'eloquent.morphToDissociated: ' . Comment::class, - function ($e, $callback) use ($post, $comment) { + function ($event, $callback) use ($post, $comment) { return $callback[0] == 'Chelout\RelationshipEvents\Tests\Stubs\Post' && $callback[1]->is($comment) && $callback[2]->is($post); } ); @@ -76,13 +76,13 @@ public function it_fires_morphToUpdating_and_morphToUpdated() Event::assertDispatched( 'eloquent.morphToUpdating: ' . Comment::class, - function ($e, $callback) use ($post, $comment) { + function ($event, $callback) use ($post, $comment) { return $callback[0] == 'Chelout\RelationshipEvents\Tests\Stubs\Post' && $callback[1]->is($comment) && $callback[2]->is($post); } ); Event::assertDispatched( 'eloquent.morphToUpdated: ' . Comment::class, - function ($e, $callback) use ($post, $comment) { + function ($event, $callback) use ($post, $comment) { return $callback[0] == 'Chelout\RelationshipEvents\Tests\Stubs\Post' && $callback[1]->is($comment) && $callback[2]->is($post); } ); diff --git a/tests/Feature/HasMorphToManyEventsTest.php b/tests/Feature/HasMorphToManyEventsTest.php index e894933..e6031c1 100644 --- a/tests/Feature/HasMorphToManyEventsTest.php +++ b/tests/Feature/HasMorphToManyEventsTest.php @@ -28,13 +28,13 @@ public function it_fires_morphToManyAttaching_and_morphToManyAttached() Event::assertDispatched( 'eloquent.morphToManyAttaching: ' . Post::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'tags' && $callback[1]->is($post) && $callback[2][0] == $tag->id; } ); Event::assertDispatched( 'eloquent.morphToManyAttached: ' . Post::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'tags' && $callback[1]->is($post) && $callback[2][0] == $tag->id; } ); @@ -52,13 +52,13 @@ public function it_fires_morphToManyDetaching_and_morphToManyDetached() Event::assertDispatched( 'eloquent.morphToManyDetaching: ' . Post::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'tags' && $callback[1]->is($post) && $callback[2][0] == $tag->id; } ); Event::assertDispatched( 'eloquent.morphToManyDetached: ' . Post::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'tags' && $callback[1]->is($post) && $callback[2][0] == $tag->id; } ); @@ -75,13 +75,13 @@ public function it_fires_morphToManySyncing_and_morphToManySynced() Event::assertDispatched( 'eloquent.morphToManySyncing: ' . Post::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'tags' && $callback[1]->is($post) && $callback[2][0] == $tag->id; } ); Event::assertDispatched( 'eloquent.morphToManySynced: ' . Post::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'tags' && $callback[1]->is($post) && $callback[2][0] == $tag->id; } ); @@ -99,13 +99,13 @@ public function it_fires_morphToManyUpdatingExistingPivot_and_morphToManyUpdated Event::assertDispatched( 'eloquent.morphToManyUpdatingExistingPivot: ' . Post::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'tags' && $callback[1]->is($post) && $callback[2][0] == $tag->id; } ); Event::assertDispatched( 'eloquent.morphToManyUpdatedExistingPivot: ' . Post::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'tags' && $callback[1]->is($post) && $callback[2][0] == $tag->id; } ); diff --git a/tests/Feature/HasMorphedByManyEventsTest.php b/tests/Feature/HasMorphedByManyEventsTest.php index ce1155d..e72234a 100644 --- a/tests/Feature/HasMorphedByManyEventsTest.php +++ b/tests/Feature/HasMorphedByManyEventsTest.php @@ -27,13 +27,13 @@ public function it_fires_morphedByManyAttaching_and_morphedByManyAttached_when_c Event::assertDispatched( 'eloquent.morphedByManyAttaching: ' . Tag::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'posts' && $callback[1]->is($tag) && $callback[2][0] == $post->id; } ); Event::assertDispatched( 'eloquent.morphedByManyAttached: ' . Tag::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'posts' && $callback[1]->is($tag) && $callback[2][0] == $post->id; } ); @@ -49,13 +49,13 @@ public function it_fires_morphedByManyAttaching_and_morphedByManyAttached_when_s Event::assertDispatched( 'eloquent.morphedByManyAttaching: ' . Tag::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'posts' && $callback[1]->is($tag) && $callback[2][0] == $post->id; } ); Event::assertDispatched( 'eloquent.morphedByManyAttached: ' . Tag::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'posts' && $callback[1]->is($tag) && $callback[2][0] == $post->id; } ); @@ -72,13 +72,13 @@ public function it_fires_morphedByManyAttaching_and_morphedByManyAttached_when_a Event::assertDispatched( 'eloquent.morphedByManyAttaching: ' . Tag::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'posts' && $callback[1]->is($tag) && $callback[2][0] == $post->id; } ); Event::assertDispatched( 'eloquent.morphedByManyAttached: ' . Tag::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'posts' && $callback[1]->is($tag) && $callback[2][0] == $post->id; } ); @@ -96,13 +96,13 @@ public function it_fires_morphedByManyDetaching_and_morphedByManyDetached_when_d Event::assertDispatched( 'eloquent.morphedByManyDetaching: ' . Tag::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'posts' && $callback[1]->is($tag) && $callback[2][0] == $post->id; } ); Event::assertDispatched( 'eloquent.morphedByManyDetached: ' . Tag::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'posts' && $callback[1]->is($tag) && $callback[2][0] == $post->id; } ); @@ -119,13 +119,13 @@ public function it_fires_morphedByManySyncing_and_morphedByManySynced() Event::assertDispatched( 'eloquent.morphedByManySyncing: ' . Tag::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'posts' && $callback[1]->is($tag) && $callback[2][0] == $post->id; } ); Event::assertDispatched( 'eloquent.morphedByManySynced: ' . Tag::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'posts' && $callback[1]->is($tag) && $callback[2][0] == $post->id; } ); @@ -142,13 +142,13 @@ public function it_fires_morphedByManyToggling_and_morphedByManyToggled() Event::assertDispatched( 'eloquent.morphedByManyToggling: ' . Tag::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'posts' && $callback[1]->is($tag) && $callback[2][0] == $post->id; } ); Event::assertDispatched( 'eloquent.morphedByManyToggled: ' . Tag::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'posts' && $callback[1]->is($tag) && $callback[2][0] == $post->id; } ); @@ -166,13 +166,13 @@ public function it_fires_morphedByManyUpdatingExistingPivot_and_morphedByManyUpd Event::assertDispatched( 'eloquent.morphedByManyUpdatingExistingPivot: ' . Tag::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'posts' && $callback[1]->is($tag) && $callback[2][0] == $post->id; } ); Event::assertDispatched( 'eloquent.morphedByManyUpdatedExistingPivot: ' . Tag::class, - function ($e, $callback) use ($post, $tag) { + function ($event, $callback) use ($post, $tag) { return $callback[0] == 'posts' && $callback[1]->is($tag) && $callback[2][0] == $post->id; } ); diff --git a/tests/Feature/HasOneEventsTest.php b/tests/Feature/HasOneEventsTest.php index 063c8bf..713c3ca 100644 --- a/tests/Feature/HasOneEventsTest.php +++ b/tests/Feature/HasOneEventsTest.php @@ -27,13 +27,13 @@ public function it_fires_hasOneCreating_and_hasOneCreated_when_a_belonged_model_ Event::assertDispatched( 'eloquent.hasOneCreating: ' . User::class, - function ($e, $callback) use ($user, $profile) { + function ($event, $callback) use ($user, $profile) { return $callback[0]->is($user) && $callback[1]->is($profile); } ); Event::assertDispatched( 'eloquent.hasOneCreated: ' . User::class, - function ($e, $callback) use ($user, $profile) { + function ($event, $callback) use ($user, $profile) { return $callback[0]->is($user) && $callback[1]->is($profile); } ); @@ -49,13 +49,13 @@ public function it_fires_hasOneSaving_and_hasOneSaved_when_a_belonged_model_save Event::assertDispatched( 'eloquent.hasOneSaving: ' . User::class, - function ($e, $callback) use ($user, $profile) { + function ($event, $callback) use ($user, $profile) { return $callback[0]->is($user) && $callback[1]->is($profile); } ); Event::assertDispatched( 'eloquent.hasOneSaved: ' . User::class, - function ($e, $callback) use ($user, $profile) { + function ($event, $callback) use ($user, $profile) { return $callback[0]->is($user) && $callback[1]->is($profile); } ); @@ -72,13 +72,13 @@ public function it_fires_hasOneUpdating_and_hasOneUpdated_when_a_belonged_model_ Event::assertDispatched( 'eloquent.hasOneUpdating: ' . User::class, - function ($e, $callback) use ($user, $profile) { + function ($event, $callback) use ($user, $profile) { return $callback[0]->is($user) && $callback[1]->is($profile); } ); Event::assertDispatched( 'eloquent.hasOneUpdated: ' . User::class, - function ($e, $callback) use ($user, $profile) { + function ($event, $callback) use ($user, $profile) { return $callback[0]->is($user) && $callback[1]->is($profile); } ); diff --git a/tests/Stubs/Address.php b/tests/Stubs/Address.php index bf4aff0..a0c353a 100644 --- a/tests/Stubs/Address.php +++ b/tests/Stubs/Address.php @@ -3,6 +3,7 @@ namespace Chelout\RelationshipEvents\Tests\Stubs; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class Address extends Model @@ -11,7 +12,7 @@ class Address extends Model public static function setupTable() { - Schema::create('addresses', function ($table) { + Schema::create('addresses', function (Blueprint $table) { $table->increments('id'); $table->string('addressable_id'); $table->string('addressable_type'); diff --git a/tests/Stubs/Comment.php b/tests/Stubs/Comment.php index e963331..90421d8 100644 --- a/tests/Stubs/Comment.php +++ b/tests/Stubs/Comment.php @@ -4,6 +4,7 @@ use Chelout\RelationshipEvents\Concerns\HasMorphToEvents; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class Comment extends Model @@ -14,7 +15,7 @@ class Comment extends Model public static function setupTable() { - Schema::create('comments', function ($table) { + Schema::create('comments', function (Blueprint $table) { $table->increments('id'); $table->string('commentable_id')->nullable(); $table->string('commentable_type')->nullable(); diff --git a/tests/Stubs/Post.php b/tests/Stubs/Post.php index 2748787..d752d67 100644 --- a/tests/Stubs/Post.php +++ b/tests/Stubs/Post.php @@ -5,6 +5,7 @@ use Chelout\RelationshipEvents\Concerns\HasMorphManyEvents; use Chelout\RelationshipEvents\Concerns\HasMorphToManyEvents; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class Post extends Model @@ -16,7 +17,7 @@ class Post extends Model public static function setupTable() { - Schema::create('posts', function ($table) { + Schema::create('posts', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('user_id')->nullable(); $table->timestamps(); diff --git a/tests/Stubs/Profile.php b/tests/Stubs/Profile.php index 388adf6..5d300d1 100644 --- a/tests/Stubs/Profile.php +++ b/tests/Stubs/Profile.php @@ -4,6 +4,7 @@ use Chelout\RelationshipEvents\Concerns\HasBelongsToEvents; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class Profile extends Model @@ -14,7 +15,7 @@ class Profile extends Model public static function setupTable() { - Schema::create('profiles', function ($table) { + Schema::create('profiles', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('user_id')->nullable(); $table->timestamps(); diff --git a/tests/Stubs/Role.php b/tests/Stubs/Role.php index a66682b..eb46231 100644 --- a/tests/Stubs/Role.php +++ b/tests/Stubs/Role.php @@ -3,6 +3,7 @@ namespace Chelout\RelationshipEvents\Tests\Stubs; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class Role extends Model @@ -11,12 +12,13 @@ class Role extends Model public static function setupTable() { - Schema::create('roles', function ($table) { + Schema::create('roles', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->timestamps(); }); - Schema::create('role_user', function ($table) { + + Schema::create('role_user', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('role_id'); $table->unsignedInteger('user_id'); diff --git a/tests/Stubs/Tag.php b/tests/Stubs/Tag.php index 94307a5..3152b8c 100644 --- a/tests/Stubs/Tag.php +++ b/tests/Stubs/Tag.php @@ -4,6 +4,7 @@ use Chelout\RelationshipEvents\Concerns\HasMorphedByManyEvents; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class Tag extends Model @@ -14,11 +15,12 @@ class Tag extends Model public static function setupTable() { - Schema::create('tags', function ($table) { + Schema::create('tags', function (Blueprint $table) { $table->increments('id'); $table->timestamps(); }); - Schema::create('taggables', function ($table) { + + Schema::create('taggables', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('tag_id'); $table->unsignedInteger('taggable_id'); diff --git a/tests/Stubs/User.php b/tests/Stubs/User.php index 2d65f82..a75b496 100644 --- a/tests/Stubs/User.php +++ b/tests/Stubs/User.php @@ -7,6 +7,7 @@ use Chelout\RelationshipEvents\Concerns\HasMorphOneEvents; use Chelout\RelationshipEvents\Concerns\HasOneEvents; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class User extends Model @@ -18,7 +19,7 @@ class User extends Model public static function setupTable() { - Schema::create('users', function ($table) { + Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->timestamps(); }); diff --git a/tests/TestCase.php b/tests/TestCase.php index b49231a..0c23b0c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,8 +3,9 @@ namespace Chelout\RelationshipEvents\Tests; use Chelout\RelationshipEvents\RelationshipEventsServiceProvider; +use Orchestra\Testbench\TestCase as BaseTestCase; -class TestCase extends \Orchestra\Testbench\TestCase +class TestCase extends BaseTestCase { /** * @param \Illuminate\Foundation\Application $app From f812fbd4f772d6bca678267619d26331f00c0365 Mon Sep 17 00:00:00 2001 From: Viacheslav Ostrovskiy Date: Wed, 4 Sep 2019 00:44:05 +0300 Subject: [PATCH 2/4] Fixed variable might have been defined --- src/MorphTo.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/MorphTo.php b/src/MorphTo.php index 7ebaf1b..2e58c36 100644 --- a/src/MorphTo.php +++ b/src/MorphTo.php @@ -68,7 +68,8 @@ public function update(array $attributes) $this->parent->fireModelMorphToEvent('updating', $this->relationName, $related); - if ($related && $result = $related->fill($attributes)->save()) { + $result = $related->fill($attributes)->save(); + if ($related && $result) { $this->parent->fireModelMorphToEvent('updated', $this->relationName, $related); } From 126965f9c70378c08cfbd77b1b7ef6ecbb00139e Mon Sep 17 00:00:00 2001 From: Viacheslav Ostrovskiy Date: Wed, 4 Sep 2019 01:03:13 +0300 Subject: [PATCH 3/4] =?UTF-8?q?Added=20=E2=80=98replicating=E2=80=99=20eve?= =?UTF-8?q?nt=20introduced=20in=205.8.10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Traits/HasRelationshipObservables.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Traits/HasRelationshipObservables.php b/src/Traits/HasRelationshipObservables.php index ffe75f5..ca37ffc 100644 --- a/src/Traits/HasRelationshipObservables.php +++ b/src/Traits/HasRelationshipObservables.php @@ -66,7 +66,7 @@ public function getObservableEvents() return array_merge( [ 'retrieved', 'creating', 'created', 'updating', 'updated', - 'saving', 'saved', 'restoring', 'restored', + 'saving', 'saved', 'restoring', 'restored', 'replicating', 'deleting', 'deleted', 'forceDeleted', ], static::getRelationshipObservables(), From a326986e83e0ba0e9a43c77fe83ad1c425be041b Mon Sep 17 00:00:00 2001 From: Viacheslav Ostrovskiy Date: Wed, 4 Sep 2019 22:15:09 +0300 Subject: [PATCH 4/4] Updated to Laravel 6.0 --- .travis.yml | 6 +++--- composer.json | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3229ac1..41d79cd 100755 --- a/.travis.yml +++ b/.travis.yml @@ -7,15 +7,15 @@ env: 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 - php: 7.3 env: setup=lowest + - php: 7.4 + - php: 7.4 + env: setup=lowest sudo: false diff --git a/composer.json b/composer.json index e5b0f64..1989979 100755 --- a/composer.json +++ b/composer.json @@ -11,15 +11,16 @@ } ], "require": { - "php": "^7.1.3", - "illuminate/container": "~5.8.0", - "illuminate/database": "~5.8.0", - "illuminate/events": "~5.8.0", - "illuminate/support": "~5.8.0" + "php": "^7.2", + "illuminate/container": "^6.0", + "illuminate/database": "^6.0", + "illuminate/events": "^6.0", + "illuminate/support": "^6.0" }, "require-dev": { - "phpunit/phpunit": "~7.0|~8.0", - "orchestra/testbench": "3.8.*" + "phpunit/phpunit": "^8.3", + "orchestra/testbench-core": "^4.0", + "orchestra/testbench": "^4.0" }, "autoload": { "psr-4": {