Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nullable log names #1029

Merged
merged 16 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ActivityLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ public function createdAt(DateTimeInterface $dateTime): static
return $this;
}

public function useLog(string $logName): static
public function useLog(?string $logName): static
{
$this->getActivity()->log_name = $logName;

return $this;
}

public function inLog(string $logName): static
public function inLog(?string $logName): static
{
return $this->useLog($logName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/LogOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function submitEmptyLogs(): self
/**
* Customize log name.
*/
public function useLogName(string $logName): self
public function useLogName(?string $logName): self
{
$this->logName = $logName;

Expand Down
2 changes: 1 addition & 1 deletion src/Traits/LogsActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function getDescriptionForEvent(string $eventName): string
return $eventName;
}

public function getLogNameToUse(): string
public function getLogNameToUse(): ?string
{
if (! empty($this->activitylogOptions->logName)) {
return $this->activitylogOptions->logName;
Expand Down
8 changes: 8 additions & 0 deletions tests/ActivityLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
expect($this->getLastActivity())->toBeNull();
});

it('will log activity with a null log name', function () {
config(['activitylog.default_log_name' => null]);

activity()->log($this->activityDescription);

expect($this->getLastActivity()->log_name)->toBeNull();
});

it('will log an activity when enabled option is null', function () {
config(['activitylog.enabled' => null]);

Expand Down