Completed
Push — master ( 5f8cc7...76d085 )
by Pavel
02:39
created

FileHandlerTest::testResolvePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
namespace Paro\BuildParametersHandler\Tests;
3
4
use Paro\BuildParametersHandler\FileHandler;
5
use Symfony\Component\Filesystem\Filesystem;
6
7
class FileHandlerTest extends \PHPUnit_Framework_TestCase
8
{
9
10
    /**
11
     * @var FileHandler
12
     */
13
    private $fileHandler;
14
15
    protected function setUp()
16
    {
17
        parent::setUp();
18
        $fs = new Filesystem();
19
        $this->fileHandler = new FileHandler($fs, array('--env=prod'));
20
    }
21
22
    /**
23
     * @dataProvider preparePathProvider
24
     * @param $path
25
     * @param $expected
26
     */
27
    public function testPreparePath($path, $expected)
28
    {
29
        $this->assertEquals($expected, $this->fileHandler->preparePath($path));
30
    }
31
32
    public function preparePathProvider()
33
    {
34
        return array(
35
            'without env parameter' => array(
36
                'path' => 'folder/parameters.yml',
37
                'expected' => 'folder/parameters.yml'
38
            ),
39
            'with env parameter' => array(
40
                'path' => '{env}/parameters.yml',
41
                'expected' => 'prod/parameters.yml'
42
            ),
43
            'with different parameter' => array(
44
                'path' => '{enev}/parameters.yml',
45
                'expected' => '{enev}/parameters.yml'
46
            )
47
        );
48
    }
49
50
    /**
51
     * @param $name
52
     * @param $expected
53
     *
54
     * @dataProvider argumentValueProvider
55
     */
56
    public function testArgumentValue($name, $expected)
57
    {
58
        $this->assertEquals($expected, $this->fileHandler->getArgumentValue($name));
59
    }
60
61
    public function argumentValueProvider()
62
    {
63
        return array(
64
            'env found' => array(
65
                'name' => 'env',
66
                'expected' => 'prod',
67
            ),
68
            '--env not found' => array(
69
                'name' => '--env',
70
                'expected' => false,
71
            )
72
        );
73
    }
74
75
76
    /**
77
     * @param $currentPath
78
     * @param $importPath
79
     * @param $expected
80
     * @dataProvider resolvePathProvider
81
     */
82
    public function testResolvePath($currentPath, $importPath, $expected)
83
    {
84
        $this->assertEquals($expected, $this->fileHandler->resolvePath($currentPath, $importPath));
85
    }
86
87
    public function resolvePathProvider()
88
    {
89
        return array(
90
            'parent path' => array(
91
                'currentPath' => '/home/user/dir/current.yml',
92
                'importPath' => '../import.yml',
93
                'expected' => '/home/user/dir/../import.yml',
94
            ),
95
            'current path' => array(
96
                'currentPath' => '/home/user/dir/current.yml',
97
                'importPath' => './import.yml',
98
                'expected' => '/home/user/dir/./import.yml',
99
            ),
100
101
            'current simple path' => array(
102
                'currentPath' => '/home/user/dir/current.yml',
103
                'importPath' => 'import.yml',
104
                'expected' => '/home/user/dir/import.yml',
105
            ),
106
            'absolute path' => array(
107
                'currentPath' => '/home/user/dir/current.yml',
108
                'importPath' => '/import.yml',
109
                'expected' => '/import.yml',
110
            )
111
        );
112
    }
113
114
    public function testInitDirectory()
115
    {
116
        $dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'testInitDirectory';
117
118
        if (is_dir($dir)) {
119
            rmdir($dir);
120
        }
121
122
        //currently doesn't exists
123
        $this->assertFalse(is_dir($dir));
124
125
        //create one
126
        $this->fileHandler->initDirectory($dir);
127
        $this->assertTrue(is_dir($dir));
128
129
        //if is existing
130
        $this->fileHandler->initDirectory($dir);
131
        $this->assertTrue(is_dir($dir));
132
133
    }
134
135
}
136