Passed
Push — master ( 7f5f0e...4369d4 )
by Adrien
05:49
created

BookableTest::testCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 16
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\DBAL\Types\BookingStatusType;
8
use Application\Model\Bookable;
9
use Application\Model\Booking;
10
use Cake\Chronos\Chronos;
11
use PHPUnit\Framework\TestCase;
12
13
class BookableTest extends TestCase
14
{
15
    public function testCode(): void
16
    {
17
        $bookable = new Bookable();
18
        self::assertNull($bookable->getCode());
19
20
        $bookable->setCode('foo');
21
        self::assertSame('foo', $bookable->getCode());
22
23
        $bookable->setCode('');
24
        self::assertNull($bookable->getCode());
25
26
        $bookable->setCode('foo');
27
        self::assertSame('foo', $bookable->getCode());
28
29
        $bookable->setCode(null);
30
        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...
31
    }
32
33
    public function testSimultaneousBookings(): void
34
    {
35
        $bookable = new Bookable();
36
        self::assertSame([], $bookable->getSimultaneousBookings());
37
38
        $booking1 = new Booking();
39
        $booking1->setStatus(BookingStatusType::BOOKED);
40
        $booking1->setBookable($bookable);
41
42
        self::assertCount(1, $bookable->getSimultaneousBookings());
43
44
        $bookable->setSimultaneousBookingMaximum(-1);
45
        self::assertSame([], $bookable->getSimultaneousBookings(), 'empty list because we try to save SQL queries');
46
47
        $bookable->setSimultaneousBookingMaximum(0);
48
        self::assertCount(1, $bookable->getSimultaneousBookings(), 'again normal list when there is a chance that simultaneous booking matter');
49
50
        $booking2 = new Booking();
51
        $booking2->setStatus(BookingStatusType::BOOKED);
52
        $booking2->setBookable($bookable);
53
54
        self::assertCount(2, $bookable->getSimultaneousBookings(), 'second bookings should be returned');
55
56
        $booking1->setEndDate(Chronos::now());
57
        self::assertCount(1, $bookable->getSimultaneousBookings(), 'terminated booking should be excluded');
58
59
        $booking2->setEndDate(Chronos::now());
60
        self::assertSame([], $bookable->getSimultaneousBookings(), 'nothing shared anymore');
61
    }
62
}
63