Completed
Push — master ( 4f5e08...58c386 )
by Adrien
05:49
created

BookingTest::testBookableRelation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 19
nc 1
nop 0
dl 0
loc 26
rs 9.6333
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 testResponsibleRelation(): void
15
    {
16
        $booking = new Booking();
17
        self::assertNull($booking->getResponsible(), 'booking should have no responsible');
18
19
        $user = new User();
20
        self::assertCount(0, $user->getBookings(), 'user should have no bookings');
21
22
        $booking->setResponsible($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->getResponsible(), 'booking should have responsible');
26
27
        $booking->setResponsible(null);
28
        self::assertNull($booking->getResponsible(), 'booking should have no responsible anymore');
0 ignored issues
show
Bug introduced by
Are you sure the usage of $booking->getResponsible() targeting Application\Model\Booking::getResponsible() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
29
    }
30
31
    public function testBookableRelation(): void
32
    {
33
        $booking = new Booking();
34
        self::assertCount(0, $booking->getBookables(), 'booking should have no bookables');
35
36
        $bookable = new Bookable();
37
        self::assertCount(0, $bookable->getBookings(), 'bookable should have no bookings');
38
39
        $booking->addBookable($bookable);
40
        self::assertCount(1, $bookable->getBookings(), 'bookable should have the added booking');
41
        self::assertSame($booking, $bookable->getBookings()->first(), 'bookable should have the same booking');
42
        self::assertCount(1, $booking->getBookables(), 'booking should have the added bookable');
43
        self::assertSame($bookable, $booking->getBookables()->first(), 'booking should be able to retrieve added bookable');
44
45
        $booking->addBookable($bookable);
46
        self::assertCount(1, $bookable->getBookings(), 'bookable should still have exactly 1 booking');
47
        self::assertCount(1, $booking->getBookables(), 'booking should still have the same unique bookable');
48
49
        $bookable2 = new Bookable();
50
        $booking->addBookable($bookable2);
51
        self::assertCount(2, $booking->getBookables(), 'should be able to add second bookable');
52
53
        $booking->removeBookable($bookable);
54
        self::assertCount(0, $bookable->getBookings(), 'bookable should not have any booking anymore');
55
        self::assertCount(1, $booking->getBookables(), 'booking should be able to remove first bookable');
56
        self::assertSame($bookable2, $booking->getBookables()->first(), 'booking should have only the second bookable left');
57
    }
58
}
59