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

TestOfPearDateEngine::testStampToHour()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 10 and the first side effect is on line 190.

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
/**
8
 * Class TestOfPearDateEngine.
9
 */
10
class TestOfPearDateEngine extends UnitTestCase
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...
Bug introduced by
The type UnitTestCase 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...
11
{
12
    public $engine;
13
14
    /**
15
     * TestOfPearDateEngine constructor.
16
     */
17
    public function __construct()
18
    {
19
        parent::__construct('Test of Calendar_Engine_PearDate');
20
    }
21
22
    public function setUp()
23
    {
24
        $this->engine = new Calendar_Engine_PearDate();
25
    }
26
27
    public function testGetSecondsInMinute()
28
    {
29
        $this->assertEqual($this->engine->getSecondsInMinute(), _EXTCAL_TS_MINUTE);
30
    }
31
32
    public function testGetMinutesInHour()
33
    {
34
        $this->assertEqual($this->engine->getMinutesInHour(), _EXTCAL_TS_MINUTE);
35
    }
36
37
    public function testGetHoursInDay()
38
    {
39
        $this->assertEqual($this->engine->getHoursInDay(), 24);
40
    }
41
42
    public function testGetFirstDayOfWeek()
43
    {
44
        $this->assertEqual($this->engine->getFirstDayOfWeek(), 1);
45
    }
46
47
    public function testGetWeekDays()
48
    {
49
        $this->assertEqual($this->engine->getWeekDays(), [0, 1, 2, 3, 4, 5, 6]);
50
    }
51
52
    public function testGetDaysInWeek()
53
    {
54
        $this->assertEqual($this->engine->getDaysInWeek(), 7);
55
    }
56
57
    public function testGetWeekNInYear()
58
    {
59
        $this->assertEqual($this->engine->getWeekNInYear(2003, 11, 3), 45);
60
    }
61
62
    public function testGetWeekNInMonth()
63
    {
64
        $this->assertEqual($this->engine->getWeekNInMonth(2003, 11, 3), 2);
65
    }
66
67
    public function testGetWeeksInMonth0()
68
    {
69
        $this->assertEqual($this->engine->getWeeksInMonth(2003, 11, 0), 6); //week starts on sunday
70
    }
71
72
    public function testGetWeeksInMonth1()
73
    {
74
        $this->assertEqual($this->engine->getWeeksInMonth(2003, 11, 1), 5); //week starts on monday
75
    }
76
77
    public function testGetWeeksInMonth2()
78
    {
79
        $this->assertEqual($this->engine->getWeeksInMonth(2003, 2, 6), 4); //week starts on saturday
80
    }
81
82
    public function testGetWeeksInMonth3()
83
    {
84
        // Unusual cases that can cause fails (shows up with example 21.php)
85
        $this->assertEqual($this->engine->getWeeksInMonth(2004, 2, 1), 5);
86
        $this->assertEqual($this->engine->getWeeksInMonth(2004, 8, 1), 6);
87
    }
88
89
    public function testGetDayOfWeek()
90
    {
91
        $this->assertEqual($this->engine->getDayOfWeek(2003, 11, 18), 2);
92
    }
93
94
    public function testGetFirstDayInMonth()
95
    {
96
        $this->assertEqual($this->engine->getFirstDayInMonth(2003, 10), 3);
97
    }
98
99
    public function testGetDaysInMonth()
100
    {
101
        $this->assertEqual($this->engine->getDaysInMonth(2003, 10), 31);
102
    }
103
104
    public function testGetMinYears()
105
    {
106
        $this->assertEqual($this->engine->getMinYears(), 0);
107
    }
108
109
    public function testGetMaxYears()
110
    {
111
        $this->assertEqual($this->engine->getMaxYears(), 9999);
112
    }
113
114
    public function testDateToStamp()
115
    {
116
        $stamp = '2003-10-15 13:30:45';
117
        $this->assertEqual($this->engine->dateToStamp(2003, 10, 15, 13, 30, 45), $stamp);
118
    }
119
120
    public function testStampToSecond()
121
    {
122
        $stamp = '2003-10-15 13:30:45';
123
        $this->assertEqual($this->engine->stampToSecond($stamp), 45);
124
    }
125
126
    public function testStampToMinute()
127
    {
128
        $stamp = '2003-10-15 13:30:45';
129
        $this->assertEqual($this->engine->stampToMinute($stamp), 30);
130
    }
131
132
    public function testStampToHour()
133
    {
134
        $stamp = '2003-10-15 13:30:45';
135
        $this->assertEqual($this->engine->stampToHour($stamp), 13);
136
    }
137
138
    public function testStampToDay()
139
    {
140
        $stamp = '2003-10-15 13:30:45';
141
        $this->assertEqual($this->engine->stampToDay($stamp), 15);
142
    }
143
144
    public function testStampToMonth()
145
    {
146
        $stamp = '2003-10-15 13:30:45';
147
        $this->assertEqual($this->engine->stampToMonth($stamp), 10);
148
    }
149
150
    public function testStampToYear()
151
    {
152
        $stamp = '2003-10-15 13:30:45';
153
        $this->assertEqual($this->engine->stampToYear($stamp), 2003);
154
    }
155
156
    public function testAdjustDate()
157
    {
158
        $stamp = '2004-01-01 13:30:45';
159
        $y     = $this->engine->stampToYear($stamp);
160
        $m     = $this->engine->stampToMonth($stamp);
161
        $d     = $this->engine->stampToDay($stamp);
162
163
        //the first day of the month should be thursday
164
        $this->assertEqual($this->engine->getDayOfWeek($y, $m, $d), 4);
165
166
        --$m; // 2004-00-01 => 2003-12-01
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
167
        $this->engine->adjustDate($y, $m, $d, $dummy, $dummy, $dummy);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $dummy seems to be never defined.
Loading history...
168
169
        $this->assertEqual($y, 2003);
170
        $this->assertEqual($m, 12);
171
        $this->assertEqual($d, 1);
172
173
        // get last day and check if it's wednesday
174
        $d = $this->engine->getDaysInMonth($y, $m);
175
176
        $this->assertEqual($this->engine->getDayOfWeek($y, $m, $d), 3);
177
    }
178
179
    public function testIsToday()
180
    {
181
        $stamp = date('Y-m-d H:i:s');
182
        $this->assertTrue($this->engine->isToday($stamp));
183
        $stamp = date('Y-m-d H:i:s', time() + 1000000000);
184
        $this->assertFalse($this->engine->isToday($stamp));
185
    }
186
}
187
188
if (!defined('TEST_RUNNING')) {
189
    define('TEST_RUNNING', true);
190
    $test = new TestOfPearDateEngine();
191
    $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...
192
}
193