Completed
Pull Request — master (#47)
by Robbie
01:32
created

TimeDataCollectorTest::testCollectorTooltip()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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;
0 ignored issues
show
Documentation Bug introduced by
It seems like new \LeKoala\DebugBar\Co...tor\TimeDataCollector() of type object<LeKoala\DebugBar\...ctor\TimeDataCollector> is incompatible with the declared type object<LeKoala\DebugBar\...ugBarTimeDataCollector> of property $collector.

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..

Loading history...
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 high ratio
38
        Config::modify()->set(DebugBar::class, 'warn_request_time_seconds', '100');
39
        Config::modify()->set(DebugBar::class, '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::modify()->set(DebugBar::class, 'warn_request_time_seconds', false);
48
        $result = $this->collector->getWidgets();
49
        $this->assertArrayNotHasKey('warn', $result['time']);
50
    }
51
}
52