CategoryTest::test_it_change_name()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 0
dl 0
loc 22
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tests\Domain\Category;
6
7
use App\Domain\Category\Category;
8
use App\Domain\Category\Events\CategoryNameWasChanged;
9
use App\Domain\Category\Events\CategoryWasCreated;
10
use App\Domain\Category\Events\CategoryWasDeleted;
11
use App\Domain\Category\Exception\SameNameException;
12
use App\Domain\Common\ValueObject\AggregateRootId;
13
use App\Domain\Common\ValueObject\Name;
14
use Tests\TestCase;
15
16
class CategoryTest extends TestCase
17
{
18
    public function test_it_create()
19
    {
20
        $category = Category::create(
21
            AggregateRootId::generate(),
22
            Name::fromString('test')
23
        );
24
        $this->assertInstanceOf(Category::class, $category);
25
        $events = $this->popRecordedEvent($category);
26
        $this->assertEquals(1, \count($events));
27
        $this->assertInstanceOf(CategoryWasCreated::class, $events[0]);
28
        $expectedPayload = [
29
            'name' => 'test',
30
        ];
31
        $this->assertEquals($expectedPayload, $events[0]->payload());
32
    }
33
34
    public function test_it_change_name()
35
    {
36
        $category = Category::create(
37
            AggregateRootId::generate(),
38
            Name::fromString('test')
39
        );
40
        $this->assertInstanceOf(Category::class, $category);
41
        $events = $this->popRecordedEvent($category);
42
        $this->assertEquals(1, \count($events));
43
        $this->assertInstanceOf(CategoryWasCreated::class, $events[0]);
44
        $expectedPayload = [
45
            'name' => 'test',
46
        ];
47
        $this->assertEquals($expectedPayload, $events[0]->payload());
48
        $category->changeName('test2');
49
        $events = $this->popRecordedEvent($category);
50
        $this->assertEquals(1, \count($events));
51
        $this->assertInstanceOf(CategoryNameWasChanged::class, $events[0]);
52
        $expectedPayload = [
53
            'name' => 'test2',
54
        ];
55
        $this->assertEquals($expectedPayload, $events[0]->payload());
56
    }
57
58
    public function test_it_change_to_same_name()
59
    {
60
        self::expectException(SameNameException::class);
61
        $category = Category::create(
62
            AggregateRootId::generate(),
63
            Name::fromString('test')
64
        );
65
        $this->assertInstanceOf(Category::class, $category);
66
        $events = $this->popRecordedEvent($category);
67
        $this->assertEquals(1, \count($events));
68
        $this->assertInstanceOf(CategoryWasCreated::class, $events[0]);
69
        $expectedPayload = [
70
            'name' => 'test',
71
        ];
72
        $this->assertEquals($expectedPayload, $events[0]->payload());
73
        $category->changeName('test');
74
        $events = $this->popRecordedEvent($category);
75
        $this->assertEquals(1, \count($events));
76
        $this->assertInstanceOf(CategoryNameWasChanged::class, $events[0]);
77
        $expectedPayload = [
78
            'name' => 'test2',
79
        ];
80
        $this->assertEquals($expectedPayload, $events[0]->payload());
81
    }
82
83
    public function test_it_delete()
84
    {
85
        $category = Category::create(
86
            AggregateRootId::generate(),
87
            Name::fromString('test')
88
        );
89
        $this->assertInstanceOf(Category::class, $category);
90
        $events = $this->popRecordedEvent($category);
91
        $this->assertEquals(1, \count($events));
92
        $this->assertInstanceOf(CategoryWasCreated::class, $events[0]);
93
        $expectedPayload = [
94
            'name' => 'test',
95
        ];
96
        $this->assertEquals($expectedPayload, $events[0]->payload());
97
        $category->delete();
98
        $events = $this->popRecordedEvent($category);
99
        $this->assertEquals(1, \count($events));
100
        $this->assertInstanceOf(CategoryWasDeleted::class, $events[0]);
101
        $expectedPayload = [];
102
        $this->assertEquals($expectedPayload, $events[0]->payload());
103
    }
104
}
105