1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace StorageTests\Database\Dialects; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use CommonTestClass; |
7
|
|
|
use kalanis\kw_mapper\Interfaces\IQueryBuilder; |
8
|
|
|
use kalanis\kw_mapper\MapperException; |
9
|
|
|
use kalanis\kw_mapper\Storage\Database\Dialects; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class TranslateTest extends CommonTestClass |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param string $operation |
16
|
|
|
* @param string $expectedOper |
17
|
|
|
* @param string $key |
18
|
|
|
* @param string $expectedKey |
19
|
|
|
* @throws MapperException |
20
|
|
|
* @dataProvider operationsProvider |
21
|
|
|
*/ |
22
|
|
|
public function testOperations(string $operation, $key, string $expectedOper, string $expectedKey): void |
23
|
|
|
{ |
24
|
|
|
$lib = new XTranslate(); |
25
|
|
|
$this->assertEquals($expectedOper, $lib->translateOperation($operation)); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string $operation |
30
|
|
|
* @param string $expectedOper |
31
|
|
|
* @param string $key |
32
|
|
|
* @param string $expectedKey |
33
|
|
|
* @throws MapperException |
34
|
|
|
* @dataProvider operationsProvider |
35
|
|
|
*/ |
36
|
|
|
public function testKeys(string $operation, $key, string $expectedOper, string $expectedKey): void |
37
|
|
|
{ |
38
|
|
|
$lib = new XTranslate(); |
39
|
|
|
$this->assertEquals($expectedKey, $lib->translateKey($operation, $key)); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function operationsProvider(): array |
43
|
|
|
{ |
44
|
|
|
return [ |
45
|
|
|
[IQueryBuilder::OPERATION_NULL, 'abc', 'IS NULL', ''], |
46
|
|
|
[IQueryBuilder::OPERATION_NNULL, 123, 'IS NOT NULL', ''], |
47
|
|
|
[IQueryBuilder::OPERATION_EQ, 'def', '=', 'def'], |
48
|
|
|
[IQueryBuilder::OPERATION_NEQ, 456, '!=', '456'], |
49
|
|
|
[IQueryBuilder::OPERATION_GT, 'ghi', '>', 'ghi'], |
50
|
|
|
[IQueryBuilder::OPERATION_GTE, 789.01, '>=', '789.01'], |
51
|
|
|
[IQueryBuilder::OPERATION_LT, 'jkl', '<', 'jkl'], |
52
|
|
|
[IQueryBuilder::OPERATION_LTE, new \StrObjMock(), '<=', 'strObj'], |
53
|
|
|
[IQueryBuilder::OPERATION_LIKE, 'mno', 'LIKE', 'mno'], |
54
|
|
|
[IQueryBuilder::OPERATION_NLIKE, 'pqr', 'NOT LIKE', 'pqr'], |
55
|
|
|
[IQueryBuilder::OPERATION_REXP, 'stu', 'REGEX', 'stu'], |
56
|
|
|
[IQueryBuilder::OPERATION_IN, [], 'IN', '(0)'], |
57
|
|
|
[IQueryBuilder::OPERATION_NIN, ['okm', 'ijn'], 'NOT IN', '(okm,ijn)'], |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @throws MapperException |
63
|
|
|
*/ |
64
|
|
|
public function testOperationsFailed(): void |
65
|
|
|
{ |
66
|
|
|
$lib = new XTranslate(); |
67
|
|
|
$this->expectException(MapperException::class); |
68
|
|
|
$lib->translateOperation('undefined one'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @throws MapperException |
73
|
|
|
*/ |
74
|
|
|
public function testKeysFailed(): void |
75
|
|
|
{ |
76
|
|
|
$lib = new XTranslate(); |
77
|
|
|
$this->expectException(MapperException::class); |
78
|
|
|
$lib->translateKey('undefined one', 'with failed'); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
class XTranslate |
84
|
|
|
{ |
85
|
|
|
use Dialects\TTranslate; |
86
|
|
|
} |
87
|
|
|
|