Completed
Push — master ( a08ded...3d3abc )
by Pavel
53:29
created

PHPConstantsOutputAdapterTest::testProcess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 8
nc 1
nop 4
1
<?php
2
namespace Paro\EnvironmentParameters\Tests\Adapter\Ouput;
3
4
use Paro\EnvironmentParameters\Adapter\Output\PHPConstantsOutputAdapter;
5
use org\bovigo\vfs\vfsStream;
6
use org\bovigo\vfs\vfsStreamDirectory;
7
use org\bovigo\vfs\vfsStreamWrapper;
8
9
class PHPConstantsOutputAdapterTest extends \PHPUnit_Framework_TestCase {
10
11
	/**
12
	 * @var PHPConstantsOutputAdapter
13
	 */
14
	private $PHPConstantsOutputAdapter;
15
16
	protected function setUp() {
17
		parent::setUp();
18
		$this->PHPConstantsOutputAdapter = new PHPConstantsOutputAdapter();
19
	}
20
21
	/**
22
	 * @param $parameters
23
	 * @param $fileName
24
	 * @param $env
25
	 * @param $expected
26
	 *
27
	 * @dataProvider processProvider
28
	 */
29
	public function testProcess($parameters, $fileName, $env, $expected) {
30
		vfsStreamWrapper::register();
31
		vfsStreamWrapper::setRoot(new vfsStreamDirectory('root'));
32
33
		$fileNameVFS = vfsStream::url('root/' . $fileName);
34
		$this->PHPConstantsOutputAdapter->process($parameters, $fileNameVFS, $env);
35
		$actual = file_get_contents(vfsStream::url('root/' . $fileName));
36
		$this->assertEquals($expected, $actual);
37
		vfsStreamWrapper::unregister();
38
	}
39
40
	public function processProvider() {
41
		return array(
42
			'number' => array(
43
				'parameters' => array(
44
					'PARAMETER' => 1100,
45
					'PARAMETER1' => 1.100
46
				),
47
				'fileName' => 'parameters.php',
48
				'env' => 'devlike/test',
49
				'expected' => sprintf("%s\n%s\n%s\n",
50
					sprintf("<?php\n/** This file is auto-generated during the build process of '%s' environment at %s **/", 'devlike/test', date(DATE_ATOM)),
51
					"define('PARAMETER', 1100);",
52
					"define('PARAMETER1', 1.1);"
53
				),
54
55
			),
56
			'array' => array(
57
				'parameters' => array(
58
					'PARAMETER' => array(100, 200, 300, "aaa'", array("'\"'"))
59
				),
60
				'fileName' => 'parameters.php',
61
				'env' => 'devlike/test',
62
				'expected' => sprintf("%s\n%s\n",
63
					sprintf("<?php\n/** This file is auto-generated during the build process of '%s' environment at %s **/", 'devlike/test', date(DATE_ATOM)),
64
					sprintf("define('PARAMETER', '%s');", "a:5:{i:0;i:100;i:1;i:200;i:2;i:300;i:3;s:4:\"aaa\\'\";i:4;a:1:{i:0;s:3:\"\\'\"\\'\";}}")
65
				),
66
67
			),
68
		);
69
	}
70
}
71