From 0fa36cb77a7c810c2bc721b34353b87f7d87f522 Mon Sep 17 00:00:00 2001 From: Magnus Boye Date: Wed, 16 Sep 2020 19:29:31 +0200 Subject: [PATCH 1/3] Update HasRelationshipObservables.php --- src/Traits/HasRelationshipObservables.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Traits/HasRelationshipObservables.php b/src/Traits/HasRelationshipObservables.php index 2ce5ead..2061f1b 100644 --- a/src/Traits/HasRelationshipObservables.php +++ b/src/Traits/HasRelationshipObservables.php @@ -26,6 +26,7 @@ trait HasRelationshipObservables */ public static function bootHasRelationshipObservables() { + static::$relationshipObservables = []; $methods = collect( class_uses(static::class) )->filter(function ($trait) { From b2c00602a639907176a99984e9c9c3a4a8f7aab2 Mon Sep 17 00:00:00 2001 From: magnusboye Date: Tue, 22 Sep 2020 21:00:44 +0200 Subject: [PATCH 2/3] Add failing test. Remove fix that I made for the tests. --- src/Traits/HasRelationshipObservables.php | 1 - .../HasRelationshipObservablesTraitTest.php | 69 +++++++++++++++++++ tests/Stubs/Jobs/TestJob.php | 20 ++++++ tests/Stubs/Observers/UserObserver.php | 11 +++ tests/Stubs/User.php | 11 ++- 5 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 tests/Feature/HasRelationshipObservablesTraitTest.php create mode 100644 tests/Stubs/Jobs/TestJob.php create mode 100644 tests/Stubs/Observers/UserObserver.php diff --git a/src/Traits/HasRelationshipObservables.php b/src/Traits/HasRelationshipObservables.php index 2061f1b..2ce5ead 100644 --- a/src/Traits/HasRelationshipObservables.php +++ b/src/Traits/HasRelationshipObservables.php @@ -26,7 +26,6 @@ trait HasRelationshipObservables */ public static function bootHasRelationshipObservables() { - static::$relationshipObservables = []; $methods = collect( class_uses(static::class) )->filter(function ($trait) { diff --git a/tests/Feature/HasRelationshipObservablesTraitTest.php b/tests/Feature/HasRelationshipObservablesTraitTest.php new file mode 100644 index 0000000..de43f14 --- /dev/null +++ b/tests/Feature/HasRelationshipObservablesTraitTest.php @@ -0,0 +1,69 @@ + 'admin']); + $user->roles()->attach($role); + + + $this->assertEquals( + collect(User::getRelationshipObservables())->count(), + collect(User::getRelationshipObservables())->unique()->count() + ); + } + + /** @test */ + public function it_fails_second_time() + { + $this->withoutJobs(); + $this->beforeApplicationDestroyed(function () { + $this->assertCount(1, $this->dispatchedJobs); + }); + + $user = User::create(); + $role = Role::create(['name' => 'admin']); + $user->roles()->attach($role); + + $this->assertEquals( + collect(User::getRelationshipObservables())->count(), + collect(User::getRelationshipObservables())->unique()->count() + ); + + } + + /** @test */ + public function it_fails_even_greater_third_time() + { + $this->withoutJobs(); + $this->beforeApplicationDestroyed(function () { + $this->assertCount(1, $this->dispatchedJobs); + }); + + $user = User::create(); + $role = Role::create(['name' => 'admin']); + $user->roles()->attach($role); + + $this->assertEquals( + collect(User::getRelationshipObservables())->count(), + collect(User::getRelationshipObservables())->unique()->count() + ); + } +} diff --git a/tests/Stubs/Jobs/TestJob.php b/tests/Stubs/Jobs/TestJob.php new file mode 100644 index 0000000..8f4262f --- /dev/null +++ b/tests/Stubs/Jobs/TestJob.php @@ -0,0 +1,20 @@ +increments('id'); From 35f673c40542d744a70802ab25b239853a5d4b56 Mon Sep 17 00:00:00 2001 From: magnusboye Date: Tue, 22 Sep 2020 21:11:38 +0200 Subject: [PATCH 3/3] Fix test as all tests are being in nonparallel. --- .../HasRelationshipObservablesTraitTest.php | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/tests/Feature/HasRelationshipObservablesTraitTest.php b/tests/Feature/HasRelationshipObservablesTraitTest.php index de43f14..54e786e 100644 --- a/tests/Feature/HasRelationshipObservablesTraitTest.php +++ b/tests/Feature/HasRelationshipObservablesTraitTest.php @@ -17,7 +17,7 @@ public function setup(): void } /** @test */ - public function it_succeeds_first_time() + public function it_fails_first_time() { $user = User::create(); $role = Role::create(['name' => 'admin']); @@ -31,7 +31,7 @@ public function it_succeeds_first_time() } /** @test */ - public function it_fails_second_time() + public function it_fails_even_greater_second_time() { $this->withoutJobs(); $this->beforeApplicationDestroyed(function () { @@ -48,22 +48,4 @@ public function it_fails_second_time() ); } - - /** @test */ - public function it_fails_even_greater_third_time() - { - $this->withoutJobs(); - $this->beforeApplicationDestroyed(function () { - $this->assertCount(1, $this->dispatchedJobs); - }); - - $user = User::create(); - $role = Role::create(['name' => 'admin']); - $user->roles()->attach($role); - - $this->assertEquals( - collect(User::getRelationshipObservables())->count(), - collect(User::getRelationshipObservables())->unique()->count() - ); - } }