Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
40 / 40 |
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\DetailBookResponse; |
| 13 | use AppDemo\Library\Presentation\DetailBookHtmlPresenter; |
| 14 | use AppDemo\Library\Presentation\DetailBookHtmlViewModel; |
| 15 | use Tests\Phexium\Fake\Presentation\PresentationContext as FakePresentationContext; |
| 16 | |
| 17 | describe('Presentation', function (): void { |
| 18 | it('maps all properties to view model', function (): void { |
| 19 | $response = new DetailBookResponse( |
| 20 | id: 42, |
| 21 | title: 'Clean Code', |
| 22 | author: 'Robert C. Martin', |
| 23 | isbn: '9780134494166', |
| 24 | status: 'available' |
| 25 | ); |
| 26 | |
| 27 | $viewModel = new DetailBookHtmlPresenter()->present($response)->getViewModel(); |
| 28 | |
| 29 | expect($viewModel)->toBeInstanceOf(DetailBookHtmlViewModel::class) |
| 30 | ->and($viewModel->id)->toBe(42) |
| 31 | ->and($viewModel->title)->toBe('Clean Code') |
| 32 | ->and($viewModel->author)->toBe('Robert C. Martin') |
| 33 | ->and($viewModel->isbn)->toBe('9780134494166') |
| 34 | ->and($viewModel->status)->toBe('available') |
| 35 | ->and($viewModel->can_update_book)->toBeFalse() |
| 36 | ; |
| 37 | }); |
| 38 | }); |
| 39 | |
| 40 | describe('Permissions', function (): void { |
| 41 | it('grants update permission when context allows', function (): void { |
| 42 | $context = new FakePresentationContext(); |
| 43 | $context->addPermission('book.update'); |
| 44 | $response = new DetailBookResponse( |
| 45 | id: 1, |
| 46 | title: 'Title', |
| 47 | author: 'Author', |
| 48 | isbn: '9780134494166', |
| 49 | status: 'available' |
| 50 | ); |
| 51 | |
| 52 | $viewModel = new DetailBookHtmlPresenter() |
| 53 | ->withContext($context) |
| 54 | ->present($response) |
| 55 | ->getViewModel() |
| 56 | ; |
| 57 | |
| 58 | expect($viewModel->can_update_book)->toBeTrue(); |
| 59 | }); |
| 60 | }); |