ApropriateConnectionTraitUnitTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetApropriateConnectionBase() 0 15 1
A testGetApropriateConnectionMultiple() 0 16 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 ApropriateConnectionTraitUnitTest extends ConnectionTraitTests
9
{
10
11
    /**
12
     * Testing method getApropriateConnection
13
     */
14
    public function testGetApropriateConnectionMultiple(): void
15
    {
16
        // setup
17
        Conf::deleteConfigValue('default-db-connection/dsn');
18
        $this->setConnection('exact-db-connection');
19
        $mock = $this->getMock();
20
        $mock->setConnection(false);
21
        $mock->expects($this->once())
22
            ->method('constructConnection')
23
            ->willReturn(new PdoCrudMock());
24
25
        // test body
26
        $connection = $mock->getApropriateConnection('exact-db-connection');
27
28
        // assertions
29
        $this->assertInstanceOf(PdoCrudMock::class, $connection);
30
    }
31
32
    /**
33
     * Testing method getApropriateConnection without overriding of the method getApropriateConnection
34
     */
35
    public function testGetApropriateConnectionBase(): void
36
    {
37
        // setup
38
        $this->setConnection('default-db-connection');
39
        $mock = $this->getMockBase();
40
        $mock->setConnection(false);
41
        $mock->expects($this->once())
42
            ->method('constructConnection')
43
            ->willReturn(new PdoCrudMock());
44
45
        // test body
46
        $connection = $mock->getApropriateConnection('default-db-connection');
47
48
        // assertions
49
        $this->assertInstanceOf(PdoCrudMock::class, $connection);
50
    }
51
}
52