Passed
Pull Request — master (#367)
by Def
02:03
created

TestQuoterTrait::testQuoteSimpleColumnName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 9
rs 10
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();
0 ignored issues
show
Bug introduced by
It seems like getConnection() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

14
        $quoter = $this->/** @scrutinizer ignore-call */ getConnection(false)->getQuoter();
Loading history...
15
16
        $unQuoted = $quoter->unquoteSimpleTableName($quoter->quoteSimpleTableName($tableName));
17
        $this->assertEquals($expectedTableName, $unQuoted);
0 ignored issues
show
Bug introduced by
It seems like assertEquals() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
        $this->/** @scrutinizer ignore-call */ 
18
               assertEquals($expectedTableName, $unQuoted);
Loading history...
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
}
78