Failed Conditions
Push — master ( 7ddf51...0a0c4a )
by Adrien
06:37
created

BookingTest::testResponsibleRelation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 15
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Model;
6
7
use Application\Model\Bookable;
8
use Application\Model\Booking;
9
use Application\Model\User;
10
use PHPUnit\Framework\TestCase;
11
12
class BookingTest extends TestCase
13
{
14
    public function testOwnerRelation(): void
15
    {
16
        $booking = new Booking();
17
        self::assertNull($booking->getOwner(), 'booking should have no owner');
18
19
        $user = new User();
20
        self::assertCount(0, $user->getBookings(), 'user should have no bookings');
21
22
        $booking->setOwner($user);
23
        self::assertCount(1, $user->getBookings(), 'user should have the added booking');
24
        self::assertSame($booking, $user->getBookings()->first(), 'user should have the same booking');
25
        self::assertSame($user, $booking->getOwner(), 'booking should have owner');
26
    }
27
28
    public function testBookableRelation(): void
29
    {
30
        $booking = new Booking();
31
        self::assertCount(0, $booking->getBookables(), 'booking should have no bookables');
32
33
        $bookable = new Bookable();
34
        self::assertCount(0, $bookable->getBookings(), 'bookable should have no bookings');
35
36
        $booking->addBookable($bookable);
37
        self::assertCount(1, $bookable->getBookings(), 'bookable should have the added booking');
38
        self::assertSame($booking, $bookable->getBookings()->first(), 'bookable should have the same booking');
39
        self::assertCount(1, $booking->getBookables(), 'booking should have the added bookable');
40
        self::assertSame($bookable, $booking->getBookables()->first(), 'booking should be able to retrieve added bookable');
41
42
        $booking->addBookable($bookable);
43
        self::assertCount(1, $bookable->getBookings(), 'bookable should still have exactly 1 booking');
44
        self::assertCount(1, $booking->getBookables(), 'booking should still have the same unique bookable');
45
46
        $bookable2 = new Bookable();
47
        $booking->addBookable($bookable2);
48
        self::assertCount(2, $booking->getBookables(), 'should be able to add second bookable');
49
50
        $booking->removeBookable($bookable);
51
        self::assertCount(0, $bookable->getBookings(), 'bookable should not have any booking anymore');
52
        self::assertCount(1, $booking->getBookables(), 'booking should be able to remove first bookable');
53
        self::assertSame($bookable2, $booking->getBookables()->first(), 'booking should have only the second bookable left');
54
    }
55
}
56