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