|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the php-utilities package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Marc Aschmann <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace Asm\Tests\Timer; |
|
11
|
|
|
|
|
12
|
|
|
use Asm\Config\Config; |
|
13
|
|
|
use Asm\Test\TestData; |
|
14
|
|
|
use Asm\Timer\Timer; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class TimerTest |
|
18
|
|
|
* |
|
19
|
|
|
* @package Asm\Tests\Timer |
|
20
|
|
|
* @author marc aschmann <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class TimerTest extends \PHPUnit_Framework_TestCase |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @covers \Asm\Timer\Timer::__construct |
|
26
|
|
|
* @return Timer |
|
27
|
|
|
* @throws \ErrorException |
|
28
|
|
|
*/ |
|
29
|
|
|
public function testConstruct() |
|
30
|
|
|
{ |
|
31
|
|
|
$config = Config::factory( |
|
32
|
|
|
[ |
|
33
|
|
|
'file' => TestData::getYamlTimerConfigFile(), |
|
34
|
|
|
'filecheck' => false, |
|
35
|
|
|
], |
|
36
|
|
|
'ConfigTimer' |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertInstanceOf('Asm\Config\ConfigTimer', $config); |
|
40
|
|
|
$timer = new Timer($config); |
|
|
|
|
|
|
41
|
|
|
$this->assertInstanceOf('Asm\Timer\Timer', $timer); |
|
42
|
|
|
|
|
43
|
|
|
return $timer; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @depends testConstruct |
|
48
|
|
|
* @covers \Asm\Timer\Timer::isTimerActive |
|
49
|
|
|
* @covers \Asm\Timer\Timer::checkDate |
|
50
|
|
|
* @covers \Asm\Timer\Timer::checkIntervals |
|
51
|
|
|
* @covers \Asm\Timer\Timer::checkDays |
|
52
|
|
|
* @covers \Asm\Timer\Timer::checkTime |
|
53
|
|
|
* @covers \Asm\Timer\Timer::checkHoliday |
|
54
|
|
|
* @covers \Asm\Timer\Timer::convertDate |
|
55
|
|
|
* @covers \Asm\Timer\Timer::flush |
|
56
|
|
|
* @param Timer $timer |
|
57
|
|
|
*/ |
|
58
|
|
|
public function testIsTimerActive(Timer $timer) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_1'))); |
|
61
|
|
|
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_2'))); |
|
62
|
|
|
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_3'))); |
|
63
|
|
|
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_3.1'))); |
|
64
|
|
|
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_4'))); |
|
65
|
|
|
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_4.1'))); |
|
66
|
|
|
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_5'))); |
|
67
|
|
|
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_6'))); |
|
68
|
|
|
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_7'))); |
|
69
|
|
|
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_7.1'))); |
|
70
|
|
|
$this->assertTrue(is_bool($timer->isTimerActive('general_shipping_promise'))); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @depends testConstruct |
|
75
|
|
|
* @covers \Asm\Timer\Timer::isHoliday |
|
76
|
|
|
* @covers \Asm\Timer\Timer::getHoliday |
|
77
|
|
|
* @covers \Asm\Timer\Timer::checkHoliday |
|
78
|
|
|
* @covers \Asm\Timer\Timer::convertDate |
|
79
|
|
|
* @param Timer $timer |
|
80
|
|
|
*/ |
|
81
|
|
|
public function testIsHoliday(Timer $timer) |
|
82
|
|
|
{ |
|
83
|
|
|
$currentYear = date('Y'); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertFalse($timer->isHoliday('2014-03-03 00:00:00'), 'failed to check non-holiday date'); |
|
86
|
|
|
$this->assertTrue($timer->isHoliday($currentYear . '-12-24 12:30:01'), 'failed to validate christmas'); |
|
87
|
|
|
$this->assertNotEmpty($timer->getHoliday()); |
|
88
|
|
|
|
|
89
|
|
|
$this->assertTrue(is_bool($timer->isHoliday()), 'failed to validate bool return'); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.