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