Test Failed
Push — master ( 37023c...961468 )
by Theo
01:47
created

SerializerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 48
rs 10
c 0
b 0
f 0
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
namespace CalendarBundle\Tests\Serializer;
4
5
use PhpSpec\ObjectBehavior;
0 ignored issues
show
Bug introduced by
The type PhpSpec\ObjectBehavior was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Prophecy\Argument;
7
use CalendarBundle\Entity\Event;
8
use CalendarBundle\Serializer\Serializer;
9
use PHPUnit\Framework\TestCase;
10
11
class SerializerTest extends TestCase
12
{
13
    public function setUp(): void
14
    {
15
        $this->eventEntity1 = $this->createMock(Event::class);
0 ignored issues
show
Bug Best Practice introduced by
The property eventEntity1 does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
16
        $this->eventEntity2 = $this->createMock(Event::class);
0 ignored issues
show
Bug Best Practice introduced by
The property eventEntity2 does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
17
18
        $this->serializer = new Serializer();
0 ignored issues
show
Bug Best Practice introduced by
The property serializer does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
19
    }
20
21
    public function testItSerializesDataSuccessfully()
22
    {
23
        $this->eventEntity1->method('toArray')->willReturn(
24
            [
25
                'title' => 'Event 1',
26
                'start' => '2015-01-20T11:50:00Z',
27
                'allDay' => false,
28
                'end' => '2015-01-21T11:50:00Z',
29
            ]
30
        );
31
        $this->eventEntity2->method('toArray')->willReturn(
32
            [
33
                'title' => 'Event 2',
34
                'start' => '2015-01-22T11:50:00Z',
35
                'allDay' => true,
36
            ]
37
        );
38
39
        $data = json_encode([
40
            [
41
                'title' => 'Event 1',
42
                'start' => '2015-01-20T11:50:00Z',
43
                'allDay' => false,
44
                'end' => '2015-01-21T11:50:00Z',
45
            ],
46
            [
47
                'title' => 'Event 2',
48
                'start' => '2015-01-22T11:50:00Z',
49
                'allDay' => true,
50
            ]
51
        ]);
52
53
        $this->assertEquals($data, $this->serializer->serialize([$this->eventEntity1, $this->eventEntity2]));
54
    }
55
56
    public function testSerializesShouldReturnEmtpyIfEventsAreEmpty()
57
    {
58
        $this->assertEquals('[]', $this->serializer->serialize([]));
59
    }
60
}
61