PresenterTest.php 1.71 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
{
14
15
16
    /**
     * @var \Source\UseCases\Users\GetUser\APIPresenter
     */
Jacob Priddy's avatar
Jacob Priddy committed
17
18
    protected APIPresenter $presenter;

19
20
21
    /**
     * @var \Source\UseCases\Users\GetUser\ResponseModel
     */
Jacob Priddy's avatar
Jacob Priddy committed
22
23
    protected ResponseModel $model;

24
25
26
    /**
     * @var array
     */
Jacob Priddy's avatar
Jacob Priddy committed
27
28
    protected array $response;

Jacob Priddy's avatar
Jacob Priddy committed
29
30
    public function setUp(): void
    {
Jacob Priddy's avatar
Jacob Priddy committed
31
32
33
34
35
        parent::setUp();

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

Jacob Priddy's avatar
Jacob Priddy committed
36
37
    public function handleTest(User $user): void
    {
Jacob Priddy's avatar
Jacob Priddy committed
38
39
40
41
42
43
44
45
        $this->model = new ResponseModel($user);

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

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

    /** @test */
Jacob Priddy's avatar
Jacob Priddy committed
46
47
    public function it_formats_a_user(): void
    {
Jacob Priddy's avatar
Jacob Priddy committed
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);

64
65
66
67
68
69
70
71
72
73
74
        $this->assertEquals([
            'user' => [
                'id' => 0,
                'first_name' => 'first',
                'last_name' => 'last',
                'display_name' => 'display',
                'emplid' => 'emplid',
                'email' => 'email',
                'expires_at' => '2020-02-02T00:00:00+00:00',
                'created_at' => null,
                'updated_at' => null,
Jacob Priddy's avatar
Jacob Priddy committed
75
            ],
76
        ], $this->response);
Jacob Priddy's avatar
Jacob Priddy committed
77
78
    }
}