Passed
Push — master ( d2520f...3f8ec2 )
by Michael
02:50
created

TestOfDayBuild   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
dl 0
loc 51
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testFetchAll() 0 10 2
A testSize() 0 4 1
A testSelection() 0 13 3
A __construct() 0 3 1
A testFetch() 0 8 2
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 150.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
//
3
4
require_once __DIR__ . '/simple_include.php';
5
require_once __DIR__ . '/calendar_include.php';
6
7
require_once __DIR__ . '/./calendar_test.php';
8
9
/**
10
 * Class TestOfDay.
11
 */
12
class TestOfDay extends TestOfCalendar
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
{
14
    /**
15
     * TestOfDay constructor.
16
     */
17
    public function __construct()
18
    {
19
        $this->UnitTestCase('Test of Day');
20
    }
21
22
    public function setUp()
23
    {
24
        $this->cal = new Calendar_Day(2003, 10, 25);
25
    }
26
27
    public function testPrevDay_Array()
28
    {
29
        $this->assertEqual([
30
                               'year'   => 2003,
31
                               'month'  => 10,
32
                               'day'    => 24,
33
                               'hour'   => 0,
34
                               'minute' => 0,
35
                               'second' => 0,
36
                           ], $this->cal->prevDay('array'));
37
    }
38
39
    public function testPrevHour()
40
    {
41
        $this->assertEqual(23, $this->cal->prevHour());
42
    }
43
44
    public function testThisHour()
45
    {
46
        $this->assertEqual(0, $this->cal->thisHour());
47
    }
48
49
    public function testNextHour()
50
    {
51
        $this->assertEqual(1, $this->cal->nextHour());
52
    }
53
54
    public function testPrevMinute()
55
    {
56
        $this->assertEqual(59, $this->cal->prevMinute());
57
    }
58
59
    public function testThisMinute()
60
    {
61
        $this->assertEqual(0, $this->cal->thisMinute());
62
    }
63
64
    public function testNextMinute()
65
    {
66
        $this->assertEqual(1, $this->cal->nextMinute());
67
    }
68
69
    public function testPrevSecond()
70
    {
71
        $this->assertEqual(59, $this->cal->prevSecond());
72
    }
73
74
    public function testThisSecond()
75
    {
76
        $this->assertEqual(0, $this->cal->thisSecond());
77
    }
78
79
    public function testNextSecond()
80
    {
81
        $this->assertEqual(1, $this->cal->nextSecond());
82
    }
83
84
    public function testGetTimeStamp()
85
    {
86
        $stamp = mktime(0, 0, 0, 10, 25, 2003);
87
        $this->assertEqual($stamp, $this->cal->getTimestamp());
88
    }
89
}
90
91
/**
92
 * Class TestOfDayBuild.
93
 */
94
class TestOfDayBuild extends TestOfDay
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
95
{
96
    /**
97
     * TestOfDayBuild constructor.
98
     */
99
    public function __construct()
100
    {
101
        $this->UnitTestCase('Test of Day::build()');
102
    }
103
104
    public function testSize()
105
    {
106
        $this->cal->build();
107
        $this->assertEqual(24, $this->cal->size());
108
    }
109
110
    public function testFetch()
111
    {
112
        $this->cal->build();
113
        $i = 0;
114
        while ($Child = $this->cal->fetch()) {
0 ignored issues
show
Unused Code introduced by
The assignment to $Child is dead and can be removed.
Loading history...
115
            ++$i;
116
        }
117
        $this->assertEqual(24, $i);
118
    }
119
120
    public function testFetchAll()
121
    {
122
        $this->cal->build();
123
        $children = [];
124
        $i        = 0;
125
        while ($Child = $this->cal->fetch()) {
126
            $children[$i] = $Child;
127
            ++$i;
128
        }
129
        $this->assertEqual($children, $this->cal->fetchAll());
130
    }
131
132
    public function testSelection()
133
    {
134
        require_once CALENDAR_ROOT . 'Hour.php';
135
        $selection = [new Calendar_Hour(2003, 10, 25, 13)];
136
        $this->cal->build($selection);
137
        $i = 0;
138
        while ($Child = $this->cal->fetch()) {
139
            if (13 == $i) {
140
                break;
141
            }
142
            ++$i;
143
        }
144
        $this->assertTrue($Child->isSelected());
145
    }
146
}
147
148
if (!defined('TEST_RUNNING')) {
149
    define('TEST_RUNNING', true);
150
    $test = new TestOfDay();
151
    $test->run(new HtmlReporter());
0 ignored issues
show
Bug introduced by
The type HtmlReporter 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...
152
    $test = new TestOfDayBuild();
153
    $test->run(new HtmlReporter());
154
}
155