GroupDatabaseTest.php 2.77 KB
Newer Older
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
<?php


namespace Tests\Database;

use Source\Entities\Group;
use Tests\DatabaseTestCase;
use Source\Gateways\Groups\DatabaseGroupsRepository;

class GroupDatabaseTest extends DatabaseTestCase
{
    /**
     * @var \Source\Gateways\Groups\DatabaseGroupsRepository
     */
    protected DatabaseGroupsRepository $groups;

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

        $this->groups = new DatabaseGroupsRepository();
    }

    /**
     * @test
     */
    public function it_gets_all_groups(): void
    {
        $all = $this->groups->all();

        $this->assertEquals([], $all);

33
34
        $this->groups->create(new Group(0, 't1', ''));
        $this->groups->create(new Group(0, 't2', ''));
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

        $all = $this->groups->all();

        $this->assertCount(2, $all);
    }

    /**
     * @test
     */
    public function it_gets_a_group(): void
    {
        $group = $this->groups->get(10);

        $this->assertNull($group);

Jacob Priddy's avatar
Jacob Priddy committed
50
        $group = $this->groups->create(new Group(0, '', ''));
51

52
        $this->assertEquals($group, $this->groups->get($group->getId()));
53
54
    }

55
56
57
58
59
60
61
62
    /**
     * @test
     */
    public function it_cannot_get_non_existent_user(): void
    {
        $this->assertNull($this->groups->get('asdf'));
    }

63
64
65
66
67
68
69
    /**
     * @test
     */
    public function it_creates_a_group(): void
    {
        $group = $this->groups->create(new Group(0, '', ''));

70
        $this->assertEquals($group, $this->groups->get($group->getId()));
71
72
73
74
75
76
77
    }

    /**
     * @test
     */
    public function it_deletes_a_group(): void
    {
78
        $group = $this->groups->create(new Group(0, '', ''));
79

80
        $this->assertTrue($this->groups->delete($group->getId()));
81

82
        $this->assertFalse($this->groups->exists(new Group(9999999, '', '')));
83
84

        $this->assertFalse($this->groups->delete(2));
85
86

        $this->assertFalse($this->groups->delete('asdf'));
87
88
89
90
91
92
93
    }

    /**
     * @test
     */
    public function it_checks_existence_of_groups(): void
    {
94
        $g = $this->groups->create(new Group(0, '', ''));
95

96
97
        $this->assertFalse($this->groups->exists(new Group(0, 'asdf', 'asdf')));
        $this->assertTrue($this->groups->exists(new Group(0, '', '')));
98
99
100
101
102
103
104
    }

    /**
     * @test
     */
    public function it_updates_a_group(): void
    {
105
        $g = $this->groups->create(new Group(0, 'title', 'description'));
106

107
        $this->groups->update($g->getId(), new Group(0, 'new title', 'new desc'));
108

109
        $group = $this->groups->get($g->getId());
110
111
112
113

        $this->assertEquals('new title', $group->getTitle());
        $this->assertEquals('new desc', $group->getDescription());
    }
114
115
116
117
118
119
120
121

    /**
     * @test
     */
    public function it_cannot_update_non_existent_group(): void
    {
        $this->assertNull($this->groups->update(1, new Group(0, 'new title', 'new desc')));
    }
122
}