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()); |
|
|
|
|
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
|
|
|
|
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.