This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace HMLB\Date\Tests\Date; |
||
4 | |||
5 | /* |
||
6 | * This file is part of the Date package. |
||
7 | * |
||
8 | * (c) Hugues Maignol <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | use HMLB\Date\Date; |
||
15 | use HMLB\Date\Tests\AbstractTestCase; |
||
16 | |||
17 | class GettersTest extends AbstractTestCase |
||
18 | { |
||
19 | public function testYearGetter() |
||
20 | { |
||
21 | $d = Date::create(1234, 5, 6, 7, 8, 9); |
||
22 | $this->assertSame(1234, $d->getYear()); |
||
23 | } |
||
24 | |||
25 | public function testYearIsoGetter() |
||
26 | { |
||
27 | $d = Date::createFromDate(2012, 12, 31); |
||
28 | $this->assertSame(2013, $d->getYearIso()); |
||
29 | } |
||
30 | |||
31 | public function testMonthGetter() |
||
32 | { |
||
33 | $d = Date::create(1234, 5, 6, 7, 8, 9); |
||
34 | $this->assertSame(5, $d->getMonth()); |
||
35 | } |
||
36 | |||
37 | public function testDayGetter() |
||
38 | { |
||
39 | $d = Date::create(1234, 5, 6, 7, 8, 9); |
||
40 | $this->assertSame(6, $d->getDay()); |
||
41 | } |
||
42 | |||
43 | public function testHourGetter() |
||
44 | { |
||
45 | $d = Date::create(1234, 5, 6, 7, 8, 9); |
||
46 | $this->assertSame(7, $d->getHour()); |
||
47 | } |
||
48 | |||
49 | public function testMinuteGetter() |
||
50 | { |
||
51 | $d = Date::create(1234, 5, 6, 7, 8, 9); |
||
52 | $this->assertSame(8, $d->getMinute()); |
||
53 | } |
||
54 | |||
55 | public function testSecondGetter() |
||
56 | { |
||
57 | $d = Date::create(1234, 5, 6, 7, 8, 9); |
||
58 | $this->assertSame(9, $d->getSecond()); |
||
59 | } |
||
60 | |||
61 | public function testMicroGetter() |
||
62 | { |
||
63 | $micro = 345678; |
||
64 | $d = Date::parse('2014-01-05 12:34:11.'.$micro); |
||
65 | $this->assertSame($micro, $d->getMicro()); |
||
66 | } |
||
67 | |||
68 | public function testMicroGetterWithDefaultNow() |
||
69 | { |
||
70 | $d = Date::now(); |
||
71 | $this->assertSame(0, $d->getMicro()); |
||
72 | } |
||
73 | |||
74 | public function testDayOfWeeGetter() |
||
75 | { |
||
76 | $d = Date::create(2012, 5, 7, 7, 8, 9); |
||
77 | $this->assertSame(Date::MONDAY, $d->getDayOfWeek()); |
||
78 | } |
||
79 | |||
80 | public function testDayOfYearGetter() |
||
81 | { |
||
82 | $d = Date::createFromDate(2012, 5, 7); |
||
83 | $this->assertSame(127, $d->getDayOfYear()); |
||
84 | } |
||
85 | |||
86 | public function testDaysInMonthGetter() |
||
87 | { |
||
88 | $d = Date::createFromDate(2012, 5, 7); |
||
89 | $this->assertSame(31, $d->getDaysInMonth()); |
||
90 | } |
||
91 | |||
92 | public function testTimestampGetter() |
||
93 | { |
||
94 | $d = Date::create()->setTimezone('GMT')->setDateTime(1970, 1, 1, 0, 0, 0)->getTimestamp(); |
||
95 | $this->assertSame(0, $d); |
||
96 | } |
||
97 | |||
98 | public function testGetAge() |
||
99 | { |
||
100 | $d = Date::now(); |
||
101 | $this->assertSame(0, $d->getAge()); |
||
102 | } |
||
103 | |||
104 | public function testGetAgeWithRealAge() |
||
105 | { |
||
106 | $d = Date::createFromDate(1975, 5, 21); |
||
107 | $age = intval(substr(date('Ymd') - date('Ymd', $d->getTimestamp()), 0, -4)); |
||
108 | |||
109 | $this->assertSame($age, $d->getAge()); |
||
110 | } |
||
111 | |||
112 | public function testGetQuarterFirst() |
||
113 | { |
||
114 | $d = Date::createFromDate(2012, 1, 1); |
||
115 | $this->assertSame(1, $d->getQuarter()); |
||
116 | } |
||
117 | |||
118 | public function testGetQuarterFirstEnd() |
||
119 | { |
||
120 | $d = Date::createFromDate(2012, 3, 31); |
||
121 | $this->assertSame(1, $d->getQuarter()); |
||
122 | } |
||
123 | |||
124 | public function testGetQuarterSecond() |
||
125 | { |
||
126 | $d = Date::createFromDate(2012, 4, 1); |
||
127 | $this->assertSame(2, $d->getQuarter()); |
||
128 | } |
||
129 | |||
130 | public function testGetQuarterThird() |
||
131 | { |
||
132 | $d = Date::createFromDate(2012, 7, 1); |
||
133 | $this->assertSame(3, $d->getQuarter()); |
||
134 | } |
||
135 | |||
136 | public function testGetQuarterFourth() |
||
137 | { |
||
138 | $d = Date::createFromDate(2012, 10, 1); |
||
139 | $this->assertSame(4, $d->getQuarter()); |
||
140 | } |
||
141 | |||
142 | public function testGetQuarterFirstLast() |
||
143 | { |
||
144 | $d = Date::createFromDate(2012, 12, 31); |
||
145 | $this->assertSame(4, $d->getQuarter()); |
||
146 | } |
||
147 | |||
148 | public function testGetLocalTrue() |
||
149 | { |
||
150 | // Default timezone has been set to America/Toronto in AbstractTestCase.php |
||
151 | $this->assertTrue(Date::createFromDate(2012, 1, 1, 'America/Toronto')->getLocal()); |
||
152 | $this->assertTrue(Date::createFromDate(2012, 1, 1, 'America/New_York')->getLocal()); |
||
153 | } |
||
154 | |||
155 | public function testGetLocalFalse() |
||
156 | { |
||
157 | $this->assertFalse(Date::createFromDate(2012, 7, 1, 'UTC')->getLocal()); |
||
158 | $this->assertFalse(Date::createFromDate(2012, 7, 1, 'Europe/London')->getLocal()); |
||
159 | } |
||
160 | |||
161 | public function testGetUtcFalse() |
||
162 | { |
||
163 | $this->assertFalse(Date::createFromDate(2013, 1, 1, 'America/Toronto')->isUtc()); |
||
164 | $this->assertFalse(Date::createFromDate(2013, 1, 1, 'Europe/Paris')->isUtc()); |
||
165 | } |
||
166 | |||
167 | public function testGetUtcTrue() |
||
168 | { |
||
169 | $this->assertTrue(Date::createFromDate(2013, 1, 1, 'Atlantic/Reykjavik')->isUtc()); |
||
170 | $this->assertTrue(Date::createFromDate(2013, 1, 1, 'Europe/Lisbon')->isUtc()); |
||
171 | $this->assertTrue(Date::createFromDate(2013, 1, 1, 'Africa/Casablanca')->isUtc()); |
||
172 | $this->assertTrue(Date::createFromDate(2013, 1, 1, 'Africa/Dakar')->isUtc()); |
||
173 | $this->assertTrue(Date::createFromDate(2013, 1, 1, 'Europe/Dublin')->isUtc()); |
||
174 | $this->assertTrue(Date::createFromDate(2013, 1, 1, 'Europe/London')->isUtc()); |
||
175 | $this->assertTrue(Date::createFromDate(2013, 1, 1, 'UTC')->isUtc()); |
||
176 | $this->assertTrue(Date::createFromDate(2013, 1, 1, 'GMT')->isUtc()); |
||
177 | } |
||
178 | |||
179 | public function testGetDstFalse() |
||
180 | { |
||
181 | $this->assertFalse(Date::createFromDate(2012, 1, 1, 'America/Toronto')->getDst()); |
||
182 | } |
||
183 | |||
184 | public function testGetDstTrue() |
||
185 | { |
||
186 | $this->assertTrue(Date::createFromDate(2012, 7, 1, 'America/Toronto')->getDst()); |
||
187 | } |
||
188 | |||
189 | public function testOffsetForTorontoWithDST() |
||
190 | { |
||
191 | $this->assertSame(-18000, Date::createFromDate(2012, 1, 1, 'America/Toronto')->getOffset()); |
||
192 | } |
||
193 | |||
194 | public function testOffsetForTorontoNoDST() |
||
195 | { |
||
196 | $this->assertSame(-14400, Date::createFromDate(2012, 6, 1, 'America/Toronto')->getOffset()); |
||
197 | } |
||
198 | |||
199 | public function testOffsetForGMT() |
||
200 | { |
||
201 | $this->assertSame(0, Date::createFromDate(2012, 6, 1, 'GMT')->getOffset()); |
||
202 | } |
||
203 | |||
204 | public function testOffsetHoursForTorontoWithDST() |
||
205 | { |
||
206 | $this->assertSame(-5, Date::createFromDate(2012, 1, 1, 'America/Toronto')->getOffsetHours()); |
||
207 | } |
||
208 | |||
209 | public function testOffsetHoursForTorontoNoDST() |
||
210 | { |
||
211 | $this->assertSame(-4, Date::createFromDate(2012, 6, 1, 'America/Toronto')->getOffsetHours()); |
||
212 | } |
||
213 | |||
214 | public function testOffsetHoursForGMT() |
||
215 | { |
||
216 | $this->assertSame(0, Date::createFromDate(2012, 6, 1, 'GMT')->getOffsetHours()); |
||
217 | } |
||
218 | |||
219 | public function testIsLeapYearTrue() |
||
220 | { |
||
221 | $this->assertTrue(Date::createFromDate(2012, 1, 1)->isLeapYear()); |
||
222 | } |
||
223 | |||
224 | public function testIsLeapYearFalse() |
||
225 | { |
||
226 | $this->assertFalse(Date::createFromDate(2011, 1, 1)->isLeapYear()); |
||
227 | } |
||
228 | |||
229 | public function testWeekOfMonth() |
||
230 | { |
||
231 | $this->assertSame(5, Date::createFromDate(2012, 9, 30)->getWeekOfMonth()); |
||
232 | $this->assertSame(4, Date::createFromDate(2012, 9, 28)->getWeekOfMonth()); |
||
233 | $this->assertSame(3, Date::createFromDate(2012, 9, 20)->getWeekOfMonth()); |
||
234 | $this->assertSame(2, Date::createFromDate(2012, 9, 8)->getWeekOfMonth()); |
||
235 | $this->assertSame(1, Date::createFromDate(2012, 9, 1)->getWeekOfMonth()); |
||
236 | } |
||
237 | |||
238 | public function testWeekOfYearFirstWeek() |
||
239 | { |
||
240 | $this->assertSame(52, Date::createFromDate(2012, 1, 1)->getWeekOfYear()); |
||
241 | $this->assertSame(1, Date::createFromDate(2012, 1, 2)->getWeekOfYear()); |
||
242 | } |
||
243 | |||
244 | public function testWeekOfYearLastWeek() |
||
245 | { |
||
246 | $this->assertSame(52, Date::createFromDate(2012, 12, 30)->getWeekOfYear()); |
||
247 | $this->assertSame(1, Date::createFromDate(2012, 12, 31)->getWeekOfYear()); |
||
248 | } |
||
249 | |||
250 | View Code Duplication | public function testGetTimezone() |
|
0 ignored issues
–
show
|
|||
251 | { |
||
252 | $dt = Date::createFromDate(2000, 1, 1, 'America/Toronto'); |
||
253 | $this->assertSame('America/Toronto', $dt->getTimezone()->getName()); |
||
254 | |||
255 | $dt = Date::createFromDate(2000, 1, 1, -5); |
||
256 | $this->assertSame('-05:00', $dt->getTimezone()->getName()); |
||
257 | } |
||
258 | |||
259 | View Code Duplication | public function testGetTimezoneName() |
|
0 ignored issues
–
show
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. ![]() |
|||
260 | { |
||
261 | $dt = Date::createFromDate(2000, 1, 1, 'America/Toronto'); |
||
262 | $this->assertSame('America/Toronto', $dt->getTimezoneName()); |
||
263 | |||
264 | $dt = Date::createFromDate(2000, 1, 1, -5); |
||
265 | $this->assertSame('-05:00', $dt->getTimezoneName()); |
||
266 | } |
||
267 | } |
||
268 |
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.