1
|
|
|
<?php |
2
|
|
|
namespace Paro\EnvironmentParameters\Tests; |
3
|
|
|
|
4
|
|
|
use Paro\EnvironmentParameters\FileProcessor; |
5
|
|
|
|
6
|
|
|
class FileProcessorTest extends \PHPUnit_Framework_TestCase |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* @dataProvider processProvider |
10
|
|
|
* @param $env |
11
|
|
|
* @param $configs |
12
|
|
|
* @param $expected |
13
|
|
|
*/ |
14
|
|
|
public function testProcess($env, $configs, $expected) |
15
|
|
|
{ |
16
|
|
|
$fs = $this->getMockBuilder('Symfony\\Component\\Filesystem\\Filesystem') |
17
|
|
|
->setMethods(array('copy')) |
18
|
|
|
->getMock(); |
19
|
|
|
|
20
|
|
|
$fs->expects($this->once()) |
21
|
|
|
->method('copy') |
22
|
|
|
->with($this->equalTo($expected['source']), $this->equalTo($expected['destination'])) |
23
|
|
|
->willReturn(true); |
24
|
|
|
|
25
|
|
|
$fileHandler = $this->getMockBuilder('Paro\\EnvironmentParameters\\FileHandler') |
26
|
|
|
->disableOriginalConstructor() |
27
|
|
|
->setMethods(array('getArgumentValue')) |
28
|
|
|
->getMock(); |
29
|
|
|
|
30
|
|
|
$fileHandler->expects($this->once()) |
31
|
|
|
->method('getArgumentValue') |
32
|
|
|
->with($this->equalTo('env')) |
33
|
|
|
->willReturn($env); |
34
|
|
|
|
35
|
|
|
$io = $this->getMockBuilder('Composer\\IO\\NullIO') |
36
|
|
|
->disableOriginalConstructor() |
37
|
|
|
->setMethods(array('write')) |
38
|
|
|
->getMock(); |
39
|
|
|
|
40
|
|
|
$io->expects($this->once()) |
41
|
|
|
->method('write'); |
42
|
|
|
|
43
|
|
|
$fileProcessor = new FileProcessor($fs, $io, $fileHandler); |
44
|
|
|
|
45
|
|
|
$fileProcessor->process($configs); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function processProvider() |
49
|
|
|
{ |
50
|
|
|
return array( |
51
|
|
|
'simple config with name' => array( |
52
|
|
|
'env' => 'prod', |
53
|
|
|
'configs' => array( |
54
|
|
|
'build-folder' => 'build', |
55
|
|
|
'files' => array( |
56
|
|
|
'file' => 'key.{env}.p12', |
57
|
|
|
'name' => 'key.p12', |
58
|
|
|
), |
59
|
|
|
), |
60
|
|
|
'expected' => array( |
61
|
|
|
'source' => 'key.prod.p12', |
62
|
|
|
'destination' => 'build/key.p12' |
63
|
|
|
) |
64
|
|
|
), |
65
|
|
|
'simple config without name' => array( |
66
|
|
|
'env' => 'dev', |
67
|
|
|
'configs' => array( |
68
|
|
|
'build-folder' => 'builder', |
69
|
|
|
'files' => array( |
70
|
|
|
array( |
71
|
|
|
'file' => 'key.{env}.p12', |
72
|
|
|
) |
73
|
|
|
), |
74
|
|
|
), |
75
|
|
|
'expected' => array( |
76
|
|
|
'source' => 'key.dev.p12', |
77
|
|
|
'destination' => 'builder/key.dev.p12' |
78
|
|
|
) |
79
|
|
|
), |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|