Skip to content

Resolve #1579 #1580

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

Closed
Closed
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
6 changes: 5 additions & 1 deletion src/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class Avatar
*/
public static function url(array $user)
{
if (empty($user['id'])) {
return;
}

if (isset(static::$callback)) {
return static::resolve($user);
}
Expand Down Expand Up @@ -52,7 +56,7 @@ public static function register(Closure $callback)
protected static function resolve($user)
{
if (static::$callback !== null) {
return call_user_func(static::$callback, $user['id'] ?? null, $user['email'] ?? null);
return call_user_func(static::$callback, $user['id'], $user['email'] ?? null);
}
}
}
41 changes: 41 additions & 0 deletions tests/Http/AvatarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,47 @@ public function it_can_read_custom_avatar_path_on_null_email()
],
]);
}

/**
* @test
*/
public function it_should_not_call_the_custom_avatar_when_no_user_was_authenticated_during_the_error()
{
$user = null;

Telescope::withoutRecording(function () use (&$user) {
$this->loadLaravelMigrations();

$user = UserEloquent::create([
'id' => 1,
'name' => 'Telescope',
'email' => '[email protected]',
'password' => 'secret',
]);
});

Telescope::avatar(function (string $id, ?string $email) {
return UserEloquent::find($id)->email;
});

$this->app->get(LoggerInterface::class)->error('Avatar path will be generated.', [
'exception' => 'Some error message',
]);

$entry = $this->loadTelescopeEntries()->first();

$this->actingAs($user);

$this->get("/telescope/telescope-api/logs/{$entry->uuid}")
->assertOk()
->assertJsonMissing([
'entry' => [
'content' => [
'user',
],
],
]);
}
}

class UserEloquent extends Model implements Authenticatable
Expand Down