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()); |
|
|
|
|
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
|
|
|
|
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.