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