|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ApplicationTest\Model; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Model\Bookable; |
|
8
|
|
|
use Application\Model\License; |
|
9
|
|
|
use Application\Model\User; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
|
|
12
|
|
|
class LicenseTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testUserRelation(): void |
|
15
|
|
|
{ |
|
16
|
|
|
$license = new License(); |
|
17
|
|
|
self::assertCount(0, $license->getUsers(), 'license should have no users'); |
|
18
|
|
|
|
|
19
|
|
|
$user = new User(); |
|
20
|
|
|
self::assertCount(0, $user->getLicenses(), 'user should have no licenses'); |
|
21
|
|
|
|
|
22
|
|
|
$license->addUser($user); |
|
23
|
|
|
self::assertCount(1, $user->getLicenses(), 'user should have the added license'); |
|
24
|
|
|
self::assertSame($license, $user->getLicenses()->first(), 'user should have the same license'); |
|
25
|
|
|
self::assertCount(1, $license->getUsers(), 'license should have the added user'); |
|
26
|
|
|
self::assertSame($user, $license->getUsers()->first(), 'license should be able to retrieve added user'); |
|
27
|
|
|
|
|
28
|
|
|
$license->addUser($user); |
|
29
|
|
|
self::assertCount(1, $user->getLicenses(), 'user should still have exactly 1 license'); |
|
30
|
|
|
self::assertCount(1, $license->getUsers(), 'license should still have the same unique user'); |
|
31
|
|
|
|
|
32
|
|
|
$user2 = new User(); |
|
33
|
|
|
$license->addUser($user2); |
|
34
|
|
|
self::assertCount(2, $license->getUsers(), 'should be able to add second user'); |
|
35
|
|
|
|
|
36
|
|
|
$license->removeUser($user); |
|
37
|
|
|
self::assertCount(0, $user->getLicenses(), 'user should not have any license anymore'); |
|
38
|
|
|
self::assertCount(1, $license->getUsers(), 'license should be able to remove first user'); |
|
39
|
|
|
self::assertSame($user2, $license->getUsers()->first(), 'license should have only the second user left'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testBookableRelation(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$license = new License(); |
|
45
|
|
|
self::assertCount(0, $license->getBookables(), 'license should have no bookables'); |
|
46
|
|
|
|
|
47
|
|
|
$bookable = new Bookable(); |
|
48
|
|
|
self::assertCount(0, $bookable->getLicenses(), 'bookable should have no licenses'); |
|
49
|
|
|
|
|
50
|
|
|
$license->addBookable($bookable); |
|
51
|
|
|
self::assertCount(1, $bookable->getLicenses(), 'bookable should have the added license'); |
|
52
|
|
|
self::assertSame($license, $bookable->getLicenses()->first(), 'bookable should have the same license'); |
|
53
|
|
|
self::assertCount(1, $license->getBookables(), 'license should have the added bookable'); |
|
54
|
|
|
self::assertSame($bookable, $license->getBookables()->first(), 'license should be able to retrieve added bookable'); |
|
55
|
|
|
|
|
56
|
|
|
$license->addBookable($bookable); |
|
57
|
|
|
self::assertCount(1, $bookable->getLicenses(), 'bookable should still have exactly 1 license'); |
|
58
|
|
|
self::assertCount(1, $license->getBookables(), 'license should still have the same unique bookable'); |
|
59
|
|
|
|
|
60
|
|
|
$bookable2 = new Bookable(); |
|
61
|
|
|
$license->addBookable($bookable2); |
|
62
|
|
|
self::assertCount(2, $license->getBookables(), 'should be able to add second bookable'); |
|
63
|
|
|
|
|
64
|
|
|
$license->removeBookable($bookable); |
|
65
|
|
|
self::assertCount(0, $bookable->getLicenses(), 'bookable should not have any license anymore'); |
|
66
|
|
|
self::assertCount(1, $license->getBookables(), 'license should be able to remove first bookable'); |
|
67
|
|
|
self::assertSame($bookable2, $license->getBookables()->first(), 'license should have only the second bookable left'); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|