LibCaldav_basicTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 18.46 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 12
loc 65
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 4 1
A testStorageBackendValue() 0 4 1
A testServer() 0 6 1
A testEventSave() 0 21 1
A testEventGet() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
require_once dirname(__FILE__).'/mock/functions.php';
4
require_once dirname(__FILE__).'/../programs/caldav.class.php';
5
require_once dirname(__FILE__).'/mock/calendar.php';
6
7
8
9
10
11
class LibCaldav_basicTest extends PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @var LibCaldav_mock
15
     */
16
    static $mock;
17
18
    public static function setUpBeforeClass()
19
    {
20
        self::$mock = bab_getInstance('LibCaldav_mock');
21
    }
22
    
23
    
24
    
25
    public function testStorageBackendValue()
26
    {
27
        $this->assertTrue(self::$mock->getCaldavBackend()->StorageBackend());
28
    }
29
    
30
    
31
    
32
    public function testServer()
33
    {
34
        $id_user = self::$mock->getCaldavUser();
35
        $backend = self::$mock->getCaldavBackend();
36
        $this->assertTrue($backend->checkCalendar($id_user), 'check calendar on localhost:5232');
37
    }
38
    
39
    
40
    public function testEventSave()
41
    {
42
        $id_user = self::$mock->getCaldavUser();
43
        $backend = self::$mock->getCaldavBackend();
44
        
45
        
46
        $calendar = $backend->PersonalCalendar($id_user);
47
        $collection = $backend->CalendarEventCollection($calendar);
48
        
49
        $dtstart = BAB_DateTime::fromIsoDateTime('2015-01-01 00:00:00');
50
        $dtend = BAB_DateTime::fromIsoDateTime('2015-01-02 00:00:00');
51
        
52
        $period = new bab_CalendarPeriod();
53
        $period->setDates($dtstart, $dtend);
54
        $period->setProperty('UID', 'LIBCALDAV_UNITTEST_1');
55
        $period->setProperty('SUMMARY', 'Test event');
56
        
57
        $collection->addPeriod($period);
58
        
59
        $this->assertTrue($backend->savePeriod($period));
60
    }
61
    
62
    
63 View Code Duplication
    public function testEventGet()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        $id_user = self::$mock->getCaldavUser();
66
        $backend = self::$mock->getCaldavBackend();
67
        $calendar = $backend->PersonalCalendar($id_user);
68
        $collection = $backend->CalendarEventCollection($calendar);
69
        
70
        $period = $backend->getPeriod($collection, 'LIBCALDAV_UNITTEST_1');
71
        
72
        $this->assertInstanceOf('caldav_CalendarPeriod', $period);
73
        $this->assertEquals('Test event', $period->getProperty('SUMMARY'));
74
    }
75
}
76