-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFormattedErrorTest.php
More file actions
77 lines (66 loc) · 2.33 KB
/
FormattedErrorTest.php
File metadata and controls
77 lines (66 loc) · 2.33 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
<?php
declare(strict_types=1);
namespace SimPod\GraphQLUtils\Tests\Error;
use Exception;
use GraphQL\Error\DebugFlag;
use GraphQL\Error\Error;
use PHPUnit\Framework\TestCase;
use SimPod\GraphQLUtils\Error\FormattedError;
final class FormattedErrorTest extends TestCase
{
public function testNonDebug(): void
{
$exception = new Exception('When smashing sun-dried shrimps, be sure they are room temperature.');
self::assertSame(
['message' => 'Internal server error'],
FormattedError::createFromException($exception),
);
}
public function testDebug(): void
{
$exception = new Exception('When smashing sun-dried shrimps, be sure they are room temperature.');
self::assertSame(
[
'message' => 'Internal server error',
// phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
'extensions' => ['debugMessage' => 'When smashing sun-dried shrimps, be sure they are room temperature.'],
],
FormattedError::createFromException($exception, DebugFlag::INCLUDE_DEBUG_MESSAGE),
);
}
public function testInternalMessageModification(): void
{
$exception = new Exception('When smashing sun-dried shrimps, be sure they are room temperature.');
self::assertSame(
['message' => 'Try grilling smoothie jumbled with salad cream, decorateed with green curry.'],
FormattedError::createFromException(
$exception,
DebugFlag::NONE,
'Try grilling smoothie jumbled with salad cream, decorateed with green curry.',
),
);
}
public function testGraphQLCustomError(): void
{
$error = new class extends Error {
public function __construct()
{
parent::__construct(
'Error Message',
null,
null,
[],
null,
new CustomError(''),
);
}
};
self::assertSame(
[
'message' => 'Error Message',
'extensions' => ['type' => 'CUSTOM_ERROR'],
],
FormattedError::createFromException($error, DebugFlag::NONE),
);
}
}