From 9388c1690adf4454eba82a0cb9410999dca1d406 Mon Sep 17 00:00:00 2001 From: John Braun Date: Thu, 3 Oct 2019 01:24:01 +0200 Subject: [PATCH 01/11] Add a method allowing overriding the causer to null By calling `activity()->causedByAnonymous()->...` the activity will not be associated with a certain causer model --- src/ActivityLogger.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ActivityLogger.php b/src/ActivityLogger.php index 147a6e90..97804b78 100644 --- a/src/ActivityLogger.php +++ b/src/ActivityLogger.php @@ -72,6 +72,14 @@ public function causedBy($modelOrId) return $this; } + public function causedByAnonymous() + { + $this->activity->causer_id = null; + $this->activity->causer_type = null; + + return $this; + } + public function by($modelOrId) { return $this->causedBy($modelOrId); From 6fa10b5e2706709e7042f07a6a78459ca948d506 Mon Sep 17 00:00:00 2001 From: John Braun Date: Thu, 3 Oct 2019 01:24:41 +0200 Subject: [PATCH 02/11] Add tests for logging activity by anonymous causers --- tests/ActivityLoggerTest.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/ActivityLoggerTest.php b/tests/ActivityLoggerTest.php index 5040f952..a0e2fac8 100644 --- a/tests/ActivityLoggerTest.php +++ b/tests/ActivityLoggerTest.php @@ -195,6 +195,42 @@ public function it_will_use_the_logged_in_user_as_the_causer_by_default() $this->assertEquals($userId, $this->getLastActivity()->causer->id); } + /** + * @test + * + * @requires !Travis + */ + public function it_can_log_activity_using_an_anonymous_causer() + { + activity() + ->causedByAnonymous() + ->log('hello poetsvrouwman'); + + + $this->assertEquals(null, $this->getLastActivity()->causer_id); + $this->assertEquals(null, $this->getLastActivity()->causer_type); + } + + /** + * @test + * + * @requires !Travis + */ + public function it_will_override_the_logged_in_user_as_the_causer_when_an_anonymous_causer_is_specified() + { + $userId = 1; + + Auth::login(User::find($userId)); + + activity() + ->causedByAnonymous() + ->log('hello poetsvrouwman'); + + + $this->assertEquals(null, $this->getLastActivity()->causer_id); + $this->assertEquals(null, $this->getLastActivity()->causer_type); + } + /** @test */ public function it_can_replace_the_placeholders() { From 0742e813df2213e537856d14f0a15b45e1739eef Mon Sep 17 00:00:00 2001 From: John Braun Date: Thu, 3 Oct 2019 01:37:46 +0200 Subject: [PATCH 03/11] Fix coding style --- tests/ActivityLoggerTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/ActivityLoggerTest.php b/tests/ActivityLoggerTest.php index a0e2fac8..b09ecc95 100644 --- a/tests/ActivityLoggerTest.php +++ b/tests/ActivityLoggerTest.php @@ -206,7 +206,6 @@ public function it_can_log_activity_using_an_anonymous_causer() ->causedByAnonymous() ->log('hello poetsvrouwman'); - $this->assertEquals(null, $this->getLastActivity()->causer_id); $this->assertEquals(null, $this->getLastActivity()->causer_type); } @@ -226,7 +225,6 @@ public function it_will_override_the_logged_in_user_as_the_causer_when_an_anonym ->causedByAnonymous() ->log('hello poetsvrouwman'); - $this->assertEquals(null, $this->getLastActivity()->causer_id); $this->assertEquals(null, $this->getLastActivity()->causer_type); } From d3efff378ff86cd35bd6690f93e37f9a87b7be5e Mon Sep 17 00:00:00 2001 From: John Braun Date: Fri, 4 Oct 2019 11:09:40 +0200 Subject: [PATCH 04/11] Add anonymous method aliases --- src/ActivityLogger.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ActivityLogger.php b/src/ActivityLogger.php index 97804b78..6cf06764 100644 --- a/src/ActivityLogger.php +++ b/src/ActivityLogger.php @@ -59,6 +59,11 @@ public function on(Model $model) return $this->performedOn($model); } + public function onAnonymous() + { + return $this->causedByAnonymous(); + } + public function causedBy($modelOrId) { if ($modelOrId === null) { @@ -85,6 +90,11 @@ public function by($modelOrId) return $this->causedBy($modelOrId); } + public function byAnonymous() + { + return $this->causedByAnonymous(); + } + public function withProperties($properties) { $this->getActivity()->properties = collect($properties); From 8e30bfe42e179dc308c0adb65df8d8c97ad86dfa Mon Sep 17 00:00:00 2001 From: John Braun Date: Fri, 4 Oct 2019 11:12:55 +0200 Subject: [PATCH 05/11] Update test annotation --- tests/ActivityLoggerTest.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/ActivityLoggerTest.php b/tests/ActivityLoggerTest.php index b09ecc95..2da6da60 100644 --- a/tests/ActivityLoggerTest.php +++ b/tests/ActivityLoggerTest.php @@ -195,11 +195,7 @@ public function it_will_use_the_logged_in_user_as_the_causer_by_default() $this->assertEquals($userId, $this->getLastActivity()->causer->id); } - /** - * @test - * - * @requires !Travis - */ + /** @test */ public function it_can_log_activity_using_an_anonymous_causer() { activity() From 21c115655066cb7c1febfaaf01086701c5bd2600 Mon Sep 17 00:00:00 2001 From: John Braun Date: Fri, 4 Oct 2019 11:13:20 +0200 Subject: [PATCH 06/11] Update test method to assertNull --- tests/ActivityLoggerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ActivityLoggerTest.php b/tests/ActivityLoggerTest.php index 2da6da60..03bd1de4 100644 --- a/tests/ActivityLoggerTest.php +++ b/tests/ActivityLoggerTest.php @@ -202,8 +202,8 @@ public function it_can_log_activity_using_an_anonymous_causer() ->causedByAnonymous() ->log('hello poetsvrouwman'); - $this->assertEquals(null, $this->getLastActivity()->causer_id); - $this->assertEquals(null, $this->getLastActivity()->causer_type); + $this->assertNull($this->getLastActivity()->causer_id); + $this->assertNull($this->getLastActivity()->causer_type); } /** From 9c6f40c2f5bde39c9d7f221f0c0fbd488184e2a5 Mon Sep 17 00:00:00 2001 From: John Braun Date: Fri, 4 Oct 2019 11:19:33 +0200 Subject: [PATCH 07/11] Update test methods to assertNull --- tests/ActivityLoggerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ActivityLoggerTest.php b/tests/ActivityLoggerTest.php index 03bd1de4..ef84e922 100644 --- a/tests/ActivityLoggerTest.php +++ b/tests/ActivityLoggerTest.php @@ -221,8 +221,8 @@ public function it_will_override_the_logged_in_user_as_the_causer_when_an_anonym ->causedByAnonymous() ->log('hello poetsvrouwman'); - $this->assertEquals(null, $this->getLastActivity()->causer_id); - $this->assertEquals(null, $this->getLastActivity()->causer_type); + $this->assertNull($this->getLastActivity()->causer_id); + $this->assertNull($this->getLastActivity()->causer_type); } /** @test */ From 3f5be6cc8a79beee388477ee5df436435222ef92 Mon Sep 17 00:00:00 2001 From: John Braun Date: Fri, 4 Oct 2019 11:35:16 +0200 Subject: [PATCH 08/11] Test byAnonymous() alias --- tests/ActivityLoggerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ActivityLoggerTest.php b/tests/ActivityLoggerTest.php index ef84e922..37b0a3e2 100644 --- a/tests/ActivityLoggerTest.php +++ b/tests/ActivityLoggerTest.php @@ -218,7 +218,7 @@ public function it_will_override_the_logged_in_user_as_the_causer_when_an_anonym Auth::login(User::find($userId)); activity() - ->causedByAnonymous() + ->byAnonymous() ->log('hello poetsvrouwman'); $this->assertNull($this->getLastActivity()->causer_id); From 54037f5e6501e7efee13d27bca523b607622f57b Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Sun, 6 Oct 2019 14:46:08 +0200 Subject: [PATCH 09/11] on is for subject not causer --- src/ActivityLogger.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/ActivityLogger.php b/src/ActivityLogger.php index 6cf06764..1b72dba7 100644 --- a/src/ActivityLogger.php +++ b/src/ActivityLogger.php @@ -59,11 +59,6 @@ public function on(Model $model) return $this->performedOn($model); } - public function onAnonymous() - { - return $this->causedByAnonymous(); - } - public function causedBy($modelOrId) { if ($modelOrId === null) { From afe8f69ee94988d34aca3a1a862f556b87e9893f Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Sun, 6 Oct 2019 14:47:06 +0200 Subject: [PATCH 10/11] place methods together --- src/ActivityLogger.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ActivityLogger.php b/src/ActivityLogger.php index 1b72dba7..40532ebc 100644 --- a/src/ActivityLogger.php +++ b/src/ActivityLogger.php @@ -72,6 +72,11 @@ public function causedBy($modelOrId) return $this; } + public function by($modelOrId) + { + return $this->causedBy($modelOrId); + } + public function causedByAnonymous() { $this->activity->causer_id = null; @@ -80,11 +85,6 @@ public function causedByAnonymous() return $this; } - public function by($modelOrId) - { - return $this->causedBy($modelOrId); - } - public function byAnonymous() { return $this->causedByAnonymous(); From 282a60ad18654a8fd72f712705386cb772aed047 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Sun, 6 Oct 2019 14:48:20 +0200 Subject: [PATCH 11/11] exec both tests on travis --- tests/ActivityLoggerTest.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/ActivityLoggerTest.php b/tests/ActivityLoggerTest.php index 37b0a3e2..8cb7bf34 100644 --- a/tests/ActivityLoggerTest.php +++ b/tests/ActivityLoggerTest.php @@ -206,11 +206,7 @@ public function it_can_log_activity_using_an_anonymous_causer() $this->assertNull($this->getLastActivity()->causer_type); } - /** - * @test - * - * @requires !Travis - */ + /** @test */ public function it_will_override_the_logged_in_user_as_the_causer_when_an_anonymous_causer_is_specified() { $userId = 1;