Passed
Pull Request — master (#22)
by Dmitriy
37:40 queued 22:25
created

HelperTest::assertSameWithoutLE()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 3
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