1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApplicationTest\Model; |
6
|
|
|
|
7
|
|
|
use Application\Model\User; |
8
|
|
|
use Application\Model\UserTag; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
class UserTagTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testUserRelation(): void |
14
|
|
|
{ |
15
|
|
|
$userTag = new UserTag(); |
16
|
|
|
self::assertCount(0, $userTag->getUsers(), 'userTag should have no users'); |
17
|
|
|
|
18
|
|
|
$user = new User(); |
19
|
|
|
self::assertCount(0, $user->getUserTags(), 'user should have no userTags'); |
20
|
|
|
|
21
|
|
|
$userTag->addUser($user); |
22
|
|
|
self::assertCount(1, $user->getUserTags(), 'user should have the added userTag'); |
23
|
|
|
self::assertSame($userTag, $user->getUserTags()->first(), 'user should have the same userTag'); |
24
|
|
|
self::assertCount(1, $userTag->getUsers(), 'userTag should have the added user'); |
25
|
|
|
self::assertSame($user, $userTag->getUsers()->first(), 'userTag should be able to retrieve added user'); |
26
|
|
|
|
27
|
|
|
$userTag->addUser($user); |
28
|
|
|
self::assertCount(1, $user->getUserTags(), 'user should still have exactly 1 userTag'); |
29
|
|
|
self::assertCount(1, $userTag->getUsers(), 'userTag should still have the same unique user'); |
30
|
|
|
|
31
|
|
|
$user2 = new User(); |
32
|
|
|
$userTag->addUser($user2); |
33
|
|
|
self::assertCount(2, $userTag->getUsers(), 'should be able to add second user'); |
34
|
|
|
|
35
|
|
|
$userTag->removeUser($user); |
36
|
|
|
self::assertCount(0, $user->getUserTags(), 'user should not have any userTag anymore'); |
37
|
|
|
self::assertCount(1, $userTag->getUsers(), 'userTag should be able to remove first user'); |
38
|
|
|
self::assertSame($user2, $userTag->getUsers()->first(), 'userTag should have only the second user left'); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|