-
-
Notifications
You must be signed in to change notification settings - Fork 575
Expand file tree
/
Copy pathPrintErrorTest.php
More file actions
106 lines (91 loc) · 2.46 KB
/
PrintErrorTest.php
File metadata and controls
106 lines (91 loc) · 2.46 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
95
96
97
98
99
100
101
102
103
104
105
106
<?php declare(strict_types=1);
namespace GraphQL\Tests\Error;
use GraphQL\Error\Error;
use GraphQL\Error\FormattedError;
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
use GraphQL\Language\Parser;
use GraphQL\Language\Source;
use GraphQL\Language\SourceLocation;
use PHPUnit\Framework\TestCase;
final class PrintErrorTest extends TestCase
{
/**
* @see it('prints an line numbers with correct padding')
*/
public function testPrintsAnLineNumbersWithCorrectPadding(): void
{
$singleDigit = new Error(
'Single digit line number with no padding',
null,
new Source('*', 'Test', new SourceLocation(9, 1)),
[0]
);
$actual = FormattedError::printError($singleDigit);
$expected = 'Single digit line number with no padding
Test (9:1)
9: *
^
';
self::assertEquals($expected, $actual);
$doubleDigit = new Error(
'Left padded first line number',
null,
new Source("*\n", 'Test', new SourceLocation(9, 1)),
[0]
);
$actual = FormattedError::printError($doubleDigit);
$expected = 'Left padded first line number
Test (9:1)
9: *
^
10:
';
self::assertEquals($expected, $actual);
}
/**
* @see it('prints an error with nodes from different sources')
*/
public function testPrintsAnErrorWithNodesFromDifferentSources(): void
{
$sourceA = Parser::parse(new Source(
'type Foo {
field: String
}',
'SourceA'
));
/** @var ObjectTypeDefinitionNode $objectDefinitionA */
$objectDefinitionA = $sourceA->definitions->get(0);
$fieldTypeA = $objectDefinitionA->fields->get(0)->type;
$sourceB = Parser::parse(new Source(
'type Foo {
field: Int
}',
'SourceB'
));
/** @var ObjectTypeDefinitionNode $objectDefinitionB */
$objectDefinitionB = $sourceB->definitions->get(0);
$fieldTypeB = $objectDefinitionB->fields->get(0)->type;
$error = new Error(
'Example error with two nodes',
[
$fieldTypeA,
$fieldTypeB,
]
);
self::assertEquals(
'Example error with two nodes
SourceA (2:10)
1: type Foo {
2: field: String
^
3: }
SourceB (2:10)
1: type Foo {
2: field: Int
^
3: }
',
FormattedError::printError($error)
);
}
}