|
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)); |
|
|
|
|
|
|
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
|
|
|
|