Completed
Push — master ( 1cdf46...d8c9d1 )
by Adrien
07:48
created

BookableTest::testGetSharedBookings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 0
dl 0
loc 29
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Model;
6
7
use Application\DBAL\Types\BookingTypeType;
8
use Application\Model\Bookable;
9
use Application\Model\BookableTag;
10
use Application\Model\Booking;
11
use Application\Repository\BookableTagRepository;
12
use Cake\Chronos\Chronos;
13
use PHPUnit\Framework\TestCase;
14
15
class BookableTest extends TestCase
16
{
17
    public function testCode(): void
18
    {
19
        $bookable = new Bookable();
20
        self::assertNull($bookable->getCode());
21
22
        $bookable->setCode('foo');
23
        self::assertSame('foo', $bookable->getCode());
24
25
        $bookable->setCode('');
26
        self::assertNull($bookable->getCode());
27
28
        $bookable->setCode('foo');
29
        self::assertSame('foo', $bookable->getCode());
30
31
        $bookable->setCode(null);
32
        self::assertNull($bookable->getCode());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $bookable->getCode() targeting Application\Model\Bookable::getCode() 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...
33
    }
34
35
    public function testGetSharedBookings(): void
36
    {
37
        $bookable = new Bookable();
38
        self::assertSame([], $bookable->getSharedBookings());
39
40
        $booking1 = new Booking();
41
        $booking1->setBookable($bookable);
42
43
        self::assertSame([], $bookable->getSharedBookings());
44
45
        $bookable->setBookingType(BookingTypeType::ADMIN_ONLY);
46
        self::assertSame([], $bookable->getSharedBookings(), 'admin_only is not enough to share');
47
48
        /** @var BookableTag $tag */
49
        $tag = _em()->getReference(BookableTag::class, BookableTagRepository::STORAGE_ID);
50
        $tag->addBookable($bookable);
51
52
        self::assertCount(1, $bookable->getSharedBookings(), 'admin_only and storage tag should show 1 booking');
53
54
        $booking2 = new Booking();
55
        $booking2->setBookable($bookable);
56
57
        self::assertCount(2, $bookable->getSharedBookings(), 'second bookings should be returned');
58
59
        $booking1->setEndDate(Chronos::now());
60
        self::assertCount(1, $bookable->getSharedBookings(), 'terminated booking should be excluded');
61
62
        $booking2->setEndDate(Chronos::now());
63
        self::assertSame([], $bookable->getSharedBookings(), 'nothing shared anymore');
64
    }
65
}
66