Failed Conditions
Push — master ( 4369d4...a5c076 )
by Adrien
15:03
created

BookableTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 62
c 1
b 0
f 0
dl 0
loc 94
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCode() 0 16 1
A testSimultaneousBookings() 0 37 1
A testGetSimultaneousBookings() 0 35 1
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 testGetSimultaneousBookings(): void
34
    {
35
        $bookable = new Bookable();
36
        self::assertCount(0, $bookable->getSimultaneousBookings());
37
        self::assertCount(0, $bookable->getSimultaneousApplications());
38
39
        $booking1 = new Booking();
40
        $booking1->setStatus(BookingStatusType::BOOKED);
41
        $booking1->setBookable($bookable);
42
43
        self::assertCount(1, $bookable->getSimultaneousBookings());
44
        self::assertCount(0, $bookable->getSimultaneousApplications());
45
46
        $bookable->setSimultaneousBookingMaximum(-1);
47
        self::assertCount(0, $bookable->getSimultaneousBookings(), 'empty list because we try to save SQL queries');
48
        self::assertCount(0, $bookable->getSimultaneousApplications());
49
50
        $bookable->setSimultaneousBookingMaximum(0);
51
        self::assertCount(1, $bookable->getSimultaneousBookings(), 'again normal list when there is a chance that simultaneous booking matter');
52
        self::assertCount(0, $bookable->getSimultaneousApplications());
53
54
        $booking2 = new Booking();
55
        $booking2->setStatus(BookingStatusType::BOOKED);
56
        $booking2->setBookable($bookable);
57
58
        self::assertCount(2, $bookable->getSimultaneousBookings(), 'second bookings should be returned');
59
        self::assertCount(0, $bookable->getSimultaneousApplications());
60
61
        $booking1->setEndDate(Chronos::now());
62
        self::assertCount(1, $bookable->getSimultaneousBookings(), 'terminated booking should be excluded');
63
        self::assertCount(0, $bookable->getSimultaneousApplications());
64
65
        $booking2->setStatus(BookingStatusType::APPLICATION);
66
        self::assertCount(0, $bookable->getSimultaneousBookings(), 'nothing shared anymore because applications are excluded');
67
        self::assertCount(1, $bookable->getSimultaneousApplications());
68
    }
69
70
    public function testSimultaneousBookings(): void
71
    {
72
        $bookable = new Bookable();
73
        self::assertCount(0, $bookable->getSimultaneousApplications());
74
        self::assertCount(0, $bookable->getSimultaneousBookings());
75
76
        $booking1 = new Booking();
77
        $booking1->setBookable($bookable);
78
79
        self::assertCount(1, $bookable->getSimultaneousApplications());
80
        self::assertCount(0, $bookable->getSimultaneousBookings());
81
82
        $bookable->setSimultaneousBookingMaximum(-1);
83
        self::assertCount(0, $bookable->getSimultaneousApplications(), 'empty list because we try to save SQL queries');
84
        self::assertCount(0, $bookable->getSimultaneousBookings());
85
86
        $bookable->setSimultaneousBookingMaximum(0);
87
        self::assertCount(1, $bookable->getSimultaneousApplications(), 'again normal list when there is a chance that simultaneous booking matter');
88
        self::assertCount(0, $bookable->getSimultaneousBookings());
89
90
        $booking2 = new Booking();
91
        $booking2->setBookable($bookable);
92
93
        self::assertCount(2, $bookable->getSimultaneousApplications(), 'second bookings should be returned');
94
        self::assertCount(0, $bookable->getSimultaneousBookings());
95
96
        $booking1->setEndDate(Chronos::now());
97
        self::assertCount(1, $bookable->getSimultaneousApplications(), 'terminated booking should be excluded');
98
        self::assertCount(0, $bookable->getSimultaneousBookings());
99
100
        $booking2->setStatus(BookingStatusType::PROCESSED);
101
        self::assertCount(0, $bookable->getSimultaneousApplications(), 'nothing shared anymore because non-applications are excluded');
102
        self::assertCount(1, $bookable->getSimultaneousBookings());
103
104
        $booking2->setStatus(BookingStatusType::BOOKED);
105
        self::assertCount(0, $bookable->getSimultaneousApplications(), 'nothing shared anymore because non-applications are excluded');
106
        self::assertCount(1, $bookable->getSimultaneousBookings());
107
    }
108
}
109