Completed
Pull Request — master (#144)
by Markus
02:45 queued 01:47
created

CalendarTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 88
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testEmptyCalendarToString() 0 9 1
A testWithSingleComponentToString() 0 17 1
A testWithMultipleComponentsToString() 0 32 1
A testRenderOwnPropertiesBeforeComponents() 0 24 1
1
<?php
2
3
namespace Eluceo\iCal\Test\Unit\Presentation;
4
5
use Eluceo\iCal\Presentation\Calendar;
6
use Eluceo\iCal\Presentation\Component;
7
use Eluceo\iCal\Presentation\Component\Property;
8
use Eluceo\iCal\Presentation\Component\Property\Value\StringValue;
9
use PHPUnit\Framework\TestCase;
10
11
class CalendarTest extends TestCase
12
{
13
    public function testEmptyCalendarToString()
14
    {
15
        $expected = implode(Component::LINE_SEPARATOR, [
16
            'BEGIN:VCALENDAR',
17
            'END:VCALENDAR',
18
        ]);
19
20
        self::assertSame($expected, (string)Calendar::createCalendar());
21
    }
22
23
    public function testWithSingleComponentToString()
24
    {
25
        $expected = implode(Component::LINE_SEPARATOR, [
26
            'BEGIN:VCALENDAR',
27
            'BEGIN:VEVENT',
28
            'END:VEVENT',
29
            'END:VCALENDAR',
30
        ]);
31
32
        $components = [
33
            Component::create('VEVENT'),
34
        ];
35
36
        $calendar = Calendar::createCalendar($components);
37
38
        self::assertSame($expected, (string)$calendar);
39
    }
40
41
    public function testWithMultipleComponentsToString()
42
    {
43
        $expected = implode(Component::LINE_SEPARATOR, [
44
            'BEGIN:VCALENDAR',
45
            'BEGIN:VEVENT',
46
            'UID:event1',
47
            'END:VEVENT',
48
            'BEGIN:VEVENT',
49
            'UID:event2',
50
            'END:VEVENT',
51
            'END:VCALENDAR',
52
        ]);
53
54
        $components = [
55
            Component::create(
56
                'VEVENT',
57
                [
58
                    Property::create('UID', StringValue::fromString('event1')),
59
                ]
60
            ),
61
            Component::create(
62
                'VEVENT',
63
                [
64
                    Property::create('UID', StringValue::fromString('event2')),
65
                ]
66
            ),
67
        ];
68
69
        $calendar = Calendar::createCalendar($components);
70
71
        self::assertSame($expected, (string)$calendar);
72
    }
73
74
    public function testRenderOwnPropertiesBeforeComponents()
75
    {
76
        $expected = implode(Component::LINE_SEPARATOR, [
77
            'BEGIN:VCALENDAR',
78
            'TEST:value',
79
            'TEST2:value2',
80
            'BEGIN:VEVENT',
81
            'END:VEVENT',
82
            'END:VCALENDAR',
83
        ]);
84
85
        $properties = [
86
            Property::create('TEST', StringValue::fromString('value')),
87
            Property::create('TEST2', StringValue::fromString('value2')),
88
        ];
89
90
        $components = [
91
            Component::create('VEVENT'),
92
        ];
93
94
        $calendar = Calendar::createCalendar($components, $properties);
95
96
        self::assertSame($expected, (string)$calendar);
97
    }
98
}
99