SerializerTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 26
c 2
b 0
f 0
dl 0
loc 52
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testSerializesShouldReturnEmtpyIfEventsAreEmpty() 0 3 1
A testItSerializesDataSuccessfully() 0 33 1
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