1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Unit\Scheduler\Schedule;
use Exception;
use Piwik\Scheduler\Schedule\Hourly;
/**
* @group Scheduler
*/
class HourlyTest extends \PHPUnit\Framework\TestCase
{
private static $_JANUARY_01_1971_09_00_00;
private static $_JANUARY_01_1971_09_10_00;
private static $_JANUARY_01_1971_10_00_00;
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
self::$_JANUARY_01_1971_09_00_00 = mktime(9, 00, 00, 1, 1, 1971);
self::$_JANUARY_01_1971_09_10_00 = mktime(9, 10, 00, 1, 1, 1971);
self::$_JANUARY_01_1971_10_00_00 = mktime(10, 00, 00, 1, 1, 1971);
}
/**
* Tests forbidden call to setHour on Hourly
* @group Core
*/
public function testSetHourScheduledTimeHourly()
{
$this->expectException(Exception::class);
$hourlySchedule = new Hourly();
$hourlySchedule->setHour(0);
}
/**
* Tests forbidden call to setDay on Hourly
* @group Core
*/
public function testSetDayScheduledTimeHourly()
{
$this->expectException(Exception::class);
$hourlySchedule = new Hourly();
$hourlySchedule->setDay(1);
}
/**
* Tests getRescheduledTime on Hourly
* @group Core
*/
public function testGetRescheduledTimeHourly()
{
/*
* Test 1
*
* Context :
* - getRescheduledTime called Friday January 1 1971 09:00:00 GMT
*
* Expected :
* getRescheduledTime returns Friday January 1 1971 10:00:00 GMT
*/
$mock = $this->createPartialMock('Piwik\Scheduler\Schedule\Hourly', array('getTime'));
$mock->expects($this->any())
->method('getTime')
->will($this->returnValue(self::$_JANUARY_01_1971_09_00_00));
$this->assertEquals(self::$_JANUARY_01_1971_10_00_00, $mock->getRescheduledTime());
/*
* Test 2
*
* Context :
* - getRescheduledTime called Friday January 1 1971 09:10:00 GMT
*
* Expected :
* getRescheduledTime returns Friday January 1 1971 10:00:00 GMT
*/
$mock = $this->createPartialMock('Piwik\Scheduler\Schedule\Hourly', array('getTime'));
$mock->expects($this->any())
->method('getTime')
->will($this->returnValue(self::$_JANUARY_01_1971_09_10_00));
$this->assertEquals(self::$_JANUARY_01_1971_10_00_00, $mock->getRescheduledTime());
}
}
|