-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathStringLiteralFormatterTest.php
More file actions
127 lines (99 loc) · 4.68 KB
/
Copy pathStringLiteralFormatterTest.php
File metadata and controls
127 lines (99 loc) · 4.68 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
namespace GraphQL\Tests;
use GraphQL\Util\StringLiteralFormatter;
use PHPUnit\Framework\TestCase;
/**
* Class StringLiteralFormatterTest
*
* @package GraphQL\Tests
*/
class StringLiteralFormatterTest extends TestCase
{
/**
* @covers \GraphQL\Util\StringLiteralFormatter::formatValueForRHS
*/
public function testFormatForClassRHSValue()
{
// Null test
$nullString = StringLiteralFormatter::formatValueForRHS(null);
$this->assertEquals('null', $nullString);
// String tests
$emptyString = StringLiteralFormatter::formatValueForRHS('');
$this->assertEquals('""', $emptyString);
$formattedString = StringLiteralFormatter::formatValueForRHS('someString');
$this->assertEquals('"someString"', $formattedString);
$formattedString = StringLiteralFormatter::formatValueForRHS('"quotedString"');
$this->assertEquals('"\"quotedString\""', $formattedString);
$formattedString = StringLiteralFormatter::formatValueForRHS("\"quotedString\"");
$this->assertEquals('"\"quotedString\""', $formattedString);
$formattedString = StringLiteralFormatter::formatValueForRHS('<span class=\\"quotedStringEscaped\\" id="unescaped"></span>');
$this->assertEquals('"<span class=\\\\\"quotedStringEscaped\\\\\" id=\"unescaped\"></span>"', $formattedString);
$formattedString = StringLiteralFormatter::formatValueForRHS('\'singleQuotes\'');
$this->assertEquals('"\'singleQuotes\'"', $formattedString);
$formattedString = StringLiteralFormatter::formatValueForRHS("with \n newlines");
$this->assertEquals("\"\"\"with \n newlines\"\"\"", $formattedString);
$formattedString = StringLiteralFormatter::formatValueForRHS('$var');
$this->assertEquals('$var', $formattedString);
$formattedString = StringLiteralFormatter::formatValueForRHS('$400');
$this->assertEquals('"$400"', $formattedString);
// Integer tests
$integerString = StringLiteralFormatter::formatValueForRHS(25);
$this->assertEquals('25', $integerString);
// Float tests
$floatString = StringLiteralFormatter::formatValueForRHS(123.123);
$this->assertEquals('123.123', $floatString);
// Bool tests
$stringTrue = StringLiteralFormatter::formatValueForRHS(true);
$this->assertEquals('true', $stringTrue);
$stringFalse = StringLiteralFormatter::formatValueForRHS(false);
$this->assertEquals('false', $stringFalse);
}
/**
* @covers \GraphQL\Util\StringLiteralFormatter::formatArrayForGQLQuery
*/
public function testFormatArrayForGQLQuery()
{
$emptyArray = [];
$stringArray = StringLiteralFormatter::formatArrayForGQLQuery($emptyArray);
$this->assertEquals('[]', $stringArray);
$oneValueArray = [1];
$stringArray = StringLiteralFormatter::formatArrayForGQLQuery($oneValueArray);
$this->assertEquals('[1]', $stringArray);
$twoValueArray = [1, 2];
$stringArray = StringLiteralFormatter::formatArrayForGQLQuery($twoValueArray);
$this->assertEquals('[1, 2]', $stringArray);
$stringArray = ['one', 'two'];
$stringArray = StringLiteralFormatter::formatArrayForGQLQuery($stringArray);
$this->assertEquals('["one", "two"]', $stringArray);
$booleanArray = [true, false];
$stringArray = StringLiteralFormatter::formatArrayForGQLQuery($booleanArray);
$this->assertEquals('[true, false]', $stringArray);
$floatArray = [1.1, 2.2];
$stringArray = StringLiteralFormatter::formatArrayForGQLQuery($floatArray);
$this->assertEquals('[1.1, 2.2]', $stringArray);
}
/**
* @covers \GraphQL\Util\StringLiteralFormatter::formatUpperCamelCase
*/
public function testFormatUpperCamelCase()
{
$snakeCase = 'some_snake_case';
$camelCase = StringLiteralFormatter::formatUpperCamelCase($snakeCase);
$this->assertEquals('SomeSnakeCase', $camelCase);
$nonSnakeCase = 'somenonSnakeCase';
$camelCase = StringLiteralFormatter::formatUpperCamelCase($nonSnakeCase);
$this->assertEquals('SomenonSnakeCase', $camelCase);
}
/**
* @covers \GraphQL\Util\StringLiteralFormatter::formatLowerCamelCase
*/
public function testFormatLowerCamelCase()
{
$snakeCase = 'some_snake_case';
$camelCase = StringLiteralFormatter::formatLowerCamelCase($snakeCase);
$this->assertEquals('someSnakeCase', $camelCase);
$nonSnakeCase = 'somenonSnakeCase';
$camelCase = StringLiteralFormatter::formatLowerCamelCase($nonSnakeCase);
$this->assertEquals('somenonSnakeCase', $camelCase);
}
}