PresenterTest.php 1.63 KB
Newer Older
Jacob Priddy's avatar
Jacob Priddy committed
1
2
3
4
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
71
72
73
74
75
76
77
78
<?php


namespace Tests\Unit\Source\UseCases\Doors\Authenticate;

use Carbon\Carbon;
use Source\Entities\User;
use Source\Entities\Door;
use Source\Entities\Token;
use PHPUnit\Framework\TestCase;
use Source\UseCases\Doors\Authenticate\ResponseModel;
use Source\UseCases\Doors\Authenticate\TranslationPresenter;

class PresenterTest extends TestCase
{
    /**
     * @var \Source\UseCases\Doors\Authenticate\TranslationPresenter
     */
    protected TranslationPresenter $presenter;

    /**
     * @var \Source\UseCases\Doors\Authenticate\ResponseModel
     */
    protected ResponseModel $model;

    /**
     * @var \App\Door|null
     */
    protected ?\App\Door $response;

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

        $this->presenter = new TranslationPresenter();

        $this->model = new ResponseModel();
    }

    public function handleTest(): void
    {
        $this->presenter->present($this->model);

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

    /**
     * @test
     */
    public function it_presents_a_null_door(): void
    {
        $this->model->setDoor(null);

        $this->handleTest();

        $this->assertNull($this->response);
    }

    /**
     * @test
     */
    public function it_presents_a_door(): void
    {
        $door = new Door(0, 'location', 'name', 'token');

        $this->model->setDoor($door);

        $this->handleTest();

        $this->assertEquals(new \App\Door([
            'id' => 0,
            'name' => 'name',
            'location' => 'location',
            'created_at' => null,
            'updated_at' => null,
        ]), $this->response);
    }
}