Completed
Push — master ( 1df032...2ea341 )
by Robbie
11s queued 11s
created

TimeDataCollectorTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 26.23 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 4
dl 16
loc 61
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testCollectorTooltip() 0 5 1
A testDangerOnVerySlowRequest() 0 7 1
A testWarningOnSlowRequest() 8 8 1
A testOkOnNormalRequest() 8 8 1
A testWarningCanBeDisabled() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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(microtime(true));
0 ignored issues
show
Documentation Bug introduced by
It seems like new \LeKoala\DebugBar\Co...lector(microtime(true)) 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
    /**
30
     * Deliberately low threshold - should return a danger result
31
     */
32
    public function testDangerOnVerySlowRequest()
33
    {
34
        Config::modify()->set(DebugBar::class, 'warn_request_time_seconds', '0.00001');
35
        $result = $this->collector->getWidgets();
36
        $this->assertSame('danger', $result['time']['warn']);
37
        $this->assertContains('>', $result['time']['tooltip']);
38
    }
39
40
    /**
41
     * Deliberately high threshold and low ratio - should return a warning result
42
     */
43 View Code Duplication
    public function testWarningOnSlowRequest()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45
        Config::modify()->set(DebugBar::class, 'warn_request_time_seconds', '100');
46
        Config::modify()->set(DebugBar::class, 'warn_warning_ratio', '0.000000001');
47
        $result = $this->collector->getWidgets();
48
        $this->assertSame('warning', $result['time']['warn']);
49
        $this->assertContains('>', $result['time']['tooltip']);
50
    }
51
52
    /**
53
     * Deliberately high threshold and high ratio - should return an "ok" result
54
     */
55 View Code Duplication
    public function testOkOnNormalRequest()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        Config::modify()->set(DebugBar::class, 'warn_request_time_seconds', '100');
58
        Config::modify()->set(DebugBar::class, 'warn_warning_ratio', '1');
59
        $result = $this->collector->getWidgets();
60
        $this->assertSame('ok', $result['time']['warn']);
61
        $this->assertContains('<', $result['time']['tooltip']);
62
    }
63
64
    public function testWarningCanBeDisabled()
65
    {
66
        Config::modify()->set(DebugBar::class, 'warn_request_time_seconds', false);
67
        $result = $this->collector->getWidgets();
68
        $this->assertArrayNotHasKey('warn', $result['time']);
69
    }
70
}
71