LimitOffsetTraitTest   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 143
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 48
c 1
b 0
f 0
dl 0
loc 143
rs 10
wmc 17

30 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ testBuildOffsetQueryPart() 0 7 1
testBuildOffsetQueryPartWhenEmpty() 0 3 ?
A hp$0 ➔ testLimit() 0 5 1
A hp$0 ➔ testLimitWithOffset() 0 6 1
A hp$0 ➔ offsetData() 0 3 1
A hp$0 ➔ buildLimitQueryPartPublic() 0 3 1
testBuildOffsetQueryPart() 0 7 ?
A hp$0 ➔ testBuildOffsetQueryPartWhenEmpty() 0 3 1
A hp$0 ➔ limitData() 0 3 1
A hp$0 ➔ testLimitEmpty() 0 6 1
A hp$0 ➔ testLimitWithOffsetWithEmptyLimit() 0 6 1
testBuildLimitQueryPartWhenEmpty() 0 3 ?
A hp$0 ➔ testBuildLimitQueryPartWhenEmpty() 0 3 1
A hp$0 ➔ testBuildLimitQueryPart() 0 7 1
A hp$0 ➔ testOffsetInvalid() 0 6 1
A hp$0 ➔ testLimitWithOffsetWithEmptyOffset() 0 6 1
A hp$0 ➔ testOffset() 0 5 1
A hp$0 ➔ buildOffsetQueryPartPublic() 0 3 1
testOffsetInvalid() 0 6 ?
A hp$0 ➔ setUp() 0 36 1
testBuildLimitQueryPart() 0 7 ?
A hp$0 ➔ testOffsetWithEmptyLimit() 0 6 1
setUp() 0 36 ?
testLimitEmpty() 0 6 ?
testOffset() 0 5 ?
testLimit() 0 5 ?
testOffsetWithEmptyLimit() 0 6 ?
testLimitWithOffsetWithEmptyOffset() 0 6 ?
testLimitWithOffset() 0 6 ?
testLimitWithOffsetWithEmptyLimit() 0 6 ?
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\LimitOffsetTrait;
8
9
class LimitOffsetTraitTest extends AbstractTraitTestCase
10
{
11
    const LIMIT_INVALID = -1;
12
    const LIMIT_DEFAULT = 1;
13
    const LIMIT = 2;
14
    const OFFSET_INVALID = -1;
15
    const OFFSET = 1;
16
17
    /**
18
     * @var LimitOffsetTrait
19
     */
20
    private $limitOffsetTraitClass;
21
    
22
    public function setUp()
23
    {
24
        $this->limitOffsetTraitClass = new class ()
25
        {
26
            use LimitOffsetTrait;
27
28
            /**
29
             * @return null|int
30
             */
31
            public function limitData(): ?int
32
            {
33
                return $this->limit;
34
            }
35
36
            /**
37
             * @return null|int
38
             */
39
            public function offsetData(): ?int
40
            {
41
                return $this->offset;
42
            }
43
44
            /**
45
             * @return null|string
46
             */
47
            public function buildLimitQueryPartPublic(): ?string
48
            {
49
                return $this->buildLimitQueryPart();
50
            }
51
52
            /**
53
             * @return null|string
54
             */
55
            public function buildOffsetQueryPartPublic(): ?string
56
            {
57
                return $this->buildOffsetQueryPart();
58
            }
59
        };
60
    }
61
62
    public function testOffset()
63
    {
64
        $object = $this->limitOffsetTraitClass->limit(static::LIMIT)->offset(static::OFFSET);
65
        $this->assertObjectUsesTrait(LimitOffsetTrait::class, $object);
66
        $this->assertEquals(static::OFFSET, $this->limitOffsetTraitClass->offsetData());
0 ignored issues
show
Bug introduced by
The method offsetData() does not exist on Janisbiz\LightOrm\Dms\My...Traits\LimitOffsetTrait. Did you maybe mean offset()? ( Ignorable by Annotation )

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

66
        $this->assertEquals(static::OFFSET, $this->limitOffsetTraitClass->/** @scrutinizer ignore-call */ offsetData());

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...
67
    }
68
69
    public function testOffsetInvalid()
70
    {
71
        $this->expectException(QueryBuilderException::class);
72
        $this->expectExceptionMessage('You must pass $offset to offset method!');
73
74
        $this->limitOffsetTraitClass->offset(static::OFFSET_INVALID);
75
    }
76
77
    public function testOffsetWithEmptyLimit()
78
    {
79
        $this->expectException(QueryBuilderException::class);
80
        $this->expectExceptionMessage('You must set LIMIT before calling offset method!');
81
82
        $this->limitOffsetTraitClass->offset(static::OFFSET);
83
    }
84
85
    public function testLimitWithOffset()
86
    {
87
        $object = $this->limitOffsetTraitClass->limitWithOffset(static::LIMIT, static::OFFSET);
88
        $this->assertObjectUsesTrait(LimitOffsetTrait::class, $object);
89
        $this->assertEquals(static::LIMIT, $this->limitOffsetTraitClass->limitData());
0 ignored issues
show
Bug introduced by
The method limitData() does not exist on Janisbiz\LightOrm\Dms\My...Traits\LimitOffsetTrait. Did you maybe mean limit()? ( Ignorable by Annotation )

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

89
        $this->assertEquals(static::LIMIT, $this->limitOffsetTraitClass->/** @scrutinizer ignore-call */ limitData());

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...
90
        $this->assertEquals(static::OFFSET, $this->limitOffsetTraitClass->offsetData());
91
    }
92
93
    public function testLimitWithOffsetWithEmptyLimit()
94
    {
95
        $this->expectException(QueryBuilderException::class);
96
        $this->expectExceptionMessage('You must pass $limit to limit method!');
97
98
        $this->limitOffsetTraitClass->limitWithOffset(static::LIMIT_INVALID, static::OFFSET);
99
    }
100
101
    public function testLimitWithOffsetWithEmptyOffset()
102
    {
103
        $this->expectException(QueryBuilderException::class);
104
        $this->expectExceptionMessage('You must pass $offset to offset method!');
105
106
        $this->limitOffsetTraitClass->limitWithOffset(static::LIMIT, static::OFFSET_INVALID);
107
    }
108
109
    public function testLimit()
110
    {
111
        $object = $this->limitOffsetTraitClass->limit(static::LIMIT);
112
        $this->assertObjectUsesTrait(LimitOffsetTrait::class, $object);
113
        $this->assertEquals(static::LIMIT, $this->limitOffsetTraitClass->limitData());
114
    }
115
116
    public function testLimitEmpty()
117
    {
118
        $this->expectException(QueryBuilderException::class);
119
        $this->expectExceptionMessage('You must pass $limit to limit method!');
120
121
        $this->limitOffsetTraitClass->limit(static::LIMIT_INVALID);
122
    }
123
124
    public function testBuildLimitQueryPart()
125
    {
126
        $this->limitOffsetTraitClass->limit(static::LIMIT);
127
128
        $this->assertEquals(
129
            \sprintf('%s %d', ConditionEnum::LIMIT, $this->limitOffsetTraitClass->limitData()),
130
            $this->limitOffsetTraitClass->buildLimitQueryPartPublic()
0 ignored issues
show
Bug introduced by
The method buildLimitQueryPartPublic() does not exist on Janisbiz\LightOrm\Dms\My...Traits\LimitOffsetTrait. Did you maybe mean buildLimitQueryPart()? ( Ignorable by Annotation )

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

130
            $this->limitOffsetTraitClass->/** @scrutinizer ignore-call */ 
131
                                          buildLimitQueryPartPublic()

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...
131
        );
132
    }
133
134
    public function testBuildLimitQueryPartWhenEmpty()
135
    {
136
        $this->assertEquals(null, $this->limitOffsetTraitClass->buildLimitQueryPartPublic());
137
    }
138
139
    public function testBuildOffsetQueryPart()
140
    {
141
        $this->limitOffsetTraitClass->limitWithOffset(static::LIMIT, static::OFFSET);
142
143
        $this->assertEquals(
144
            \sprintf('%s %d', ConditionEnum::OFFSET, $this->limitOffsetTraitClass->offsetData()),
145
            $this->limitOffsetTraitClass->buildOffsetQueryPartPublic()
0 ignored issues
show
Bug introduced by
The method buildOffsetQueryPartPublic() does not exist on Janisbiz\LightOrm\Dms\My...Traits\LimitOffsetTrait. Did you maybe mean buildOffsetQueryPart()? ( Ignorable by Annotation )

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

145
            $this->limitOffsetTraitClass->/** @scrutinizer ignore-call */ 
146
                                          buildOffsetQueryPartPublic()

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...
146
        );
147
    }
148
149
    public function testBuildOffsetQueryPartWhenEmpty()
150
    {
151
        $this->assertEquals(null, $this->limitOffsetTraitClass->buildOffsetQueryPartPublic());
152
    }
153
}
154