This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
/
ExceptionsTest.php
80 lines (66 loc) · 1.99 KB
/
ExceptionsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* Spiral Framework.
*
* @license MIT
* @author Anton Titov (Wolfy-J)
*/
declare(strict_types=1);
namespace Spiral\Database\Tests;
use Spiral\Database\Database;
use Spiral\Database\Exception\HandlerException;
use Spiral\Database\Exception\StatementException;
/**
* Add exception versions in a future versions.
*/
abstract class ExceptionsTest extends BaseTest
{
/**
* @var Database
*/
protected $database;
public function setUp(): void
{
$this->database = $this->db();
}
public function testSelectionException(): void
{
$select = $this->database->select()->from('udnefinedTable');
try {
$select->run();
} catch (StatementException $e) {
$this->assertInstanceOf(\PDOException::class, $e->getPrevious());
$this->assertSame(
$e->getQuery(),
$select->sqlStatement()
);
}
}
public function testHandlerException(): void
{
$select = $this->database->select()->from('udnefinedTable');
try {
$select->run();
} catch (StatementException $e) {
$h = new HandlerException($e);
$this->assertInstanceOf(StatementException::class, $h->getPrevious());
$this->assertSame(
$h->getQuery(),
$select->sqlStatement()
);
}
}
public function testInsertNotNullable(): void
{
$schema = $this->getDriver()->getSchema('test');
$schema->primary('id');
$schema->string('value')->nullable(false)->defaultValue(null);
$schema->save();
$this->getDriver()->insertQuery('', 'test')->values(['value' => 'value'])->run();
try {
$this->getDriver()->insertQuery('', 'test')->values(['value' => null])->run();
} catch (StatementException\ConstrainException $e) {
$this->assertInstanceOf(StatementException\ConstrainException::class, $e);
}
}
}