PresenterTest.php 1.63 KB
Newer Older
Jacob Priddy's avatar
Jacob Priddy committed
1
2
3
<?php


Jacob Priddy's avatar
Jacob Priddy committed
4
namespace Unit\Source\UseCases\Users\GetUser;
Jacob Priddy's avatar
Jacob Priddy committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70


use Carbon\Carbon;
use Source\Entities\User;
use PHPUnit\Framework\TestCase;
use Source\UseCases\Users\GetUser\APIPresenter;
use Source\UseCases\Users\GetUser\ResponseModel;

class PresenterTest extends TestCase {

    protected APIPresenter $presenter;

    protected ResponseModel $model;

    protected array $response;

    public function setUp(): void {
        parent::setUp();

        $this->presenter = new APIPresenter();
    }

    public function handleTest(User $user): void {
        $this->model = new ResponseModel($user);

        $this->presenter->present($this->model);

        $this->response = $this->presenter->getViewModel();
    }

    /** @test */
    public function it_formats_a_user(): void {
        $user = new User(
            0,
            'first',
            'last',
            'display',
            'emplid',
            'email',
            'password',
            'doorcode',
            new Carbon('2020-02-02'),
            null,
            null
        );

        $this->handleTest($user);

        $this->assertEquals(
            [
                'user' => [
                    'id'           => 0,
                    'first_name'   => 'first',
                    'last_name'    => 'last',
                    'display_name' => 'display',
                    'emplid'       => 'emplid',
                    'email'        => 'email',
                    'expires_at'   => 'Feb 2, 2020',
                    'created_at'   => null,
                    'updated_at'   => null,
                ],
            ],
            $this->response
        );
    }
}