Skip to content

Commit 1029827

Browse files
authored
Quoter test (for increase test support) (#367)
* Remove connection from Quoter * fix * Add tests for Quoter * Fix
1 parent b43f9a0 commit 1029827

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yiisoft\Db\TestSupport;
6+
7+
trait TestQuoterTrait
8+
{
9+
/**
10+
* @dataProvider simpleTableNamesProvider
11+
*/
12+
public function testQuoteTableName(string $tableName, string $expectedTableName): void
13+
{
14+
$quoter = $this->getConnection(false)->getQuoter();
15+
16+
$unQuoted = $quoter->unquoteSimpleTableName($quoter->quoteSimpleTableName($tableName));
17+
$this->assertEquals($expectedTableName, $unQuoted);
18+
19+
$unQuoted = $quoter->unquoteSimpleTableName($quoter->quoteTableName($tableName));
20+
$this->assertEquals($expectedTableName, $unQuoted);
21+
}
22+
23+
/**
24+
* @dataProvider simpleColumnNamesProvider
25+
*/
26+
public function testQuoteSimpleColumnName(string $columnName, string $expectedQuotedColumnName, string $expectedUnQuotedColunName): void
27+
{
28+
$quoter = $this->getConnection(false)->getQuoter();
29+
30+
$quoted = $quoter->quoteSimpleColumnName($columnName);
31+
$this->assertEquals($expectedQuotedColumnName, $quoted);
32+
33+
$unQuoted = $quoter->unquoteSimpleColumnName($quoted);
34+
$this->assertEquals($expectedUnQuotedColunName, $unQuoted);
35+
}
36+
37+
/**
38+
* @dataProvider columnNamesProvider
39+
*/
40+
public function testQuoteColumnName(string $columnName, string $expectedQuotedColumnName): void
41+
{
42+
$quoter = $this->getConnection(false)->getQuoter();
43+
44+
$quoted = $quoter->quoteColumnName($columnName);
45+
$this->assertEquals($expectedQuotedColumnName, $quoted);
46+
}
47+
48+
/**
49+
* @return string[][]
50+
*/
51+
public function simpleTableNamesProvider(): array
52+
{
53+
return [
54+
['test', 'test', ],
55+
];
56+
}
57+
58+
/**
59+
* @return string[][]
60+
*/
61+
public function simpleColumnNamesProvider(): array
62+
{
63+
return [
64+
['*', '*', '*'],
65+
];
66+
}
67+
68+
/**
69+
* @return string[][]
70+
*/
71+
public function columnNamesProvider(): array
72+
{
73+
return [
74+
['*', '*'],
75+
];
76+
}
77+
}

0 commit comments

Comments
 (0)