| 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 |
||||
|
0 ignored issues
–
show
|
|||||
| 14 | */ |
||||
| 15 | protected $collector; |
||||
| 16 | |||||
| 17 | public function setUp(): void |
||||
| 18 | { |
||||
| 19 | parent::setUp(); |
||||
| 20 | $this->collector = new TimeDataCollector(microtime(true)); |
||||
|
0 ignored issues
–
show
It seems like
new LeKoala\DebugBar\Col...lector(microtime(true)) of type LeKoala\DebugBar\Collector\TimeDataCollector is incompatible with the declared type LeKoala\DebugBar\Test\Co...bugBarTimeDataCollector 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...
It seems like
microtime(true) can also be of type string; however, parameter $requestStartTime of LeKoala\DebugBar\Collect...ollector::__construct() does only seem to accept double, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 21 | } |
||||
| 22 | |||||
| 23 | public function tearDown(): void |
||||
| 24 | { |
||||
| 25 | DebugBar::clearDebugBar(); |
||||
| 26 | $this->collector = null; |
||||
| 27 | |||||
| 28 | parent::tearDown(); |
||||
| 29 | } |
||||
| 30 | |||||
| 31 | public function testCollectorTooltip() |
||||
| 32 | { |
||||
| 33 | $result = $this->collector->getWidgets(); |
||||
| 34 | $this->assertStringContainsString('Request duration', $result['time']['tooltip']); |
||||
| 35 | } |
||||
| 36 | |||||
| 37 | /** |
||||
| 38 | * Deliberately low threshold - should return a danger result |
||||
| 39 | */ |
||||
| 40 | public function testDangerOnVerySlowRequest() |
||||
| 41 | { |
||||
| 42 | Config::modify()->set(DebugBar::class, 'warn_request_time_seconds', '0.00001'); |
||||
| 43 | $result = $this->collector->getWidgets(); |
||||
| 44 | $this->assertSame('danger', $result['time']['warn']); |
||||
| 45 | $this->assertStringContainsString('>', $result['time']['tooltip']); |
||||
| 46 | } |
||||
| 47 | |||||
| 48 | /** |
||||
| 49 | * Deliberately high threshold and low ratio - should return a warning result |
||||
| 50 | */ |
||||
| 51 | public function testWarningOnSlowRequest() |
||||
| 52 | { |
||||
| 53 | Config::modify()->set(DebugBar::class, 'warn_request_time_seconds', '100'); |
||||
| 54 | Config::modify()->set(DebugBar::class, 'warn_warning_ratio', '0.000000001'); |
||||
| 55 | $result = $this->collector->getWidgets(); |
||||
| 56 | $this->assertSame('warning', $result['time']['warn']); |
||||
| 57 | $this->assertStringContainsString('>', $result['time']['tooltip']); |
||||
| 58 | } |
||||
| 59 | |||||
| 60 | /** |
||||
| 61 | * Deliberately high threshold and high ratio - should return an "ok" result |
||||
| 62 | */ |
||||
| 63 | public function testOkOnNormalRequest() |
||||
| 64 | { |
||||
| 65 | Config::modify()->set(DebugBar::class, 'warn_request_time_seconds', '100'); |
||||
| 66 | Config::modify()->set(DebugBar::class, 'warn_warning_ratio', '1'); |
||||
| 67 | $result = $this->collector->getWidgets(); |
||||
| 68 | $this->assertSame('ok', $result['time']['warn']); |
||||
| 69 | $this->assertStringContainsString('<', $result['time']['tooltip']); |
||||
| 70 | } |
||||
| 71 | |||||
| 72 | public function testWarningCanBeDisabled() |
||||
| 73 | { |
||||
| 74 | Config::modify()->set(DebugBar::class, 'warn_request_time_seconds', false); |
||||
| 75 | $result = $this->collector->getWidgets(); |
||||
| 76 | $this->assertArrayNotHasKey('warn', $result['time']); |
||||
| 77 | } |
||||
| 78 | } |
||||
| 79 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths