TableTraitTest   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 46
c 1
b 0
f 0
dl 0
loc 128
rs 10
wmc 13

21 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ tableData() 0 3 1
A hp$0 ➔ testBuildFromQueryPartWhenEmpty() 0 5 1
A hp$0 ➔ testTableWhenEmpty() 0 6 1
A hp$0 ➔ __construct() 0 3 1
testBuildFromQueryPartWhenEmpty() 0 5 ?
A hp$0 ➔ buildFromQueryPartPublic() 0 3 1
A hp$0 ➔ testTable() 0 16 1
A hp$0 ➔ setUp() 0 41 1
A hp$0 ➔ buildTableQueryPartPublic() 0 3 1
A hp$0 ➔ testBuildFromQueryPart() 0 7 1
A hp$0 ➔ testTableClearAll() 0 4 1
A hp$0 ➔ testBuildTableQueryPartWhenEmpty() 0 5 1
testBuildTableQueryPartWhenEmpty() 0 5 ?
A hp$0 ➔ clearTableData() 0 3 1
testBuildFromQueryPart() 0 7 ?
testBuildTableQueryPart() 0 7 ?
A hp$0 ➔ testBuildTableQueryPart() 0 7 1
testTableWhenEmpty() 0 6 ?
setUp() 0 41 ?
testTable() 0 16 ?
testTableClearAll() 0 4 ?
1
<?php declare(strict_types=1);
2
3
namespace Janisbiz\LightOrm\Tests\Unit\Dms\MySQL\QueryBuilder\Traits;
4
5
use Janisbiz\LightOrm\Dms\MySQL\Enum\ConditionEnum;
6
use Janisbiz\LightOrm\Dms\MySQL\QueryBuilder\QueryBuilderException;
7
use Janisbiz\LightOrm\Dms\MySQL\QueryBuilder\Traits\TableTrait;
8
9
class TableTraitTest extends AbstractTraitTestCase
10
{
11
    const TABLE_DEFAULT = [
12
        'table1',
13
        'table2',
14
    ];
15
    const TABLE_ARRAY = [
16
        'table3',
17
        'table4',
18
    ];
19
    const TABLE_EMPTY = '';
20
    const TABLE = 'table5';
21
22
    /**
23
     * @var TableTrait
24
     */
25
    private $tableTraitClass;
26
27
    public function setUp()
28
    {
29
        $this->tableTraitClass = new class (TableTraitTest::TABLE_DEFAULT)
30
        {
31
            use TableTrait;
32
33
            /**
34
             * @param array $tableDataDefault
35
             */
36
            public function __construct(array $tableDataDefault)
37
            {
38
                $this->table = $tableDataDefault;
39
            }
40
41
            /**
42
             * @return array
43
             */
44
            public function &tableData(): array
45
            {
46
                return $this->table;
47
            }
48
            
49
            public function clearTableData()
50
            {
51
                $this->table = [];
52
            }
53
54
            /**
55
             * @return null|string
56
             */
57
            public function buildTableQueryPartPublic(): ?string
58
            {
59
                return $this->buildTableQueryPart();
60
            }
61
62
            /**
63
             * @return null|string
64
             */
65
            public function buildFromQueryPartPublic(): ?string
66
            {
67
                return $this->buildFromQueryPart();
68
            }
69
        };
70
    }
71
72
    public function testTable()
73
    {
74
        $this->assertEquals(static::TABLE_DEFAULT, $this->tableTraitClass->tableData());
0 ignored issues
show
Bug introduced by
The method tableData() does not exist on Janisbiz\LightOrm\Dms\My...ilder\Traits\TableTrait. Did you maybe mean table()? ( Ignorable by Annotation )

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

74
        $this->assertEquals(static::TABLE_DEFAULT, $this->tableTraitClass->/** @scrutinizer ignore-call */ tableData());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
75
76
        $object = $this->tableTraitClass->table(static::TABLE_ARRAY);
77
        $this->assertObjectUsesTrait(TableTrait::class, $object);
78
        $this->assertEquals(
79
            \array_merge(static::TABLE_DEFAULT, static::TABLE_ARRAY),
80
            $this->tableTraitClass->tableData()
81
        );
82
83
        $object = $this->tableTraitClass->table(static::TABLE);
84
        $this->assertObjectUsesTrait(TableTrait::class, $object);
85
        $this->assertEquals(
86
            \array_merge(static::TABLE_DEFAULT, static::TABLE_ARRAY, [static::TABLE]),
87
            $this->tableTraitClass->tableData()
88
        );
89
    }
90
91
    public function testTableClearAll()
92
    {
93
        $this->tableTraitClass->table(static::TABLE, true);
94
        $this->assertEquals([static::TABLE], $this->tableTraitClass->tableData());
95
    }
96
97
    public function testTableWhenEmpty()
98
    {
99
        $this->expectException(QueryBuilderException::class);
100
        $this->expectExceptionMessage('You must pass $table to table method!');
101
102
        $this->tableTraitClass->table(static::TABLE_EMPTY);
103
    }
104
105
    public function testBuildTableQueryPart()
106
    {
107
        $this->tableTraitClass->table(static::TABLE);
108
109
        $this->assertEquals(
110
            \reset($this->tableTraitClass->tableData()),
111
            $this->tableTraitClass->buildTableQueryPartPublic()
0 ignored issues
show
Bug introduced by
The method buildTableQueryPartPublic() does not exist on Janisbiz\LightOrm\Dms\My...ilder\Traits\TableTrait. Did you maybe mean buildTableQueryPart()? ( Ignorable by Annotation )

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

111
            $this->tableTraitClass->/** @scrutinizer ignore-call */ 
112
                                    buildTableQueryPartPublic()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
112
        );
113
    }
114
115
    public function testBuildTableQueryPartWhenEmpty()
116
    {
117
        $this->tableTraitClass->clearTableData();
0 ignored issues
show
Bug introduced by
It seems like clearTableData() 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

117
        $this->tableTraitClass->/** @scrutinizer ignore-call */ 
118
                                clearTableData();
Loading history...
118
119
        $this->assertEquals(null, $this->tableTraitClass->buildTableQueryPartPublic());
120
    }
121
122
    public function testBuildFromQueryPart()
123
    {
124
        $this->tableTraitClass->table(static::TABLE);
125
126
        $this->assertEquals(
127
            \sprintf('%s %s', ConditionEnum::FROM, \implode(', ', $this->tableTraitClass->tableData())),
128
            $this->tableTraitClass->buildFromQueryPartPublic()
0 ignored issues
show
Bug introduced by
The method buildFromQueryPartPublic() does not exist on Janisbiz\LightOrm\Dms\My...ilder\Traits\TableTrait. Did you maybe mean buildFromQueryPart()? ( Ignorable by Annotation )

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

128
            $this->tableTraitClass->/** @scrutinizer ignore-call */ 
129
                                    buildFromQueryPartPublic()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
129
        );
130
    }
131
132
    public function testBuildFromQueryPartWhenEmpty()
133
    {
134
        $this->tableTraitClass->clearTableData();
135
136
        $this->assertEquals(null, $this->tableTraitClass->buildFromQueryPartPublic());
137
    }
138
}
139