Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
22 / 22
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\Library\Application\Query\ListBooksResponse;
13use AppDemo\Library\Presentation\ListBooksJsonPresenter;
14use Phexium\Domain\Pagination;
15
16describe('Presentation', function (): void {
17    it('maps response to array with books and pagination', function (): void {
18        $books = [['id' => 1, 'title' => 'Book A']];
19        $response = new ListBooksResponse(
20            books: $books,
21            pagination: new Pagination(25, 2, 10)
22        );
23
24        $viewModel = new ListBooksJsonPresenter()->present($response)->getViewModel();
25
26        expect($viewModel)->toBeArray()
27            ->and($viewModel['books'])->toBe($books)
28            ->and($viewModel['pagination'])->toBe([
29                'total_count' => 25,
30                'page' => 2,
31                'per_page' => 10,
32                'total_pages' => 3,
33                'has_next_page' => true,
34                'has_previous_page' => true,
35            ])
36        ;
37    });
38});