Completed
Push — master ( c84e82...c18a23 )
by Andrii
21:10 queued 06:15
created

HelperTest::testFixRemoveArrayKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 17
rs 9.9
cc 1
nc 1
nop 0
1
<?php
2
3
namespace hiqdev\composer\config\tests\unit;
4
5
use hiqdev\composer\config\utils\Helper;
6
use hiqdev\composer\config\utils\RemoveArrayKeys;
7
use PHPUnit\Framework\TestCase;
8
9
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()
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