testSerializesShouldReturnEmtpyIfEventsAreEmpty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CalendarBundle\Tests\Serializer;
6
7
use CalendarBundle\Entity\Event;
8
use CalendarBundle\Serializer\Serializer;
9
use PHPUnit\Framework\TestCase;
10
11
class SerializerTest extends TestCase
12
{
13
    private $eventEntity1;
14
    private $eventEntity2;
15
    private $serializer;
16
17
    public function setUp(): void
18
    {
19
        $this->eventEntity1 = $this->createMock(Event::class);
20
        $this->eventEntity2 = $this->createMock(Event::class);
21
22
        $this->serializer = new Serializer();
23
    }
24
25
    public function testItSerializesDataSuccessfully()
26
    {
27
        $this->eventEntity1->method('toArray')->willReturn(
28
            [
29
                'title' => 'Event 1',
30
                'start' => '2015-01-20T11:50:00Z',
31
                'allDay' => false,
32
                'end' => '2015-01-21T11:50:00Z',
33
            ]
34
        );
35
        $this->eventEntity2->method('toArray')->willReturn(
36
            [
37
                'title' => 'Event 2',
38
                'start' => '2015-01-22T11:50:00Z',
39
                'allDay' => true,
40
            ]
41
        );
42
43
        $data = json_encode([
44
            [
45
                'title' => 'Event 1',
46
                'start' => '2015-01-20T11:50:00Z',
47
                'allDay' => false,
48
                'end' => '2015-01-21T11:50:00Z',
49
            ],
50
            [
51
                'title' => 'Event 2',
52
                'start' => '2015-01-22T11:50:00Z',
53
                'allDay' => true,
54
            ],
55
        ]);
56
57
        $this->assertEquals($data, $this->serializer->serialize([$this->eventEntity1, $this->eventEntity2]));
58
    }
59
60
    public function testSerializesShouldReturnEmtpyIfEventsAreEmpty()
61
    {
62
        $this->assertEquals('[]', $this->serializer->serialize([]));
63
    }
64
}
65