PresenterTest.php 1.65 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

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

Jacob Priddy's avatar
Jacob Priddy committed
12
13
class PresenterTest extends TestCase
{
Jacob Priddy's avatar
Jacob Priddy committed
14
15
16
17
18
19
    protected APIPresenter $presenter;

    protected ResponseModel $model;

    protected array $response;

Jacob Priddy's avatar
Jacob Priddy committed
20
21
    public function setUp(): void
    {
Jacob Priddy's avatar
Jacob Priddy committed
22
23
24
25
26
        parent::setUp();

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

Jacob Priddy's avatar
Jacob Priddy committed
27
28
    public function handleTest(User $user): void
    {
Jacob Priddy's avatar
Jacob Priddy committed
29
30
31
32
33
34
35
36
        $this->model = new ResponseModel($user);

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

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

    /** @test */
Jacob Priddy's avatar
Jacob Priddy committed
37
38
    public function it_formats_a_user(): void
    {
Jacob Priddy's avatar
Jacob Priddy committed
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
        $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',
64
                    'expires_at'   => '2020-02-02T00:00:00+00:00',
Jacob Priddy's avatar
Jacob Priddy committed
65
66
67
68
69
70
71
72
                    'created_at'   => null,
                    'updated_at'   => null,
                ],
            ],
            $this->response
        );
    }
}