Passed
Pull Request — master (#227)
by Dmitriy
04:30 queued 01:40
created

ExceptionCollectorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
c 1
b 0
f 0
dl 0
loc 51
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A collectTestData() 0 4 1
A checkCollectedData() 0 17 1
A getCollector() 0 3 1
A checkSummaryData() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Tests\Unit\Collector;
6
7
use Exception;
8
use Yiisoft\ErrorHandler\Event\ApplicationError;
9
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
10
use Yiisoft\Yii\Debug\Collector\ExceptionCollector;
11
use Yiisoft\Yii\Debug\Collector\TimelineCollector;
12
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;
13
14
final class ExceptionCollectorTest extends AbstractCollectorTestCase
15
{
16
    /**
17
     * @param CollectorInterface|ExceptionCollector $collector
18
     */
19
    protected function collectTestData(CollectorInterface $collector): void
20
    {
21
        $exception = new Exception('test', 777);
22
        $collector->collect(new ApplicationError($exception));
0 ignored issues
show
Bug introduced by
The method collect() does not exist on Yiisoft\Yii\Debug\Collector\CollectorInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Yiisoft\Yii\Debug\Collec...mmaryCollectorInterface or Yiisoft\Yii\Debug\Tests\...\Support\DummyCollector. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        $collector->/** @scrutinizer ignore-call */ 
23
                    collect(new ApplicationError($exception));
Loading history...
23
    }
24
25
    protected function getCollector(): CollectorInterface
26
    {
27
        return new ExceptionCollector(new TimelineCollector());
28
    }
29
30
    protected function checkCollectedData(array $data): void
31
    {
32
        parent::checkCollectedData($data);
33
        $this->assertCount(1, $data);
34
        $exception = $data[0];
35
36
        $this->assertArrayHasKey('class', $exception);
37
        $this->assertArrayHasKey('message', $exception);
38
        $this->assertArrayHasKey('file', $exception);
39
        $this->assertArrayHasKey('line', $exception);
40
        $this->assertArrayHasKey('code', $exception);
41
        $this->assertArrayHasKey('trace', $exception);
42
        $this->assertArrayHasKey('traceAsString', $exception);
43
44
        $this->assertEquals(Exception::class, $exception['class']);
45
        $this->assertEquals('test', $exception['message']);
46
        $this->assertEquals(777, $exception['code']);
47
    }
48
49
    protected function checkSummaryData(array $data): void
50
    {
51
        parent::checkSummaryData($data);
52
        $this->assertCount(1, $data);
53
        $this->assertArrayHasKey('exception', $data);
54
55
        $exception = $data['exception'];
56
        $this->assertArrayHasKey('class', $exception);
57
        $this->assertArrayHasKey('message', $exception);
58
        $this->assertArrayHasKey('file', $exception);
59
        $this->assertArrayHasKey('line', $exception);
60
        $this->assertArrayHasKey('code', $exception);
61
62
        $this->assertEquals(Exception::class, $exception['class']);
63
        $this->assertEquals('test', $exception['message']);
64
        $this->assertEquals(777, $exception['code']);
65
    }
66
}
67