UnlexableSqlExceptionTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldProvideSql() 0 4 1
A shouldProduceAsciiLocationDump() 0 16 1
A setUp() 0 3 1
A shouldProvideSqlOffset() 0 4 1
A shouldProvideSqlLine() 0 4 1
1
<?php
2
/**
3
 * Copyright (C) 2019  Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 *
8
 * @license GPL-3.0
9
 * @author Gerrit Addiks <[email protected]>
10
 */
11
12
namespace Addiks\StoredSQL\Tests\Unit\Exception;
13
14
use Addiks\StoredSQL\Exception\UnlexableSqlException;
15
use PHPUnit\Framework\TestCase;
16
use Webmozart\Assert\Assert;
17
18
/** @covers Addiks\StoredSQL\Exception\UnlexableSqlException */
19
final class UnlexableSqlExceptionTest extends TestCase
20
{
21
    private ?UnlexableSqlException $exception = null;
22
23
    public function setUp(): void
24
    {
25
        $this->exception = new UnlexableSqlException("SELECT foo\nFROM bar", 1, 6);
26
    }
27
28
    /** @test */
29
    public function shouldProduceAsciiLocationDump(): void
30
    {
31
        Assert::object($this->exception);
32
33
        /** @var mixed $expectedOutput */
34
        $expectedOutput = <<<EOL
35
36
37
         \u{2193}
38
   SELECT foo
39
 \u{2192} FROM bar   \u{2190}
40
         \u{2191}
41
42
EOL;
43
44
        $this->assertEquals($expectedOutput, $this->exception->asciiLocationDump());
0 ignored issues
show
Bug introduced by
The method asciiLocationDump() does not exist on null. ( Ignorable by Annotation )

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

44
        $this->assertEquals($expectedOutput, $this->exception->/** @scrutinizer ignore-call */ asciiLocationDump());

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...
45
    }
46
47
    /** @test */
48
    public function shouldProvideSql(): void
49
    {
50
        Assert::object($this->exception);
51
        $this->assertEquals("SELECT foo\nFROM bar", $this->exception->sql());
52
    }
53
54
    /** @test */
55
    public function shouldProvideSqlLine(): void
56
    {
57
        Assert::object($this->exception);
58
        $this->assertEquals(1, $this->exception->sqlLine());
59
    }
60
61
    /** @test */
62
    public function shouldProvideSqlOffset(): void
63
    {
64
        Assert::object($this->exception);
65
        $this->assertEquals(6, $this->exception->sqlOffset());
66
    }
67
}
68