|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LeKoala\DebugBar\Test\Collector; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Core\Config\Config; |
|
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
7
|
|
|
use LeKoala\DebugBar\Collector\TimeDataCollector; |
|
8
|
|
|
use LeKoala\DebugBar\DebugBar; |
|
9
|
|
|
|
|
10
|
|
|
class TimeDataCollectorTest extends SapphireTest |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var DebugBarTimeDataCollector |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $collector; |
|
16
|
|
|
|
|
17
|
|
|
public function setUp() |
|
18
|
|
|
{ |
|
19
|
|
|
parent::setUp(); |
|
20
|
|
|
$this->collector = new TimeDataCollector; |
|
|
|
|
|
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function testCollectorTooltip() |
|
24
|
|
|
{ |
|
25
|
|
|
$result = $this->collector->getWidgets(); |
|
26
|
|
|
$this->assertContains('Request duration', $result['time']['tooltip']); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testWarning() |
|
30
|
|
|
{ |
|
31
|
|
|
// Deliberately low threshold |
|
32
|
|
|
Config::modify()->set(DebugBar::class, 'warn_request_time_seconds', '0.00001'); |
|
33
|
|
|
$result = $this->collector->getWidgets(); |
|
34
|
|
|
$this->assertSame('danger', $result['time']['warn']); |
|
35
|
|
|
$this->assertContains('>', $result['time']['tooltip']); |
|
36
|
|
|
|
|
37
|
|
|
// Deliberately high threshold and low ratio |
|
38
|
|
|
Config::modify()->set(DebugBar::class, 'warn_request_time_seconds', '100'); |
|
39
|
|
|
Config::modify()->set(DebugBar::class, 'warn_warning_ratio', '0.000000001'); |
|
40
|
|
|
$result = $this->collector->getWidgets(); |
|
41
|
|
|
$this->assertSame('warning', $result['time']['warn']); |
|
42
|
|
|
$this->assertContains('>', $result['time']['tooltip']); |
|
43
|
|
|
|
|
44
|
|
|
// Deliberately high threshold and high ratio |
|
45
|
|
|
Config::modify()->set(DebugBar::class, 'warn_request_time_seconds', '100'); |
|
46
|
|
|
Config::modify()->set(DebugBar::class, 'warn_warning_ratio', '1'); |
|
47
|
|
|
$result = $this->collector->getWidgets(); |
|
48
|
|
|
$this->assertSame('ok', $result['time']['warn']); |
|
49
|
|
|
$this->assertContains('<', $result['time']['tooltip']); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testWarningCanBeDisabled() |
|
53
|
|
|
{ |
|
54
|
|
|
Config::modify()->set(DebugBar::class, 'warn_request_time_seconds', false); |
|
55
|
|
|
$result = $this->collector->getWidgets(); |
|
56
|
|
|
$this->assertArrayNotHasKey('warn', $result['time']); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..