Skip to content

Commit 013d456

Browse files
Remove src\TestSupport\TestQuoterTrait from yiisoft\db. (#418)
* Remove src\TestSupport\TestQuoterTrait from yiisoft\db.
1 parent e0e6992 commit 013d456

4 files changed

Lines changed: 109 additions & 225 deletions

File tree

src/TestSupport/TestQuoterTrait.php

Lines changed: 0 additions & 77 deletions
This file was deleted.

tests/AbstractQuoterTest.php

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testGetTableNameParts(string $tableName, string ...$expected): v
4242
}
4343

4444
/**
45-
* @dataProvider \Yiisoft\Db\Tests\Provider\QuoterProvider::columnName()
45+
* @dataProvider \Yiisoft\Db\Tests\Provider\QuoterProvider::columnNames()
4646
*/
4747
public function testQuoteColumnName(string $columnName, string $expected): void
4848
{
@@ -52,52 +52,39 @@ public function testQuoteColumnName(string $columnName, string $expected): void
5252
}
5353

5454
/**
55-
* @dataProvider \Yiisoft\Db\Tests\Provider\QuoterProvider::columnName()
55+
* @dataProvider \Yiisoft\Db\Tests\Provider\QuoterProvider::simpleColumnNames()
5656
*/
57-
public function testQuoteSimpleColumnName(string $columnName, string $expected): void
58-
{
57+
public function testQuoteSimpleColumnName(
58+
string $columnName,
59+
string $expectedQuotedColumnName,
60+
string $expectedUnQuotedColumnName
61+
): void {
5962
$db = $this->getConnection();
6063

61-
$this->assertSame($expected, $db->getQuoter()->quoteSimpleColumnName($columnName));
62-
}
64+
$quoter = $db->getQuoter();
65+
$quoted = $quoter->quoteSimpleColumnName($columnName);
6366

64-
/**
65-
* @dataProvider \Yiisoft\Db\Tests\Provider\QuoterProvider::simpleTableName()
66-
*/
67-
public function testQuoteSimpleTableName(string $columnName, string $expected): void
68-
{
69-
$db = $this->getConnection();
67+
$this->assertSame($expectedQuotedColumnName, $quoted);
68+
69+
$unQuoted = $quoter->unquoteSimpleColumnName($quoted);
7070

71-
$this->assertSame($expected, $db->getQuoter()->quoteSimpleTableName($columnName));
71+
$this->assertSame($expectedUnQuotedColumnName, $unQuoted);
7272
}
7373

7474
/**
75-
* @dataProvider \Yiisoft\Db\Tests\Provider\QuoterProvider::tableName()
75+
* @dataProvider \Yiisoft\Db\Tests\Provider\QuoterProvider::simpleTableNames()
7676
*/
7777
public function testQuoteTableName(string $tableName, string $expected): void
7878
{
7979
$db = $this->getConnection();
8080

81-
$this->assertSame($expected, $db->getQuoter()->quoteTableName($tableName));
82-
}
83-
84-
/**
85-
* @dataProvider \Yiisoft\Db\Tests\Provider\QuoterProvider::unquoteSimpleColumnName()
86-
*/
87-
public function testUnquoteSimpleColumnName(string $columnName, string $expected): void
88-
{
89-
$db = $this->getConnection();
81+
$quoter = $db->getQuoter();
82+
$unQuoted = $quoter->unquoteSimpleTableName($quoter->quoteSimpleTableName($tableName));
9083

91-
$this->assertSame($expected, $db->getQuoter()->unquoteSimpleColumnName($columnName));
92-
}
84+
$this->assertSame($expected, $unQuoted);
9385

94-
/**
95-
* @dataProvider \Yiisoft\Db\Tests\Provider\QuoterProvider::unquoteSimpleTableName()
96-
*/
97-
public function testUnquoteSimpleTableName(string $tableName, string $expected): void
98-
{
99-
$db = $this->getConnection();
86+
$unQuoted = $quoter->unquoteSimpleTableName($quoter->quoteTableName($tableName));
10087

101-
$this->assertSame($expected, $db->getQuoter()->unquoteSimpleTableName($tableName));
88+
$this->assertSame($expected, $unQuoted);
10289
}
10390
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yiisoft\Db\Tests\Provider;
6+
7+
abstract class AbstractQuoterProvider
8+
{
9+
/**
10+
* @return string[][]
11+
*/
12+
public function columnNames(): array
13+
{
14+
return [
15+
['*', '*'],
16+
['(*)', '(*)'],
17+
['[[*]]', '[[*]]'],
18+
];
19+
}
20+
21+
/**
22+
* @return string[][]
23+
*/
24+
public function ensureColumnName(): array
25+
{
26+
return [
27+
['*', '*'],
28+
['`*`', '`*`'],
29+
['[[*]]', '[[*]]'],
30+
['{{*}}', '{{*}}'],
31+
['table.column', 'column'],
32+
['`table`.`column`', '`column`'],
33+
['[[table]].[[column]]', 'column'],
34+
['{{table}}.{{column}}', '{{column}}'],
35+
];
36+
}
37+
38+
/**
39+
* @return string[][]
40+
*/
41+
public function ensureNameQuoted(): array
42+
{
43+
return [
44+
['name', '{{name}}'],
45+
['`name`', '{{name}}'],
46+
['[[name]]', '{{name}}'],
47+
['{{name}}', '{{name}}'],
48+
['table.name', '{{table.name}}'],
49+
['`table`.`name`', '{{table.name}}'],
50+
['[[table]].[[name]]', '{{table.name}}'],
51+
['{{table}}.{{name}}', '{{table}}.{{name}}'],
52+
];
53+
}
54+
55+
/**
56+
* @return string[][]
57+
*/
58+
public function simpleColumnNames(): array
59+
{
60+
return [
61+
['*', '*', '*'],
62+
];
63+
}
64+
65+
/**
66+
* @return string[][]
67+
*/
68+
public function simpleTableNames(): array
69+
{
70+
return [
71+
['test', 'test'],
72+
];
73+
}
74+
75+
/**
76+
* @return string[][]
77+
*/
78+
public function tableNameParts(): array
79+
{
80+
return [
81+
['animal', 'animal',],
82+
['dbo.animal', 'animal', 'dbo'],
83+
['[dbo].[animal]', 'animal', 'dbo'],
84+
['[other].[animal2]', 'animal2', 'other'],
85+
['other.[animal2]', 'animal2', 'other'],
86+
['other.animal2', 'animal2', 'other'],
87+
];
88+
}
89+
}

tests/Provider/QuoterProvider.php

Lines changed: 1 addition & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -4,121 +4,6 @@
44

55
namespace Yiisoft\Db\Tests\Provider;
66

7-
final class QuoterProvider
7+
final class QuoterProvider extends AbstractQuoterProvider
88
{
9-
/**
10-
* @return string[][]
11-
*/
12-
public function columnName(): array
13-
{
14-
return [
15-
['test', '[test]'],
16-
['[test]', '[test]'],
17-
['*', '*'],
18-
];
19-
}
20-
21-
/**
22-
* @return string[][]
23-
*/
24-
public function ensureColumnName(): array
25-
{
26-
return [
27-
['*', '*'],
28-
['`*`', '`*`'],
29-
['[[*]]', '[[*]]'],
30-
['{{*}}', '{{*}}'],
31-
['table.column', 'column'],
32-
['`table`.`column`', '`column`'],
33-
['[[table]].[[column]]', 'column'],
34-
['{{table}}.{{column}}', '{{column}}'],
35-
];
36-
}
37-
38-
/**
39-
* @return string[][]
40-
*/
41-
public function ensureNameQuoted(): array
42-
{
43-
return [
44-
['name', '{{name}}'],
45-
['`name`', '{{name}}'],
46-
['[[name]]', '{{name}}'],
47-
['{{name}}', '{{name}}'],
48-
['table.name', '{{table.name}}'],
49-
['`table`.`name`', '{{table.name}}'],
50-
['[[table]].[[name]]', '{{table.name}}'],
51-
['{{table}}.{{name}}', '{{table}}.{{name}}'],
52-
];
53-
}
54-
55-
/**
56-
* @return string[][]
57-
*/
58-
public function simpleTableName(): array
59-
{
60-
return [
61-
['test', '[test]', ],
62-
['te`st', '[te`st]', ],
63-
['te\'st', '[te\'st]', ],
64-
['te"st', '[te"st]', ],
65-
['current-table-name', '[current-table-name]'],
66-
['[current-table-name]', '[current-table-name]'],
67-
];
68-
}
69-
70-
/**
71-
* @return string[][]
72-
*/
73-
public function tableName(): array
74-
{
75-
return [
76-
['test', '[test]'],
77-
['test.test', '[test].[test]'],
78-
['[test]', '[test]'],
79-
['[test].[test]', '[test].[test]'],
80-
];
81-
}
82-
83-
/**
84-
* @return string[][]
85-
*/
86-
public function tableNameParts(): array
87-
{
88-
return [
89-
['animal', 'animal',],
90-
['dbo.animal', 'animal', 'dbo'],
91-
['[dbo].[animal]', 'animal', 'dbo'],
92-
['[other].[animal2]', 'animal2', 'other'],
93-
['other.[animal2]', 'animal2', 'other'],
94-
['other.animal2', 'animal2', 'other'],
95-
];
96-
}
97-
98-
/**
99-
* @return string[][]
100-
*/
101-
public function unquoteSimpleColumnName(): array
102-
{
103-
return [
104-
['test', 'test'],
105-
['[test]', 'test'],
106-
['*', '*'],
107-
];
108-
}
109-
110-
/**
111-
* @return string[][]
112-
*/
113-
public function unquoteSimpleTableName(): array
114-
{
115-
return [
116-
['[test]', 'test'],
117-
['[te`st]', 'te`st'],
118-
['[te\'st]', 'te\'st'],
119-
['[te"st]', 'te"st'],
120-
['[current-table-name]', 'current-table-name'],
121-
['[current-table-name]', 'current-table-name'],
122-
];
123-
}
1249
}

0 commit comments

Comments
 (0)