|
1
|
|
|
<?php |
|
2
|
|
|
namespace PortlandLabs\Slackbot\Slack; |
|
3
|
|
|
|
|
4
|
|
|
use Carbon\Carbon; |
|
5
|
|
|
use Mockery as M; |
|
6
|
|
|
use PortlandLabs\Slackbot\Bot; |
|
7
|
|
|
use PortlandLabs\Slackbot\TestCase; |
|
8
|
|
|
|
|
9
|
|
|
class BotTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @dataProvider uptimeDates |
|
14
|
|
|
*/ |
|
15
|
|
|
public function testUptimeString($expected, \DateTime $connected, \DateTime $now) |
|
16
|
|
|
{ |
|
17
|
|
|
$property = (new \ReflectionClass(Bot::class))->getProperty('connected'); |
|
18
|
|
|
$property->setAccessible(true); |
|
19
|
|
|
|
|
20
|
|
|
/** @var Bot|M\MockInterface $bot */ |
|
21
|
|
|
$bot = M::mock(Bot::class)->makePartial(); |
|
22
|
|
|
$property->setValue($bot, $connected); |
|
23
|
|
|
|
|
24
|
|
|
$this->assertEquals($expected, $bot->getUptime($now)); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function uptimeDates() |
|
28
|
|
|
{ |
|
29
|
|
|
$time = new Carbon(); |
|
30
|
|
|
return [ |
|
31
|
|
|
// Never 0 |
|
32
|
|
|
['1 second', $time, $time], |
|
33
|
|
|
['2 days', $time->copy()->subDays(2), $time], |
|
34
|
|
|
['1 week', $time->copy()->subDays(7), $time], |
|
35
|
|
|
['2 days and 5 hours', $time->copy()->subDays(2)->subHours(5), $time], |
|
36
|
|
|
['2 years 5 hours and 2 seconds', $time->copy()->subYear(2)->subHours(5)->subSeconds(2), $time], |
|
37
|
|
|
[ |
|
38
|
|
|
// Make sure it only shows 6 segments |
|
39
|
|
|
'123 years 4 months 3 weeks 3 days 15 hours and 10 minutes', |
|
40
|
|
|
$time->copy()->subYear(123)->subMonth(4)->subDays(25)->subHours(15)->subMinutes(10)->subSeconds(22), |
|
41
|
|
|
$time |
|
42
|
|
|
], |
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
} |