-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Condense multiple online viewers to one row
- Loading branch information
Showing
6 changed files
with
181 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
namespace Tests\Unit\OnlineUsers; | ||
|
||
use Coyote\Domain\Online\Viewers; | ||
use Coyote\Domain\Online\ViewerUser; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ViewersTest extends TestCase | ||
{ | ||
#[Test] | ||
public function totalCount(): void | ||
{ | ||
$viewers = new Viewers($this->usersOfSize(2), 3); | ||
$this->assertSame(5, $viewers->totalCount()); | ||
} | ||
|
||
#[Test] | ||
public function leadingUsers(): void | ||
{ | ||
$viewers = new Viewers([$this->user('Mark')], 0); | ||
[$leading] = $viewers->usersLeading(2); | ||
$this->assertSame('Mark', $leading->name); | ||
} | ||
|
||
#[Test] | ||
public function leadingUsersUpToLimit(): void | ||
{ | ||
$viewers = new Viewers($this->usersOfSize(5), 0); | ||
$this->assertCount(2, $viewers->usersLeading(2)); | ||
} | ||
|
||
#[Test] | ||
public function countSuperfluousUsers(): void | ||
{ | ||
$viewers = new Viewers($this->usersOfSize(5), 0); | ||
$this->assertSame(3, $viewers->usersSuperfluous(2)); | ||
} | ||
|
||
#[Test] | ||
public function withLimitBiggerThanUsers_returnEmptySuperfluous(): void | ||
{ | ||
$viewers = new Viewers($this->usersOfSize(3), 0); | ||
$this->assertSame(0, $viewers->usersSuperfluous(5)); | ||
} | ||
|
||
#[Test] | ||
public function usersWithGroup(): void | ||
{ | ||
$viewers = new Viewers([ | ||
$this->user(name:'Tom'), | ||
$this->user(name:'Mark', group:'Blue'), | ||
], 0); | ||
$users = $viewers->usersWithGroup(); | ||
$this->assertCount(1, $users); | ||
$this->assertSame('Mark', $users[0]->name); | ||
} | ||
|
||
#[Test] | ||
public function leadingUsers_areWithoutGroups(): void | ||
{ | ||
$viewers = new Viewers([ | ||
$this->user(name:'Mark', group:'Blue'), | ||
$this->user(name:'Tom'), | ||
], 0); | ||
$leading = $viewers->usersLeading(2); | ||
$this->assertCount(1, $leading); | ||
$this->assertSame('Tom', $leading[0]->name); | ||
} | ||
|
||
#[Test] | ||
public function superfluousUsers_areWithoutGroups(): void | ||
{ | ||
$viewers = new Viewers([ | ||
$this->user(name:'Mark', group:'Blue'), | ||
$this->user(name:'Mark', group:'Blue'), | ||
$this->user(name:'Tom'), | ||
], 0); | ||
$this->assertSame(1, $viewers->usersSuperfluous(0)); | ||
} | ||
|
||
private function usersOfSize(int $size): array | ||
{ | ||
return \array_fill(0, $size, $this->user()); | ||
} | ||
|
||
private function user(string $name = null, string $group = null): ViewerUser | ||
{ | ||
return new ViewerUser($name ?? '', $group, null); | ||
} | ||
} |