Passed
Pull Request — master (#53)
by Alexander
13:52
created

ConfigTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
dl 0
loc 36
c 1
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigValue() 0 6 2
A setUp() 0 3 1
A testConfig() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Composer\Config\Tests\Integration\Tests\Config;
6
7
use Closure;
8
use Yiisoft\Composer\Config\Tests\Integration\Tests\Helper\LiterallyCallback;
9
use Yiisoft\Composer\Config\Tests\Integration\Tests\PluginTestCase;
10
11
abstract class ConfigTest extends PluginTestCase
12
{
13
    protected function setUp(): void
14
    {
15
        $this->registerConfig($this->getDefaultConfigName());
16
    }
17
18
    /**
19
     * @dataProvider configProvider()
20
     * @param string $name
21
     * @param $expectedValue
22
     * @param string|null $configName
23
     */
24
    public function testConfig(string $name, $expectedValue, string $configName = null): void
25
    {
26
        $actualValue = $this->getConfigValue($name, $configName);
27
        if ($expectedValue instanceof Closure) {
28
            $expectedValue($actualValue);
29
            return;
30
        }
31
        if ($expectedValue instanceof LiterallyCallback) {
32
            $expectedValue = $expectedValue->getCallback();
33
        }
34
35
        $this->assertEquals($expectedValue, $actualValue);
36
    }
37
38
    protected function getConfigValue(string $name, string $configName = null)
39
    {
40
        if ($configName !== null) {
41
            $this->registerConfig($configName);
42
        }
43
        return $this->getFromConfig($configName ?? $this->getDefaultConfigName(), $name);
44
    }
45
46
    abstract protected function getDefaultConfigName(): string;
47
}
48