Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
31 / 31
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3// ╔════════════════════════════════════════════════════════════╗
4// ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║
5// ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com>     ║
6// ╚════════════════════════════════════════════════════════════╝
7
8declare(strict_types=1);
9
10use AppDemo\Library\Domain\Author;
11use AppDemo\Library\Domain\Book;
12use AppDemo\Library\Domain\BookStatus;
13use AppDemo\Library\Domain\ISBN;
14use AppDemo\Library\Domain\Title;
15use Phexium\Domain\Id\TimestampId;
16use Tests\AppDemo\Fixture\BookMother;
17
18test('By default, the status of a new book is available', function (): void {
19    $book = new Book(
20        new TimestampId(123),
21        Title::fromString('BookTitle'),
22        Author::fromString('BookAuthor'),
23        ISBN::fromString('9780134494166'),
24    );
25
26    expect($book->getStatus())->toBe(BookStatus::Available);
27});
28
29test('An available book can be marked as borrowed', function (): void {
30    $book = BookMother::available(123);
31
32    expect($book->getStatus())->toBe(BookStatus::Available);
33
34    $book->markAsBorrowed();
35
36    expect($book->getStatus())->toBe(BookStatus::Borrowed);
37});
38
39test('A borrowed book can be marked as available', function (): void {
40    $book = BookMother::borrowed(123);
41
42    expect($book->getStatus())->toBe(BookStatus::Borrowed);
43
44    $book->markAsAvailable();
45
46    expect($book->getStatus())->toBe(BookStatus::Available);
47});
48
49test('Two books with the same ID are equal', function (): void {
50    $book1 = BookMother::available(123);
51    $book2 = BookMother::available(123);
52
53    expect($book1->equals($book2))->toBeTrue();
54});
55
56test('Two books with different IDs are not equal', function (): void {
57    $book1 = BookMother::available(123);
58    $book2 = BookMother::available(234);
59
60    expect($book1->equals($book2))->toBeFalse();
61});