1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace Tests ;
4
6
5
7
use InvalidArgumentException ;
9
11
use PHPUnit \Framework \TestCase ;
10
12
11
13
/**
14
+ * Class DiffTest
15
+ *
12
16
*
17
+ * @package Tests\Diff
18
+ * @author Mario Brandt <[email protected] >
19
+ * @copyright (c) 2023 Mario Brandt
20
+ * @license New BSD License http://www.opensource.org/licenses/bsd-license.php
21
+ * @version 2.4.0
22
+ * @link https://github.com/JBlond/php-diff
13
23
*/
14
24
class DiffTest extends TestCase
15
25
{
16
26
/**
27
+ * Store the Diff object
17
28
* @var Diff
18
29
*/
19
30
protected $ diff ;
20
31
21
32
/**
22
33
* @param string|null $name
23
34
* @param array $data
24
- * @param $dataName
35
+ * @param string $dataName
25
36
*/
26
- public function __construct (?string $ name = null , array $ data = [], $ dataName = '' )
37
+ public function __construct (?string $ name = null , array $ data = [], string $ dataName = '' )
27
38
{
28
39
parent ::__construct ($ name , $ data , $ dataName );
29
40
$ this ->diff = new Diff (
@@ -33,9 +44,10 @@ public function __construct(?string $name = null, array $data = [], $dataName =
33
44
}
34
45
35
46
/**
47
+ * Test the grouped OP codes
36
48
* @return void
37
49
*/
38
- public function testGetGroupedOpCodes ()
50
+ public function testGetGroupedOpCodes (): void
39
51
{
40
52
$ this ->assertEquals (
41
53
[
@@ -69,23 +81,45 @@ public function testGetGroupedOpCodes()
69
81
);
70
82
}
71
83
72
- public function testGetVersion1 ()
84
+ /**
85
+ * Test the getter function
86
+ * @return void
87
+ */
88
+ public function testGetVersion1 (): void
73
89
{
90
+ $ compareData = file ('tests/resources/a.txt ' );
91
+ $ compareData = array_map (static function ($ value ) {
92
+ return str_replace ("\n" , '' , $ value );
93
+ }, $ compareData );
94
+ $ compareData [] = "" ;
74
95
$ this ->assertEquals (
75
- file ( ' tests/resources/a.txt ' ) ,
96
+ $ compareData ,
76
97
$ this ->diff ->getVersion1 ()
77
98
);
78
99
}
79
100
80
- public function testGetVersion2 ()
101
+ /**
102
+ * Test the getter function
103
+ * @return void
104
+ */
105
+ public function testGetVersion2 (): void
81
106
{
107
+ $ compareData = file ('tests/resources/b.txt ' );
108
+ $ compareData = array_map (static function ($ value ) {
109
+ return str_replace ("\n" , '' , $ value );
110
+ }, $ compareData );
111
+ $ compareData [] = "" ;
82
112
$ this ->assertEquals (
83
- file ( ' tests/resources/b.txt ' ) ,
113
+ $ compareData ,
84
114
$ this ->diff ->getVersion2 ()
85
115
);
86
116
}
87
117
88
- public function testGetArgumentType ()
118
+ /**
119
+ * Test the kind of variable.
120
+ * @return void
121
+ */
122
+ public function testGetArgumentType (): void
89
123
{
90
124
$ this ->assertEquals (
91
125
[
@@ -101,32 +135,45 @@ public function testGetArgumentType()
101
135
$ this ->diff ->getArgumentType (123 );
102
136
}
103
137
104
- public function testRender ()
138
+ /**
139
+ * Test the rendering setter
140
+ * @return void
141
+ */
142
+ public function testRender (): void
105
143
{
106
144
$ renderer = new SideBySide ();
107
- $ this ->assertEquals (
108
- file_get_contents ('tests/resources/htmlSideBySide.txt ' ),
109
- $ this ->diff ->render ($ renderer )
145
+ $ this ->assertStringEqualsFile (
146
+ 'tests/resources/htmlSideBySide.txt ' , $ this ->diff ->render ($ renderer )
110
147
);
111
148
}
112
149
113
- public function testGetSimilarity ()
150
+ /**
151
+ * Test the similarity ratio of the two sequences
152
+ * @return void
153
+ */
154
+ public function testGetSimilarity (): void
114
155
{
115
156
$ this ->assertEquals (
116
157
0.7272727272727273 ,
117
158
$ this ->diff ->getSimilarity ()
118
159
);
119
160
}
120
161
121
- public function testIsIdentical ()
162
+ /**
163
+ * @return void
164
+ */
165
+ public function testIsIdentical (): void
122
166
{
123
167
$ this ->assertEquals (
124
168
false ,
125
169
$ this ->diff ->isIdentical ()
126
170
);
127
171
}
128
172
129
- public function testGetStatistics ()
173
+ /**
174
+ * @return void
175
+ */
176
+ public function testGetStatistics (): void
130
177
{
131
178
$ this ->assertEquals (
132
179
[
@@ -139,7 +186,10 @@ public function testGetStatistics()
139
186
);
140
187
}
141
188
142
- public function testGetArrayRange ()
189
+ /**
190
+ * @return void
191
+ */
192
+ public function testGetArrayRange (): void
143
193
{
144
194
$ this ->assertEquals (
145
195
[5 , 6 ],
0 commit comments