1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApplicationTest\Model; |
6
|
|
|
|
7
|
|
|
use Application\Enum\BookingStatus; |
8
|
|
|
use Application\Enum\BookingType; |
9
|
|
|
use Application\Model\Bookable; |
10
|
|
|
use Application\Model\Booking; |
11
|
|
|
use Cake\Chronos\Chronos; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
class BookableTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
public function testCode(): void |
17
|
|
|
{ |
18
|
|
|
$bookable = new Bookable(); |
19
|
|
|
self::assertNull($bookable->getCode()); |
20
|
|
|
|
21
|
|
|
$bookable->setCode('foo'); |
22
|
|
|
self::assertSame('foo', $bookable->getCode()); |
23
|
|
|
|
24
|
|
|
$bookable->setCode(''); |
25
|
|
|
self::assertNull($bookable->getCode()); |
26
|
|
|
|
27
|
|
|
$bookable->setCode('foo'); |
28
|
|
|
self::assertSame('foo', $bookable->getCode()); |
29
|
|
|
|
30
|
|
|
$bookable->setCode(null); |
31
|
|
|
self::assertNull($bookable->getCode()); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testGetSimultaneousBookings(): void |
35
|
|
|
{ |
36
|
|
|
$bookable = new Bookable(); |
37
|
|
|
self::assertCount(0, $bookable->getSimultaneousBookings()); |
38
|
|
|
self::assertCount(0, $bookable->getSimultaneousApplications()); |
39
|
|
|
|
40
|
|
|
$booking1 = new Booking(); |
41
|
|
|
$booking1->setStatus(BookingStatus::Booked); |
42
|
|
|
$booking1->setBookable($bookable); |
43
|
|
|
|
44
|
|
|
self::assertCount(1, $bookable->getSimultaneousBookings()); |
45
|
|
|
self::assertCount(0, $bookable->getSimultaneousApplications()); |
46
|
|
|
|
47
|
|
|
$bookable->setBookingType(BookingType::SelfApproved); |
48
|
|
|
self::assertCount(0, $bookable->getSimultaneousBookings(), 'empty list because we try to save SQL queries'); |
49
|
|
|
self::assertCount(0, $bookable->getSimultaneousApplications()); |
50
|
|
|
|
51
|
|
|
$bookable->setBookingType(BookingType::Mandatory); |
52
|
|
|
self::assertCount(0, $bookable->getSimultaneousBookings(), 'empty list because we try to save SQL queries'); |
53
|
|
|
self::assertCount(0, $bookable->getSimultaneousApplications()); |
54
|
|
|
|
55
|
|
|
$bookable->setBookingType(BookingType::AdminApproved); |
56
|
|
|
self::assertCount(1, $bookable->getSimultaneousBookings(), 'again normal list when there is a chance that simultaneous booking matter'); |
57
|
|
|
self::assertCount(0, $bookable->getSimultaneousApplications()); |
58
|
|
|
|
59
|
|
|
$bookable->setBookingType(BookingType::AdminAssigned); |
60
|
|
|
self::assertCount(1, $bookable->getSimultaneousBookings(), 'again normal list when there is a chance that simultaneous booking matter'); |
61
|
|
|
self::assertCount(0, $bookable->getSimultaneousApplications()); |
62
|
|
|
|
63
|
|
|
$booking2 = new Booking(); |
64
|
|
|
$booking2->setStatus(BookingStatus::Booked); |
65
|
|
|
$booking2->setBookable($bookable); |
66
|
|
|
|
67
|
|
|
self::assertCount(2, $bookable->getSimultaneousBookings(), 'second bookings should be returned'); |
68
|
|
|
self::assertCount(0, $bookable->getSimultaneousApplications()); |
69
|
|
|
|
70
|
|
|
$booking1->setEndDate(Chronos::now()); |
71
|
|
|
self::assertCount(1, $bookable->getSimultaneousBookings(), 'terminated booking should be excluded'); |
72
|
|
|
self::assertCount(0, $bookable->getSimultaneousApplications()); |
73
|
|
|
|
74
|
|
|
$booking2->setStatus(BookingStatus::Application); |
75
|
|
|
self::assertCount(0, $bookable->getSimultaneousBookings(), 'nothing shared anymore because applications are excluded'); |
76
|
|
|
self::assertCount(1, $bookable->getSimultaneousApplications()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testGetSimultaneousApplications(): void |
80
|
|
|
{ |
81
|
|
|
$bookable = new Bookable(); |
82
|
|
|
self::assertCount(0, $bookable->getSimultaneousApplications()); |
83
|
|
|
self::assertCount(0, $bookable->getSimultaneousBookings()); |
84
|
|
|
|
85
|
|
|
$booking1 = new Booking(); |
86
|
|
|
$booking1->setBookable($bookable); |
87
|
|
|
|
88
|
|
|
self::assertCount(1, $bookable->getSimultaneousApplications()); |
89
|
|
|
self::assertCount(0, $bookable->getSimultaneousBookings()); |
90
|
|
|
|
91
|
|
|
$bookable->setBookingType(BookingType::SelfApproved); |
92
|
|
|
self::assertCount(0, $bookable->getSimultaneousApplications(), 'empty list because we try to save SQL queries'); |
93
|
|
|
self::assertCount(0, $bookable->getSimultaneousBookings()); |
94
|
|
|
|
95
|
|
|
$bookable->setBookingType(BookingType::AdminApproved); |
96
|
|
|
self::assertCount(1, $bookable->getSimultaneousApplications(), 'again normal list when there is a chance that simultaneous booking matter'); |
97
|
|
|
self::assertCount(0, $bookable->getSimultaneousBookings()); |
98
|
|
|
|
99
|
|
|
$booking2 = new Booking(); |
100
|
|
|
$booking2->setBookable($bookable); |
101
|
|
|
|
102
|
|
|
self::assertCount(2, $bookable->getSimultaneousApplications(), 'second bookings should be returned'); |
103
|
|
|
self::assertCount(0, $bookable->getSimultaneousBookings()); |
104
|
|
|
|
105
|
|
|
$booking1->setEndDate(Chronos::now()); |
106
|
|
|
self::assertCount(1, $bookable->getSimultaneousApplications(), 'terminated booking should be excluded'); |
107
|
|
|
self::assertCount(0, $bookable->getSimultaneousBookings()); |
108
|
|
|
|
109
|
|
|
$booking2->setStatus(BookingStatus::Processed); |
110
|
|
|
self::assertCount(0, $bookable->getSimultaneousApplications(), 'nothing shared anymore because non-applications are excluded'); |
111
|
|
|
self::assertCount(1, $bookable->getSimultaneousBookings()); |
112
|
|
|
|
113
|
|
|
$booking2->setStatus(BookingStatus::Booked); |
114
|
|
|
self::assertCount(0, $bookable->getSimultaneousApplications(), 'nothing shared anymore because non-applications are excluded'); |
115
|
|
|
self::assertCount(1, $bookable->getSimultaneousBookings()); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
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.