11<?php
22
3+ declare (strict_types=1 );
4+
35namespace Tests ;
46
57use InvalidArgumentException ;
911use PHPUnit \Framework \TestCase ;
1012
1113/**
14+ * Class DiffTest
15+ *
1216 *
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
1323 */
1424class DiffTest extends TestCase
1525{
1626 /**
27+ * Store the Diff object
1728 * @var Diff
1829 */
1930 protected $ diff ;
2031
2132 /**
2233 * @param string|null $name
2334 * @param array $data
24- * @param $dataName
35+ * @param string $dataName
2536 */
26- public function __construct (?string $ name = null , array $ data = [], $ dataName = '' )
37+ public function __construct (?string $ name = null , array $ data = [], string $ dataName = '' )
2738 {
2839 parent ::__construct ($ name , $ data , $ dataName );
2940 $ this ->diff = new Diff (
@@ -33,9 +44,10 @@ public function __construct(?string $name = null, array $data = [], $dataName =
3344 }
3445
3546 /**
47+ * Test the grouped OP codes
3648 * @return void
3749 */
38- public function testGetGroupedOpCodes ()
50+ public function testGetGroupedOpCodes (): void
3951 {
4052 $ this ->assertEquals (
4153 [
@@ -69,23 +81,45 @@ public function testGetGroupedOpCodes()
6981 );
7082 }
7183
72- public function testGetVersion1 ()
84+ /**
85+ * Test the getter function
86+ * @return void
87+ */
88+ public function testGetVersion1 (): void
7389 {
90+ $ compareData = file ('tests/resources/a.txt ' );
91+ $ compareData = array_map (static function ($ value ) {
92+ return str_replace ("\n" , '' , $ value );
93+ }, $ compareData );
94+ $ compareData [] = "" ;
7495 $ this ->assertEquals (
75- file ( ' tests/resources/a.txt ' ) ,
96+ $ compareData ,
7697 $ this ->diff ->getVersion1 ()
7798 );
7899 }
79100
80- public function testGetVersion2 ()
101+ /**
102+ * Test the getter function
103+ * @return void
104+ */
105+ public function testGetVersion2 (): void
81106 {
107+ $ compareData = file ('tests/resources/b.txt ' );
108+ $ compareData = array_map (static function ($ value ) {
109+ return str_replace ("\n" , '' , $ value );
110+ }, $ compareData );
111+ $ compareData [] = "" ;
82112 $ this ->assertEquals (
83- file ( ' tests/resources/b.txt ' ) ,
113+ $ compareData ,
84114 $ this ->diff ->getVersion2 ()
85115 );
86116 }
87117
88- public function testGetArgumentType ()
118+ /**
119+ * Test the kind of variable.
120+ * @return void
121+ */
122+ public function testGetArgumentType (): void
89123 {
90124 $ this ->assertEquals (
91125 [
@@ -101,32 +135,45 @@ public function testGetArgumentType()
101135 $ this ->diff ->getArgumentType (123 );
102136 }
103137
104- public function testRender ()
138+ /**
139+ * Test the rendering setter
140+ * @return void
141+ */
142+ public function testRender (): void
105143 {
106144 $ 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 )
110147 );
111148 }
112149
113- public function testGetSimilarity ()
150+ /**
151+ * Test the similarity ratio of the two sequences
152+ * @return void
153+ */
154+ public function testGetSimilarity (): void
114155 {
115156 $ this ->assertEquals (
116157 0.7272727272727273 ,
117158 $ this ->diff ->getSimilarity ()
118159 );
119160 }
120161
121- public function testIsIdentical ()
162+ /**
163+ * @return void
164+ */
165+ public function testIsIdentical (): void
122166 {
123167 $ this ->assertEquals (
124168 false ,
125169 $ this ->diff ->isIdentical ()
126170 );
127171 }
128172
129- public function testGetStatistics ()
173+ /**
174+ * @return void
175+ */
176+ public function testGetStatistics (): void
130177 {
131178 $ this ->assertEquals (
132179 [
@@ -139,7 +186,10 @@ public function testGetStatistics()
139186 );
140187 }
141188
142- public function testGetArrayRange ()
189+ /**
190+ * @return void
191+ */
192+ public function testGetArrayRange (): void
143193 {
144194 $ this ->assertEquals (
145195 [5 , 6 ],
0 commit comments