Skip to content

Commit

Permalink
Add FakeSessionRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
danon committed Oct 7, 2024
1 parent 262d3df commit 2d8b676
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/Domain/Online/FakeSessionRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace Coyote\Domain\Online;

use Coyote\User;
use Illuminate\Database\Eloquent;

/**
* For development purposes only.
*/
readonly class FakeSessionRepository extends SessionRepository
{
public function sessionsIn(string $prefixPath): SessionsSnapshot
{
if ($prefixPath === '/') {
return new SessionsSnapshot(
users:$this->id(User::query()->inRandomOrder(rand(1, 100))),
guestsCount:\rand(450, 900),
);
}
return new SessionsSnapshot(
users:[
...$this->id(User::query()->whereNotNull('group_name')->limit(1)),
...$this->id(User::query()->inRandomOrder()->limit(\rand(5, 7))),
],
guestsCount:\rand(5, 90),
);
}

private function id(Eloquent\Builder $builder): array
{
return $builder->pluck('id')->toArray();
}
}

0 comments on commit 2d8b676

Please sign in to comment.