Passed
Pull Request — master (#380)
by Alexander
03:00
created

ExceptionTest::testaddDefaultValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests\QueryBuilder;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Db\Exception\Exception;
9
use Yiisoft\Db\Exception\InvalidArgumentException;
10
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
11
use Yiisoft\Db\Tests\Support\Mock;
12
use Yiisoft\Db\Tests\Support\Stubs\ExpressionStub;
13
14
/**
15
 * @group db
16
 */
17
final class ExceptionTest extends TestCase
18
{
19
    private QueryBuilderInterface $queryBuilder;
20
    private Mock $mock;
21
22
    public function setUp(): void
23
    {
24
        parent::setUp();
25
26
        $this->mock = new Mock();
27
        $this->queryBuilder = $this->mock->queryBuilder();
28
    }
29
30
    public function tearDown(): void
31
    {
32
        parent::tearDown();
33
34
        unset($this->queryBuilder, $this->mock);
35
    }
36
37
    public function testaddDefaultValue(): void
38
    {
39
        $this->expectException(Exception::class);
40
        $this->expectExceptionMessage(
41
            'Yiisoft\Db\Tests\Support\Stubs\DDLQueryBuilder does not support adding default value constraints.'
42
        );
43
        $this->queryBuilder->addDefaultValue('name', 'table', 'column', 'value');
44
    }
45
46
    public function testBuilColumnStringException(): void
47
    {
48
        $this->expectException(InvalidArgumentException::class);
49
        $this->expectExceptionMessage(
50
            'Column name must be a string or an instance of ExpressionInterface.'
51
        );
52
53
        $this->queryBuilder->buildColumns([1]);
54
    }
55
56
    public function testBuildJoinException(): void
57
    {
58
        $this->expectException(Exception::class);
59
        $this->expectExceptionMessage(
60
            'A join clause must be specified as an array of join type, join table, and optionally join condition.'
61
        );
62
63
        $params = [];
64
        $this->queryBuilder->buildJoin([1], $params);
65
    }
66
67
    public function testCheckIntegrityException(): void
68
    {
69
        $this->expectException(Exception::class);
70
        $this->expectExceptionMessage(
71
            'Yiisoft\Db\Tests\Support\Stubs\DDLQueryBuilder does not support enabling/disabling integrity check.'
72
        );
73
74
        $this->queryBuilder->checkIntegrity('schema', 'table', true);
75
    }
76
77
    public function testGetExpressionBuilderException(): void
78
    {
79
        $this->expectException(InvalidArgumentException::class);
80
        $this->expectExceptionMessage(
81
            'Expression of class Yiisoft\Db\Tests\Support\Stubs\ExpressionStub can not be built in Yiisoft\Db\Tests\Support\Stubs\DQLQueryBuilder'
82
        );
83
84
        $this->queryBuilder->getExpressionBuilder(new ExpressionStub());
85
    }
86
}
87