1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApplicationTest\Model; |
6
|
|
|
|
7
|
|
|
use Application\Model\Bookable; |
8
|
|
|
use Application\Model\Booking; |
9
|
|
|
use Application\Model\User; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
class BookingTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public function testResponsibleRelation(): void |
15
|
|
|
{ |
16
|
|
|
$booking = new Booking(); |
17
|
|
|
self::assertNull($booking->getResponsible(), 'booking should have no responsible'); |
18
|
|
|
|
19
|
|
|
$user = new User(); |
20
|
|
|
self::assertCount(0, $user->getBookings(), 'user should have no bookings'); |
21
|
|
|
|
22
|
|
|
$booking->setResponsible($user); |
23
|
|
|
self::assertCount(1, $user->getBookings(), 'user should have the added booking'); |
24
|
|
|
self::assertSame($booking, $user->getBookings()->first(), 'user should have the same booking'); |
25
|
|
|
self::assertSame($user, $booking->getResponsible(), 'booking should have responsible'); |
26
|
|
|
|
27
|
|
|
$booking->setResponsible(null); |
28
|
|
|
self::assertNull($booking->getResponsible(), 'booking should have no responsible anymore'); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testBookableRelation(): void |
32
|
|
|
{ |
33
|
|
|
$booking = new Booking(); |
34
|
|
|
self::assertCount(0, $booking->getBookables(), 'booking should have no bookables'); |
35
|
|
|
|
36
|
|
|
$bookable = new Bookable(); |
37
|
|
|
self::assertCount(0, $bookable->getBookings(), 'bookable should have no bookings'); |
38
|
|
|
|
39
|
|
|
$booking->addBookable($bookable); |
40
|
|
|
self::assertCount(1, $bookable->getBookings(), 'bookable should have the added booking'); |
41
|
|
|
self::assertSame($booking, $bookable->getBookings()->first(), 'bookable should have the same booking'); |
42
|
|
|
self::assertCount(1, $booking->getBookables(), 'booking should have the added bookable'); |
43
|
|
|
self::assertSame($bookable, $booking->getBookables()->first(), 'booking should be able to retrieve added bookable'); |
44
|
|
|
|
45
|
|
|
$booking->addBookable($bookable); |
46
|
|
|
self::assertCount(1, $bookable->getBookings(), 'bookable should still have exactly 1 booking'); |
47
|
|
|
self::assertCount(1, $booking->getBookables(), 'booking should still have the same unique bookable'); |
48
|
|
|
|
49
|
|
|
$bookable2 = new Bookable(); |
50
|
|
|
$booking->addBookable($bookable2); |
51
|
|
|
self::assertCount(2, $booking->getBookables(), 'should be able to add second bookable'); |
52
|
|
|
|
53
|
|
|
$booking->removeBookable($bookable); |
54
|
|
|
self::assertCount(0, $bookable->getBookings(), 'bookable should not have any booking anymore'); |
55
|
|
|
self::assertCount(1, $booking->getBookables(), 'booking should be able to remove first bookable'); |
56
|
|
|
self::assertSame($bookable2, $booking->getBookables()->first(), 'booking should have only the second bookable left'); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
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.