ConnectionTraitGetConnectionWithExceptionUnitTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 61
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConnectionExceptionDataProvider() 0 31 1
A testGetConnectionException() 0 10 1
1
<?php
2
namespace Mezon\PdoCrud\Tests;
3
4
use Mezon\Conf\Conf;
5
use Mezon\PdoCrud\PdoCrud;
6
use PHPUnit\Framework\TestCase;
7
8
class ConnectionTraitGetConnectionWithExceptionUnitTest extends ConnectionTraitTests
9
{
10
11
    /**
12
     * Data provider for the test testGetConnectionException
13
     *
14
     * @return array testing data
15
     */
16
    public function getConnectionExceptionDataProvider(): array
17
    {
18
        return [
19
            [
20
                function () {
21
                    Conf::deleteConfigValue('default-db-connection/dsn');
22
                    $this->setUser('user');
23
                    $this->setPassword('password');
24
                    $mock = $this->getMock();
25
                    $mock->setConnection(false);
26
                    return $mock;
27
                }
28
            ],
29
            [
30
                function () {
31
                    $this->setDsn('dsn');
32
                    Conf::deleteConfigValue('default-db-connection/user');
33
                    $this->setPassword('password');
34
                    $mock = $this->getMock();
35
                    $mock->setConnection(false);
36
                    return $mock;
37
                }
38
            ],
39
            [
40
                function () {
41
                    $this->setDsn('dsn');
42
                    $this->setUser('user');
43
                    Conf::deleteConfigValue('default-db-connection/password');
44
                    $mock = $this->getMock();
45
                    $mock->setConnection(false);
46
                    return $mock;
47
                }
48
            ]
49
        ];
50
    }
51
52
    /**
53
     * Testing exception
54
     *
55
     * @param callable $setup
56
     *            setup method
57
     * @dataProvider getConnectionExceptionDataProvider
58
     */
59
    public function testGetConnectionException(callable $setup): void
60
    {
61
        // assertions
62
        $this->expectException(\Exception::class);
63
64
        // setup
65
        $connection = $setup();
66
67
        // test body
68
        $connection->getConnection();
69
    }
70
}
71