|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Yiisoft\Db\Tests\Support\TestTrait; |
|
9
|
|
|
|
|
10
|
|
|
abstract class AbstractQuoterTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
use TestTrait; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @dataProvider \Yiisoft\Db\Tests\Provider\QuoterProvider::ensureColumnName() |
|
16
|
|
|
*/ |
|
17
|
|
|
public function testEnsureColumnName(string $columnName, string $expected): void |
|
18
|
|
|
{ |
|
19
|
|
|
$db = $this->getConnection(); |
|
20
|
|
|
|
|
21
|
|
|
$this->assertSame($expected, $db->getQuoter()->ensureColumnName($columnName)); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @dataProvider \Yiisoft\Db\Tests\Provider\QuoterProvider::ensureNameQuoted() |
|
26
|
|
|
*/ |
|
27
|
|
|
public function testEnsureNameQuoted(string $name, string $expected): void |
|
28
|
|
|
{ |
|
29
|
|
|
$db = $this->getConnection(); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertSame($expected, $db->getQuoter()->ensureNameQuoted($name)); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @dataProvider \Yiisoft\Db\Tests\Provider\QuoterProvider::tableNameParts() |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testGetTableNameParts(string $tableName, string ...$expected): void |
|
38
|
|
|
{ |
|
39
|
|
|
$db = $this->getConnection(); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertSame($expected, array_reverse($db->getQuoter()->getTableNameParts($tableName))); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @dataProvider \Yiisoft\Db\Tests\Provider\QuoterProvider::columnNames() |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testQuoteColumnName(string $columnName, string $expected): void |
|
48
|
|
|
{ |
|
49
|
|
|
$db = $this->getConnection(); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertSame($expected, $db->getQuoter()->quoteColumnName($columnName)); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @dataProvider \Yiisoft\Db\Tests\Provider\QuoterProvider::simpleColumnNames() |
|
56
|
|
|
*/ |
|
57
|
|
|
public function testQuoteSimpleColumnName( |
|
58
|
|
|
string $columnName, |
|
59
|
|
|
string $expectedQuotedColumnName, |
|
60
|
|
|
string $expectedUnQuotedColumnName |
|
61
|
|
|
): void { |
|
62
|
|
|
$db = $this->getConnection(); |
|
63
|
|
|
|
|
64
|
|
|
$quoter = $db->getQuoter(); |
|
65
|
|
|
$quoted = $quoter->quoteSimpleColumnName($columnName); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertSame($expectedQuotedColumnName, $quoted); |
|
68
|
|
|
|
|
69
|
|
|
$unQuoted = $quoter->unquoteSimpleColumnName($quoted); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertSame($expectedUnQuotedColumnName, $unQuoted); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @dataProvider \Yiisoft\Db\Tests\Provider\QuoterProvider::simpleTableNames() |
|
76
|
|
|
*/ |
|
77
|
|
|
public function testQuoteTableName(string $tableName, string $expected): void |
|
78
|
|
|
{ |
|
79
|
|
|
$db = $this->getConnection(); |
|
80
|
|
|
|
|
81
|
|
|
$quoter = $db->getQuoter(); |
|
82
|
|
|
$unQuoted = $quoter->unquoteSimpleTableName($quoter->quoteSimpleTableName($tableName)); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertSame($expected, $unQuoted); |
|
85
|
|
|
|
|
86
|
|
|
$unQuoted = $quoter->unquoteSimpleTableName($quoter->quoteTableName($tableName)); |
|
87
|
|
|
|
|
88
|
|
|
$this->assertSame($expected, $unQuoted); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|