-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathQueryFormatterTest.php
More file actions
46 lines (36 loc) · 1.62 KB
/
QueryFormatterTest.php
File metadata and controls
46 lines (36 loc) · 1.62 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
<?hh // strict
namespace Slack\SQLFake;
use type Facebook\HackTest\HackTest;
use function Facebook\FBExpect\expect;
final class QueryFormatterTest extends HackTest {
public async function testSingleFormat(): Awaitable<void> {
$qf = QueryFormatter::formatQuery('SELECT * FROM foo WHERE bar = %s', 'baz');
expect($qf)->toBeSame('SELECT * FROM foo WHERE bar = "baz"');
}
public async function testNullString(): Awaitable<void> {
$qf = QueryFormatter::formatQuery('SELECT %s FROM foo WHERE bar %=s', null, null);
expect($qf)->toBeSame('SELECT NULL FROM foo WHERE bar IS NULL');
}
public async function testComplexFormat(): Awaitable<void> {
$qf = QueryFormatter::formatQuery('SELECT %C, %C FROM %T WHERE %C = %d', 'col1', 'col2', 'mytable', 'col2', 25);
expect($qf)->toBeSame('SELECT `col1`, `col2` FROM `mytable` WHERE `col2` = 25');
}
public async function testInvalidValue(): Awaitable<void> {
expect(() ==> QueryFormatter::formatQuery('SELECT %d', '1'))->toThrow(
SQLFakeParseException::class,
'string value not valid for %d',
);
}
public async function testIdentifierTuples(): Awaitable<void> {
$qf = QueryFormatter::formatQuery('SELECT %C FROM %T', tuple('tab1', 'col1', 'myalias'), tuple('db1', 'tab1'));
expect($qf)->toBeSame('SELECT `tab1`.`col1` AS `myalias` FROM `db1`.`tab1`');
}
public async function testStringList(): Awaitable<void> {
$qf = QueryFormatter::formatQuery(
'SELECT * FROM t1 WHERE name IN (%Ls) OR id IN (%Ld)',
keyset['foo', 'bar', 'baz'],
keyset[100, 101, 102],
);
expect($qf)->toBeSame('SELECT * FROM t1 WHERE name IN ("foo", "bar", "baz") OR id IN (100, 101, 102)');
}
}