FileProcessorTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 81
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testProcess() 0 37 1
B processProvider() 0 34 1
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', 'exists'))
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
        $fs->expects($this->once())
26
            ->method('exists')
27
            ->willReturn(true);
28
29
        $fileHandler = $this->getMockBuilder('Paro\\EnvironmentParameters\\FileHandler')
30
            ->setConstructorArgs(array($fs, array()))
31
            ->setMethods(array('getArgumentValue'))
32
            ->getMock();
33
34
        $fileHandler->expects($this->atLeastOnce())
35
            ->method('getArgumentValue')
36
            ->with($this->equalTo('env'))
37
            ->willReturn($env);
38
39
        $io = $this->getMockBuilder('Composer\\IO\\NullIO')
40
            ->disableOriginalConstructor()
41
            ->setMethods(array('write'))
42
            ->getMock();
43
44
        $io->expects($this->once())
45
            ->method('write');
46
47
        $fileProcessor = new FileProcessor($fs, $io, $fileHandler);
48
49
        $fileProcessor->process($configs);
50
    }
51
52
    public function processProvider()
53
    {
54
        return array(
55
            'simple config with name' => array(
56
                'env' => 'prod',
57
                'configs' => array(
58
                    'build-folder' => 'build',
59
                    'files' => array(
60
                        'file' => 'key.{env}.p12',
61
                        'name' => 'key.p12',
62
                    ),
63
                ),
64
                'expected' => array(
65
                    'source' => 'key.prod.p12',
66
                    'destination' => 'build/key.p12'
67
                )
68
            ),
69
            'simple config without name' => array(
70
                'env' => 'dev',
71
                'configs' => array(
72
                    'build-folder' => 'builder',
73
                    'files' => array(
74
                        array(
75
                            'file' => 'key.{env}.p12',
76
                        )
77
                    ),
78
                ),
79
                'expected' => array(
80
                    'source' => 'key.dev.p12',
81
                    'destination' => 'builder/key.dev.p12'
82
                )
83
            ),
84
        );
85
    }
86
}
87