From 2ca6f9a7039755ad086c6f661f883edade05a45e Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Thu, 10 Nov 2022 13:06:09 -0500 Subject: [PATCH 1/4] Add test for nullable property --- tests/ActivityLoggerTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/ActivityLoggerTest.php b/tests/ActivityLoggerTest.php index b38e607b..661336ed 100644 --- a/tests/ActivityLoggerTest.php +++ b/tests/ActivityLoggerTest.php @@ -148,6 +148,21 @@ expect($firstActivity->getExtraProperty('property.subProperty'))->toEqual('value'); }); +it('can log activity with null properties', function () { + $properties = [ + 'property' => null + ]; + + activity() + ->withProperties($properties) + ->log($this->activityDescription); + + $firstActivity = Activity::first(); + + expect($firstActivity->properties)->toBeInstanceOf(Collection::class); + expect($firstActivity->getExtraProperty('property'))->toBeNull(); +}); + it('can log activity with a single properties', function () { activity() ->withProperty('key', 'value') From 7b1aed85ac77ec86ddc529975e58db5fc2e9d648 Mon Sep 17 00:00:00 2001 From: stevebauman Date: Thu, 10 Nov 2022 18:06:37 +0000 Subject: [PATCH 2/4] Fix styling --- tests/ActivityLoggerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ActivityLoggerTest.php b/tests/ActivityLoggerTest.php index 661336ed..e8aa426c 100644 --- a/tests/ActivityLoggerTest.php +++ b/tests/ActivityLoggerTest.php @@ -150,7 +150,7 @@ it('can log activity with null properties', function () { $properties = [ - 'property' => null + 'property' => null, ]; activity() From 8a8584c5509c418507e29167041301293e1aa202 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Thu, 10 Nov 2022 13:09:12 -0500 Subject: [PATCH 3/4] Cast enum namespace to string to ensure proper type is given to `enum_exists()` --- src/Actions/ResolveForPropertyValueAction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Actions/ResolveForPropertyValueAction.php b/src/Actions/ResolveForPropertyValueAction.php index c4cc91c9..c4c436f5 100644 --- a/src/Actions/ResolveForPropertyValueAction.php +++ b/src/Actions/ResolveForPropertyValueAction.php @@ -34,6 +34,6 @@ protected function isValueAnEnum($value): bool $enumNamespace = is_object($value) ? get_class($value) : $value; - return ! is_array($value) && enum_exists($enumNamespace); + return ! is_array($value) && enum_exists((string) $enumNamespace); } } From 5642f393185af1530f8f2d7a72f1609dc20d34dc Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 11 Nov 2022 09:56:29 -0500 Subject: [PATCH 4/4] Update src/Actions/ResolveForPropertyValueAction.php Co-authored-by: Tom Witkowski --- src/Actions/ResolveForPropertyValueAction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Actions/ResolveForPropertyValueAction.php b/src/Actions/ResolveForPropertyValueAction.php index c4c436f5..836e0a9b 100644 --- a/src/Actions/ResolveForPropertyValueAction.php +++ b/src/Actions/ResolveForPropertyValueAction.php @@ -34,6 +34,6 @@ protected function isValueAnEnum($value): bool $enumNamespace = is_object($value) ? get_class($value) : $value; - return ! is_array($value) && enum_exists((string) $enumNamespace); + return ! is_array($value) && is_string($enumNamespace) && enum_exists($enumNamespace); } }