Passed
Push — master ( 71ac2a...8d79cc )
by Dmitriy
02:35
created

ExceptionCollectorTest::checkCollectedData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 18
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 23
rs 9.6666
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, new Exception('previous', 666));
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(2, $data);
34
        foreach ($data as $exception) {
35
            $this->assertArrayHasKey('class', $exception);
36
            $this->assertArrayHasKey('message', $exception);
37
            $this->assertArrayHasKey('file', $exception);
38
            $this->assertArrayHasKey('line', $exception);
39
            $this->assertArrayHasKey('code', $exception);
40
            $this->assertArrayHasKey('trace', $exception);
41
            $this->assertArrayHasKey('traceAsString', $exception);
42
        }
43
44
        $exception = $data[0];
45
        $this->assertEquals(Exception::class, $exception['class']);
46
        $this->assertEquals('test', $exception['message']);
47
        $this->assertEquals(777, $exception['code']);
48
49
        $exception = $data[1];
50
        $this->assertEquals(Exception::class, $exception['class']);
51
        $this->assertEquals('previous', $exception['message']);
52
        $this->assertEquals(666, $exception['code']);
53
    }
54
55
    protected function checkSummaryData(array $data): void
56
    {
57
        parent::checkSummaryData($data);
58
        $this->assertCount(1, $data);
59
        $this->assertArrayHasKey('exception', $data);
60
61
        $exception = $data['exception'];
62
        $this->assertArrayHasKey('class', $exception);
63
        $this->assertArrayHasKey('message', $exception);
64
        $this->assertArrayHasKey('file', $exception);
65
        $this->assertArrayHasKey('line', $exception);
66
        $this->assertArrayHasKey('code', $exception);
67
68
        $this->assertEquals(Exception::class, $exception['class']);
69
        $this->assertEquals('test', $exception['message']);
70
        $this->assertEquals(777, $exception['code']);
71
    }
72
73
    public function testNoExceptionCollected()
74
    {
75
        $collector = new ExceptionCollector(new TimelineCollector());
76
77
        $collector->startup();
78
79
        $this->assertEquals([], $collector->getCollected());
80
    }
81
}
82