Passed
Pull Request — master (#41)
by Níckolas Daniel
04:58
created

JigsawParticipantRepositoryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 54
dl 0
loc 85
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A buildNewPage() 0 34 1
A testByEpisode() 0 22 1
A testAll() 0 13 1
A setUp() 0 4 1
1
<?php
2
3
namespace PODEntender\Infrastructure\Domain\Model\Participant;
4
5
use PODEntender\Domain\Model\Participant\Participant;
6
use PHPUnit\Framework\TestCase;
7
use TightenCo\Jigsaw\IterableObject;
8
use TightenCo\Jigsaw\Jigsaw;
9
use TightenCo\Jigsaw\PageVariable;
10
11
class JigsawParticipantRepositoryTest extends TestCase
12
{
13
    private $jigsaw;
14
15
    private $participantRepository;
16
17
    public function setUp(): void
18
    {
19
        $this->jigsaw = $this->prophesize(Jigsaw::class);
20
        $this->participantRepository = new JigsawParticipantRepository($this->jigsaw->reveal());
21
    }
22
23
    public function testByEpisode(): void
24
    {
25
        $this->jigsaw->getCollection('episodes')->willReturn(new PageVariable([
26
            $this->buildNewPage('2019-01-01', ['Nickolas', 'Tchecão'], '001'),
27
            $this->buildNewPage('2019-01-08', ['Dalton', 'Katarina'], '002'),
28
        ]));
29
30
        $participants = $this->participantRepository->byEpisode('001')
31
            ->map(function (Participant $participant) {
32
                return $participant->name();
33
            });
34
35
        $this->assertEquals('Nickolas', $participants->first());
36
        $this->assertEquals('Tchecão', $participants->last());
37
38
        $participants = $this->participantRepository->byEpisode('002')
39
            ->map(function (Participant $participant) {
40
                return $participant->name();
41
            });
42
43
        $this->assertEquals('Dalton', $participants->first());
44
        $this->assertEquals('Katarina', $participants->last());
45
    }
46
47
    public function testAll()
48
    {
49
        $this->jigsaw->getCollection('episodes')->willReturn(new PageVariable([
50
            $this->buildNewPage('2019-01-01', ['Nickolas', 'Tchecão'], '001'),
51
            $this->buildNewPage('2019-01-08', ['Dalton', 'Katarina'], '002'),
52
        ]));
53
54
        $participants = $this->participantRepository->all();
55
56
        $this->assertEquals('Nickolas', $participants->get(0)->name());
57
        $this->assertEquals('Tchecão', $participants->get(1)->name());
58
        $this->assertEquals('Dalton', $participants->get(2)->name());
59
        $this->assertEquals('Katarina', $participants->get(3)->name());
60
    }
61
62
    private function buildNewPage(string $postDate, array $participants, ?string $number = 'default'): PageVariable
63
    {
64
        $participants = array_map(function (string $name) {
65
            return [
66
                'name' => $name,
67
                'picture' => '',
68
                'description' => '',
69
            ];
70
        }, $participants);
71
72
        return new PageVariable([
73
            'extends' => '_layouts/test-base',
74
            'postDate' => strtotime($postDate),
75
            'category' => 'episodio',
76
            'date' => strtotime($postDate),
77
            'participants' => $participants,
78
            'episode' => [
79
                'number' => $number,
80
                'title' => '',
81
                'description' => '',
82
                'author' => '',
83
                'date' => strtotime($postDate),
84
                'audioUrl' => $postDate . '.mp3',
85
                'cover' => [
86
                    'url' => '',
87
                ],
88
            ],
89
            '_meta' => new IterableObject([
90
                'baseUrl' => 'tmp://test.env',
91
                'category' => 'episodio',
92
                'content' => 'dummy content',
93
                'collectionName' => 'episodes',
94
                'url' => '/test/' . $postDate . '.html',
95
                'filename' => 'test/filename/' . $postDate . '.md',
96
            ]),
97
        ]);
98
    }
99
}
100