-
-
Notifications
You must be signed in to change notification settings - Fork 471
Expand file tree
/
Copy pathCodeLocationResolverTest.php
More file actions
94 lines (79 loc) · 2.87 KB
/
CodeLocationResolverTest.php
File metadata and controls
94 lines (79 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
declare(strict_types=1);
namespace Sentry\Tests;
use PHPUnit\Framework\TestCase;
use Sentry\Frame;
use Sentry\Options;
use Sentry\Serializer\RepresentationSerializer;
use Sentry\Util\CodeLocationResolver;
final class CodeLocationResolverTest extends TestCase
{
public function testFindFirstInAppFrameForBacktrace(): void
{
$expectedLine = 123;
$resolver = $this->createResolver([
'prefixes' => [],
]);
$frame = $resolver->findFirstInAppFrameForBacktrace($this->createQueryBacktrace($expectedLine));
$this->assertNotNull($frame);
$this->assertSame(__FILE__, $frame->getFile());
$this->assertSame($expectedLine, $frame->getLine());
$this->assertSame('App\\Repository\\UserRepository::findActiveUsers', $frame->getFunctionName());
}
public function testResolveFromBacktraceReturnsCodeLocationMetadata(): void
{
$expectedLine = 321;
$resolver = $this->createResolver([
'prefixes' => [\dirname(__DIR__)],
]);
$location = $resolver->resolveFromBacktrace($this->createQueryBacktrace($expectedLine));
$this->assertNotNull($location);
$this->assertSame(\DIRECTORY_SEPARATOR . 'tests' . \DIRECTORY_SEPARATOR . 'CodeLocationResolverTest.php', $location['code.filepath']);
$this->assertSame('App\\Repository\\UserRepository::findActiveUsers', $location['code.function']);
$this->assertSame($expectedLine, $location['code.lineno']);
}
public function testResolveFromBacktraceReturnsNullWithoutInAppFrame(): void
{
$resolver = $this->createResolver();
$location = $resolver->resolveFromBacktrace([
[
'file' => Frame::INTERNAL_FRAME_FILENAME,
'line' => 0,
'function' => 'internal',
],
[
'class' => 'Doctrine\\DBAL\\Connection',
'function' => 'executeQuery',
],
]);
$this->assertNull($location);
}
private function createResolver(array $options = []): CodeLocationResolver
{
$options = new Options($options);
return new CodeLocationResolver($options, new RepresentationSerializer($options));
}
/**
* @return array<int, array<string, mixed>>
*/
private function createQueryBacktrace(int $line): array
{
return [
[
'file' => Frame::INTERNAL_FRAME_FILENAME,
'line' => 0,
'function' => 'internal',
],
[
'file' => __FILE__,
'line' => $line,
'class' => 'Doctrine\\DBAL\\Connection',
'function' => 'executeQuery',
],
[
'class' => 'App\\Repository\\UserRepository',
'function' => 'findActiveUsers',
],
];
}
}