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

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
class DebugBarTimeDataCollectorTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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']);
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DebugBarTimeDataCollectorTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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']);
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DebugBarTimeDataCollectorTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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']);
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DebugBarTimeDataCollectorTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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']);
0 ignored issues
show
Bug introduced by
The method assertArrayNotHasKey() does not seem to exist on object<DebugBarTimeDataCollectorTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
    }
51
}
52