Passed
Push — master ( 9b7912...982aac )
by Janis
02:15
created

ConnectionFeatureContext   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A iHaveExistingConnectionConfig() 0 14 2
A iShouldHaveConnection() 0 3 1
A iAddConnectionConfigToConnectionPool() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Janisbiz\LightOrm\Tests\Behat\Features\Connection;
4
5
use Janisbiz\LightOrm\Connection\ConnectionConfigInterface;
6
use Janisbiz\LightOrm\Dms\MySQL\Connection\ConnectionConfig as MySQLConnectionConfig;
7
use Janisbiz\LightOrm\Tests\Behat\Bootstrap\AbstractFeatureContext;
8
9
class ConnectionFeatureContext extends AbstractFeatureContext
10
{
11
    /**
12
     * @var ConnectionConfigInterface
13
     */
14
    private $connectionConfig;
15
16
    /**
17
     * @Given /^I have existing connection config "(\w+)"$/
18
     *
19
     * @param string $connectionName
20
     *
21
     * @throws \Exception
22
     */
23
    public function iHaveExistingConnectionConfig(string $connectionName)
24
    {
25
        $connectionConfigArray = $this->getConnectionConfig($connectionName);
26
27
        switch ($connectionConfigArray['adapter']) {
28
            case MySQLConnectionConfig::ADAPTER:
29
                $this->connectionConfig = new MySQLConnectionConfig(
30
                    $connectionConfigArray['host'],
31
                    $connectionConfigArray['username'],
32
                    $connectionConfigArray['password'],
33
                    $connectionConfigArray['dbname']
34
                );
35
36
                break;
37
        }
38
    }
39
40
    /**
41
     * @When I add connection config to connection pool
42
     */
43
    public function iAddConnectionConfigToConnectionPool()
44
    {
45
        $this->connectionPool->addConnectionConfig($this->connectionConfig);
46
    }
47
48
    /**
49
     * @Then /^I should have connection "(\w+)"$/
50
     *
51
     * @param string $connectionName
52
     */
53
    public function iShouldHaveConnection(string $connectionName)
54
    {
55
        $this->connectionPool->getConnection($connectionName);
56
    }
57
}
58