Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
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
8declare(strict_types=1);
9
10pest()->group('unit');
11
12use Tests\Phexium\Fake\Presentation\PresentationContext as FakePresentationContext;
13use Tests\Phexium\Fake\Presentation\Presenter as FakePresenter;
14use Tests\Phexium\Fake\Presentation\QueryResponse as FakeQueryResponse;
15
16describe('Presentation', function (): void {
17    it('presents response and returns self', function (): void {
18        $response = new FakeQueryResponse();
19        $presenter = new FakePresenter();
20
21        $result = $presenter->present($response);
22
23        expect($result)->toBe($presenter);
24    });
25
26    it('returns view model after presentation', function (): void {
27        $response = new FakeQueryResponse();
28        $presenter = new FakePresenter();
29
30        $viewModel = $presenter->present($response)->getViewModel();
31
32        expect($viewModel)->toBeInstanceOf(stdClass::class);
33        expect($viewModel->attribute)->toBe('TestAttribute');
34    });
35});
36
37describe('Context', function (): void {
38    it('injects presentation context with withContext()', function (): void {
39        $context = new FakePresentationContext();
40        $presenter = new FakePresenter();
41
42        $result = $presenter->withContext($context);
43
44        expect($result)->toBe($presenter);
45        expect($presenter->hasContext())->toBeTrue();
46        expect($presenter->getContext())->toBe($context);
47    });
48});