Passed
Pull Request — master (#22)
by Dmitriy
28:42 queued 13:51
created

HelperTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 20
dl 0
loc 38
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testFixRemoveArrayKeys() 0 17 1
A testExportClosure() 0 10 1
A assertSameWithoutLE() 0 5 1
1
<?php
2
3
namespace Yiisoft\Composer\Config\Tests\Unit\Util;
4
5
use PHPUnit\Framework\TestCase;
6
use Yiisoft\Composer\Config\Util\Helper;
7
use Yiisoft\Composer\Config\Util\RemoveArrayKeys;
8
9
final class HelperTest extends TestCase
10
{
11
    public function testExportClosure(): void
12
    {
13
        $params = ['test' => 42];
14
        $closure = static function () use ($params) {
15
            return $params['test'];
16
        };
17
18
        $exportedClosure = Helper::exportVar($closure);
19
20
        $this->assertSameWithoutLE("static function () use (\$params) {\n            return \$params['test'];\n        }", $exportedClosure);
21
    }
22
23
    private function assertSameWithoutLE($expected, $actual, string $message = ''): void
24
    {
25
        $expected = preg_replace('/\R/', "\n", $expected);
26
        $actual = preg_replace('/\R/', "\n", $actual);
27
        $this->assertSame($expected, $actual, $message);
28
    }
29
30
    public function testFixRemoveArrayKeys(): void
31
    {
32
        $config = [
33
            'a' => '1',
34
            'b' => '2',
35
            'c' => [
36
                'd' => 4,
37
                'remove' => new RemoveArrayKeys(),
38
                'e' => 5,
39
            ],
40
        ];
41
42
        $fixed = $config;
43
        unset($fixed['c']['remove']);
44
        $fixed['c'] = array_values($fixed['c']);
45
46
        $this->assertEquals($fixed, Helper::fixConfig($config));
47
    }
48
}
49