/
PhpFormatterTest.php
141 lines (136 loc) · 2.97 KB
/
PhpFormatterTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\App\Test\Unit\DeploymentConfig\Writer;
use Magento\Framework\App\DeploymentConfig\Writer\PhpFormatter;
class PhpFormatterTest extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvider formatWithCommentDataProvider
* @param string[] $data
* @param string[] $comments
* @param string $expectedResult
*/
public function testFormat($data, $comments, $expectedResult)
{
$formatter = new PhpFormatter();
$this->assertEquals($expectedResult, $formatter->format($data, $comments));
}
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function formatWithCommentDataProvider()
{
$array = [
'ns1' => [
's1' => [
's11',
's12'
],
's2' => [
's21',
's22'
],
],
'ns2' => [
's1' => [
's11'
],
],
'ns3' => 'just text',
'ns4' => 'just text'
];
$comments1 = ['ns2' => 'comment for namespace 2'];
$comments2 = [
'ns1' => 'comment for\' namespace 1',
'ns2' => "comment for namespace 2.\nNext comment for' namespace 2",
'ns3' => 'comment for" namespace 3',
'ns4' => 'comment for namespace 4',
'ns5' => 'comment for unexisted namespace 5',
];
$expectedResult1 = <<<TEXT
<?php
return array (
'ns1' =>
array (
's1' =>
array (
0 => 's11',
1 => 's12',
),
's2' =>
array (
0 => 's21',
1 => 's22',
),
),
/**
* For the section: ns2
* comment for namespace 2
*/
'ns2' =>
array (
's1' =>
array (
0 => 's11',
),
),
'ns3' => 'just text',
'ns4' => 'just text',
);
TEXT;
$expectedResult2 = <<<TEXT
<?php
return array (
/**
* For the section: ns1
* comment for' namespace 1
*/
'ns1' =>
array (
's1' =>
array (
0 => 's11',
1 => 's12',
),
's2' =>
array (
0 => 's21',
1 => 's22',
),
),
/**
* For the section: ns2
* comment for namespace 2.
* Next comment for' namespace 2
*/
'ns2' =>
array (
's1' =>
array (
0 => 's11',
),
),
/**
* For the section: ns3
* comment for" namespace 3
*/
'ns3' => 'just text',
/**
* For the section: ns4
* comment for namespace 4
*/
'ns4' => 'just text',
);
TEXT;
return [
['string', [], "<?php\nreturn 'string';\n"],
['string', ['comment'], "<?php\nreturn 'string';\n"],
[$array, [], "<?php\nreturn " . var_export($array, true) . ";\n"],
[$array, $comments1, $expectedResult1],
[$array, $comments2, $expectedResult2],
];
}
}