|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class DebugBarTimeDataCollectorTest extends SapphireTest |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
/** |
|
6
|
|
|
* @var DebugBarTimeDataCollector |
|
7
|
|
|
*/ |
|
8
|
|
|
protected $collector; |
|
9
|
|
|
|
|
10
|
|
|
public function setUp() |
|
11
|
|
|
{ |
|
12
|
|
|
parent::setUp(); |
|
13
|
|
|
$this->collector = new DebugBarTimeDataCollector; |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function testCollectorTooltip() |
|
17
|
|
|
{ |
|
18
|
|
|
$result = $this->collector->getWidgets(); |
|
19
|
|
|
$this->assertContains('Request duration', $result['time']['tooltip']); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testWarning() |
|
23
|
|
|
{ |
|
24
|
|
|
// Deliberately low threshold |
|
25
|
|
|
Config::inst()->update('DebugBar', 'warn_request_time_seconds', '0.00001'); |
|
26
|
|
|
$result = $this->collector->getWidgets(); |
|
27
|
|
|
$this->assertSame('danger', $result['time']['warn']); |
|
|
|
|
|
|
28
|
|
|
$this->assertContains('>', $result['time']['tooltip']); |
|
29
|
|
|
|
|
30
|
|
|
// Deliberately high threshold and low ratio |
|
31
|
|
|
Config::inst()->update('DebugBar', 'warn_request_time_seconds', '100'); |
|
32
|
|
|
Config::inst()->update('DebugBar', 'warn_warning_ratio', '0.000000001'); |
|
33
|
|
|
$result = $this->collector->getWidgets(); |
|
34
|
|
|
$this->assertSame('warning', $result['time']['warn']); |
|
|
|
|
|
|
35
|
|
|
$this->assertContains('>', $result['time']['tooltip']); |
|
36
|
|
|
|
|
37
|
|
|
// Deliberately high threshold and high ratio |
|
38
|
|
|
Config::inst()->update('DebugBar', 'warn_request_time_seconds', '100'); |
|
39
|
|
|
Config::inst()->update('DebugBar', 'warn_warning_ratio', '1'); |
|
40
|
|
|
$result = $this->collector->getWidgets(); |
|
41
|
|
|
$this->assertSame('ok', $result['time']['warn']); |
|
|
|
|
|
|
42
|
|
|
$this->assertContains('<', $result['time']['tooltip']); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testWarningCanBeDisabled() |
|
46
|
|
|
{ |
|
47
|
|
|
Config::inst()->update('DebugBar', 'warn_request_time_seconds', false); |
|
48
|
|
|
$result = $this->collector->getWidgets(); |
|
49
|
|
|
$this->assertArrayNotHasKey('warn', $result['time']); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.