Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
26 / 26 |
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 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | pest()->group('unit'); |
| 11 | |
| 12 | use AppDemo\Library\Application\Query\UpdateBookResponse; |
| 13 | use AppDemo\Library\Presentation\UpdateBookHtmlPresenter; |
| 14 | use AppDemo\Library\Presentation\UpdateBookHtmlViewModel; |
| 15 | |
| 16 | describe('Presentation', function (): void { |
| 17 | it('builds book object and passes through form values and errors', function (): void { |
| 18 | $formValues = ['title' => 'Updated Title']; |
| 19 | $errors = ['author' => 'Author is required']; |
| 20 | $response = new UpdateBookResponse( |
| 21 | bookId: 42, |
| 22 | bookTitle: 'Clean Code', |
| 23 | bookAuthor: 'Robert C. Martin', |
| 24 | bookIsbn: '9780134494166', |
| 25 | bookStatus: 'available', |
| 26 | formValues: $formValues, |
| 27 | errors: $errors |
| 28 | ); |
| 29 | |
| 30 | $viewModel = new UpdateBookHtmlPresenter()->present($response)->getViewModel(); |
| 31 | |
| 32 | expect($viewModel)->toBeInstanceOf(UpdateBookHtmlViewModel::class) |
| 33 | ->and($viewModel->book->id)->toBe(42) |
| 34 | ->and($viewModel->book->title)->toBe('Clean Code') |
| 35 | ->and($viewModel->book->author)->toBe('Robert C. Martin') |
| 36 | ->and($viewModel->book->isbn)->toBe('9780134494166') |
| 37 | ->and($viewModel->book->status)->toBe('available') |
| 38 | ->and($viewModel->formValues)->toBe($formValues) |
| 39 | ->and($viewModel->errors)->toBe($errors) |
| 40 | ; |
| 41 | }); |
| 42 | }); |