Completed
Push — master ( ea8409...03835b )
by Emil
02:17
created

ScheduleTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 20 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
lcom 0
cbo 1
dl 14
loc 70
rs 10
c 1
b 0
f 0

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
namespace Glooby\TaskBundle\Tests\Annotation\Schedule;
4
5
use Glooby\TaskBundle\Annotation\Schedule;
6
7
/**
8
 * @author Emil Kilhage
9
 */
10
class ScheduleTest extends \PHPUnit_Framework_TestCase
11
{
12
    public function testSimple()
13
    {
14
        $schedule = new Schedule(['value' => '@daily']);
15
16
        $this->assertEquals('0 0 * * *', $schedule->runEvery);
17
        $this->assertTrue($schedule->active);
18
    }
19
20
    public function testInterval()
21
    {
22
        $schedule = new Schedule(['runEvery' => '@daily']);
23
24
        $this->assertEquals('0 0 * * *', $schedule->runEvery);
25
        $this->assertTrue($schedule->active);
26
    }
27
28
    public function testIntervalActiveParams()
29
    {
30
        $schedule = new Schedule([
31
            'runEvery' => '@daily',
32
            'active' => false,
33
            'params' => [1],
34
        ]);
35
36
        $this->assertEquals('0 0 * * *', $schedule->runEvery);
37
        $this->assertEquals([1], $schedule->params);
38
        $this->assertFalse($schedule->active);
39
    }
40
41
    public function testParamsNonArray()
42
    {
43
        $this->setExpectedException('\InvalidArgumentException');
44
45
        new Schedule([
46
            'interval' => '@daily',
47
            'active' => false,
48
            'params' => 'foo',
49
        ]);
50
    }
51
52
    public function testInvalidProperty()
53
    {
54
        $this->setExpectedException('\InvalidArgumentException');
55
56
        new Schedule(['fooo' => '@daily']);
57
    }
58
59
    public function testInvalidInterval()
60
    {
61
        $this->setExpectedException('\InvalidArgumentException');
62
63
        new Schedule(['runEvery' => 'fdsfds fds']);
64
    }
65
66
    public function testMissingInvalid()
67
    {
68
        $this->setExpectedException('\InvalidArgumentException');
69
70
        new Schedule([]);
71
    }
72
73
    public function testInvalidTimeout()
74
    {
75
        $this->setExpectedException('\InvalidArgumentException');
76
77
        new Schedule(['interval' => '@daily', 'timeout' => 'x']);
78
    }
79
}
80