Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
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
10pest()->group('unit');
11
12use AppDemo\Loan\Application\Query\ListLoansResponse;
13use AppDemo\Loan\Presentation\ListLoansHtmlPresenter;
14use AppDemo\Loan\Presentation\ListLoansHtmlViewModel;
15use Phexium\Domain\Pagination;
16
17describe('Presentation', function (): void {
18    it('maps response to view model with pagination', function (): void {
19        $loans = [['id' => 1, 'book' => 'Book A'], ['id' => 2, 'book' => 'Book B']];
20        $response = new ListLoansResponse(
21            loans: $loans,
22            pagination: new Pagination(25, 2, 10)
23        );
24
25        $viewModel = new ListLoansHtmlPresenter()->present($response)->getViewModel();
26
27        expect($viewModel)->toBeInstanceOf(ListLoansHtmlViewModel::class)
28            ->and($viewModel->loans)->toBe($loans)
29            ->and($viewModel->count)->toBe(25)
30            ->and($viewModel->page)->toBe(2)
31            ->and($viewModel->totalPages)->toBe(3)
32            ->and($viewModel->has_next_page)->toBeTrue()
33            ->and($viewModel->has_previous_page)->toBeTrue()
34        ;
35    });
36});