UseCaseTest.php 1.85 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
<?php


namespace Tests\Unit\Source\UseCases\Groups\GetAllGroups;

use Source\Entities\Group;
use PHPUnit\Framework\TestCase;
use Source\Gateways\Groups\InMemoryGroupsRepository;
use Source\UseCases\Groups\GetAllGroups\GetAllGroups;
use Source\UseCases\Groups\GetAllGroups\ResponseModel;

class UseCaseTest extends TestCase
{
    /**
     * @var \Source\Gateways\Groups\InMemoryGroupsRepository
     */
    protected InMemoryGroupsRepository $groupsRepository;

    /**
     * @var \Source\UseCases\Groups\GetAllGroups\GetAllGroups
     */
    protected GetAllGroups $useCase;

    /**
     * @var \Source\UseCases\Groups\GetAllGroups\ResponseModel
     */
    protected ResponseModel $response;

    /**
     * @var \Tests\Unit\Source\UseCases\Groups\GetAllGroups\PresenterStub
     */
    protected PresenterStub $presenter;

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

        $this->groupsRepository = new InMemoryGroupsRepository();
        $this->useCase = new GetAllGroups($this->groupsRepository);
        $this->presenter = new PresenterStub();
    }

    public function handleTest(): void
    {
        $this->useCase->all($this->presenter);

        $this->response = $this->presenter->response;
    }

    /** @test */
    public function presenter_was_called(): void
    {
        $this->handleTest();

        $this->assertTrue($this->presenter->wasPresenterCalled());
    }

    /** @test */
    public function it_works_when_no_groups_are_added(): void
    {
        $this->handleTest();

        $this->assertEquals([], $this->response->getGroups());
    }

    /** @test */
    public function it_sees_groups(): void
    {
        $this->groupsRepository->create(new Group(0, '', ''));
        $this->groupsRepository->create(new Group(0, '', ''));

        $this->handleTest();

        $this->assertCount(2, $this->response->getGroups());
    }
}