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

CalendarFactoryTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testRenderEmptyCalendar() 0 12 1
A testRenderWithEvents() 0 33 1
1
<?php
2
3
4
namespace Eluceo\iCal\Test\Unit\Presentation\Factory;
5
6
use DateTimeImmutable;
7
use DateTimeZone;
8
use Eluceo\iCal\Domain\Entity\Calendar;
9
use Eluceo\iCal\Domain\Entity\Event;
10
use Eluceo\iCal\Domain\ValueObject\Timestamp;
11
use Eluceo\iCal\Domain\ValueObject\UniqueIdentifier;
12
use Eluceo\iCal\Presentation\Component;
13
use Eluceo\iCal\Presentation\Factory\CalendarFactory;
14
use PHPUnit\Framework\TestCase;
15
16
class CalendarFactoryTest extends TestCase
17
{
18
    public function testRenderEmptyCalendar()
19
    {
20
        $calendar = Calendar::create();
21
        $expected = implode(Component::LINE_SEPARATOR, [
22
            'BEGIN:VCALENDAR',
23
            'PRODID:' . $calendar->getProductIdentifier(),
24
            'VERSION:2.0',
25
            'END:VCALENDAR'
26
        ]);
27
28
        self::assertSame($expected, (string)(new CalendarFactory())->createCalendar($calendar));
29
    }
30
31
    public function testRenderWithEvents()
32
    {
33
        $currentTime = Timestamp::fromDateTimeInterface(
34
            DateTimeImmutable::createFromFormat(
35
                'Y-m-d H:i:s',
36
                '2019-11-10 11:22:33',
37
                new DateTimeZone('UTC')
38
            )
39
        );
40
        $calendar = Calendar::create(
41
            [
42
                Event::create(UniqueIdentifier::fromString('event1'))->touch($currentTime),
43
                Event::create(UniqueIdentifier::fromString('event2'))->touch($currentTime),
44
            ]
45
        );
46
47
        $expected = implode(Component::LINE_SEPARATOR, [
48
            'BEGIN:VCALENDAR',
49
            'PRODID:' . $calendar->getProductIdentifier(),
50
            'VERSION:2.0',
51
            'BEGIN:VEVENT',
52
            'UID:event1',
53
            'DTSTAMP:20191110T112233Z',
54
            'END:VEVENT',
55
            'BEGIN:VEVENT',
56
            'UID:event2',
57
            'DTSTAMP:20191110T112233Z',
58
            'END:VEVENT',
59
            'END:VCALENDAR',
60
        ]);
61
62
        self::assertSame($expected, (string)(new CalendarFactory())->createCalendar($calendar));
63
    }
64
}
65