Passed
Pull Request — master (#31)
by Dmitriy
11:25
created

PathHelperTest::notExistsFilesProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 22
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Composer\Config\Tests\unit\Util;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Composer\Config\Utils\PathHelper;
9
10
final class PathHelperTest extends TestCase
11
{
12
    /**
13
     * @dataProvider notExistsFilesProvider()
14
     * @param string $pathToCheck
15
     * @param string $expected
16
     */
17
    public function testRealpath(string $pathToCheck, string $expected): void
18
    {
19
        $this->assertEquals($expected, PathHelper::realpath($pathToCheck));
20
    }
21
22
    public function notExistsFilesProvider(): array
23
    {
24
        return [
25
            [
26
                '/tmp/yii_temp_file',
27
                '/tmp/yii_temp_file',
28
            ],
29
            [
30
                '/tmp/yii/temp/../../file',
31
                '/tmp/file',
32
            ],
33
            [
34
                'C:\Temp\Yii\File',
35
                'C:/Temp/Yii/File',
36
            ],
37
            [
38
                'C:\Temp\Yii\..\..\File',
39
                'C:/File',
40
            ],
41
            [
42
                'C:\Temp\Yii\../../Temp/Yii/File',
43
                'C:/Temp/Yii/File',
44
            ],
45
        ];
46
    }
47
48
    /**
49
     * @dataProvider nonNormalizedPathsProvider()
50
     * @param string $pathToCheck
51
     * @param string $expected
52
     */
53
    public function testNormalize(string $pathToCheck, string $expected): void
54
    {
55
        $this->assertEquals($expected, PathHelper::normalize($pathToCheck));
56
    }
57
58
    public function nonNormalizedPathsProvider(): array
59
    {
60
        return [
61
            [
62
                '/tmp///////////',
63
                '/tmp',
64
            ],
65
            [
66
                '/tmp////////../',
67
                '/tmp/..',
68
            ],
69
            [
70
                'C:\\\\\Temp',
71
                'C:/Temp',
72
            ],
73
            [
74
                'C:\Temp\/File',
75
                'C:/Temp/File',
76
            ],
77
        ];
78
    }
79
}
80