DriverConfigurationInterfaceTest::dataProvider()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 75
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 50
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 75
rs 9.0909

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Doctrine\Test\Unit\Configuration\Driver;
15
16
use Micro\Framework\Kernel\Configuration\DefaultApplicationConfiguration;
17
use Micro\Plugin\Doctrine\Configuration\Driver\DriverConfigurationInterface;
18
use Micro\Plugin\Doctrine\Configuration\Driver\PdoMySqlConfiguration;
19
use Micro\Plugin\Doctrine\Configuration\Driver\PdoPgSqlConfiguration;
20
use Micro\Plugin\Doctrine\Configuration\Driver\PdoSqliteDriverConfiguration;
21
use PHPUnit\Framework\TestCase;
22
23
class DriverConfigurationInterfaceTest extends TestCase
24
{
25
    /**
26
     * @dataProvider dataProvider
27
     */
28
    public function testDrivers(string $adapterClass, array $adapterConfig, array $toArrayExcepted)
29
    {
30
        $arrayCfg = [];
31
        foreach ($adapterConfig as $cfgName => $cfgValue) {
32
            $arrayCfg['ORM_TEST_'.mb_strtoupper($cfgName)] = $cfgValue;
33
        }
34
35
        $appCfg = new DefaultApplicationConfiguration($arrayCfg);
36
37
        /** @var DriverConfigurationInterface $cfg */
38
        $cfg = new $adapterClass(
39
            $appCfg,
40
            'test'
41
        );
42
43
        $this->assertInstanceOf(DriverConfigurationInterface::class, $cfg);
44
        $this->assertEquals($toArrayExcepted, $cfg->getParameters());
45
    }
46
47
    public function dataProvider()
48
    {
49
        $user = 'demo0';
50
        $password = 'pwd';
51
        $db = 'test';
52
        $port = '555';
53
        $host = 'somehost';
54
        $path = '/dev/null';
55
56
        return [
57
            [
58
                PdoMySqlConfiguration::class,
59
                [
60
                    'host' => $host,
61
                    'port' => $port,
62
                    'DATABASE' => $db,
63
                    'user' => $user,
64
                    'password' => $password,
65
                ],
66
                [
67
                    'driver' => 'pdo_mysql',
68
                    'user' => $user,
69
                    'host' => $host,
70
                    'password' => $password,
71
                    'port' => (int) $port,
72
                    'dbname' => $db,
73
                ],
74
            ],
75
            [
76
                PdoPgSqlConfiguration::class,
77
                [
78
                    'host' => $host,
79
                    'port' => $port,
80
                    'DATABASE' => $db,
81
                    'user' => $user,
82
                    'password' => $password,
83
                ],
84
                [
85
                    'driver' => 'pdo_pgsql',
86
                    'user' => $user,
87
                    'host' => $host,
88
                    'password' => $password,
89
                    'port' => (int) $port,
90
                    'dbname' => $db,
91
                ],
92
            ],
93
            [
94
                PdoSqliteDriverConfiguration::class,
95
                [
96
                    'path' => $path,
97
                    'in_memory' => false,
98
                    'user' => $user,
99
                    'password' => $password,
100
                ],
101
                [
102
                    'driver' => 'pdo_sqlite',
103
                    'path' => $path,
104
                    'user' => $user,
105
                    'password' => $password,
106
                    'memory' => false,
107
                ],
108
            ],
109
            [
110
                PdoSqliteDriverConfiguration::class,
111
                [
112
                    'path' => $path,
113
                    'in_memory' => true,
114
                    'user' => $user,
115
                    'password' => $password,
116
                ],
117
                [
118
                    'driver' => 'pdo_sqlite',
119
                    'user' => $user,
120
                    'password' => $password,
121
                    'memory' => true,
122
                ],
123
            ],
124
        ];
125
    }
126
}
127