Skip to content
This repository
Browse code

Removed Constants from Diff, put into tests for readability

  • Loading branch information...
commit 5b2cb846603bfa60831ead027cb2e71282c542e8 1 parent f68d44e
Philipp Scheit authored
25  PHPUnit/Util/Diff.php
@@ -59,11 +59,6 @@
59 59
  */
60 60
 class PHPUnit_Util_Diff
61 61
 {
62  
-  
63  
-    const REMOVED = 2;
64  
-    const ADDED = 1;
65  
-    const OLD = 0;
66  
-    
67 62
     /**
68 63
      * Returns the diff between two arrays or strings as string.
69 64
      *
@@ -81,7 +76,7 @@ public static function diff($from, $to)
81 76
         $old   = array();
82 77
 
83 78
         foreach ($diff as $line) {
84  
-            if ($line[1] === self::OLD) {
  79
+            if ($line[1] === 0 /* OLD */) {
85 80
                 if ($inOld === FALSE) {
86 81
                     $inOld = $i;
87 82
                 }
@@ -120,11 +115,11 @@ public static function diff($from, $to)
120 115
                 $newChunk = FALSE;
121 116
             }
122 117
 
123  
-            if ($diff[$i][1] === self::ADDED) {
  118
+            if ($diff[$i][1] === 1 /* ADDED */) {
124 119
                 $buffer .= '+' . $diff[$i][0] . "\n";
125 120
             }
126 121
 
127  
-            else if ($diff[$i][1] === self::REMOVED) {
  122
+            else if ($diff[$i][1] === 2 /* REMOVED */) {
128 123
                 $buffer .= '-' . $diff[$i][0] . "\n";
129 124
             }
130 125
 
@@ -195,7 +190,7 @@ public static function diffToArray($from, $to) {
195 190
         $line = 0;
196 191
 
197 192
         foreach ($start as $token) {
198  
-            $diff[] = array($token, self::OLD);
  193
+            $diff[] = array($token, 0 /* OLD */);
199 194
         }
200 195
 
201 196
         reset($from);
@@ -203,29 +198,29 @@ public static function diffToArray($from, $to) {
203 198
 
204 199
         foreach ($common as $token) {
205 200
             while ((($fromToken = reset($from)) !== $token)) {
206  
-                $diff[] = array(array_shift($from), self::REMOVED);
  201
+                $diff[] = array(array_shift($from), 2 /* REMOVED */);
207 202
             }
208 203
 
209 204
             while ((($toToken = reset($to)) !== $token)) {
210  
-                $diff[] = array(array_shift($to), self::ADDED);
  205
+                $diff[] = array(array_shift($to), 1 /* ADDED */);
211 206
             }
212 207
 
213  
-            $diff[] = array($token, self::OLD);
  208
+            $diff[] = array($token, 0 /* OLD */);
214 209
 
215 210
             array_shift($from);
216 211
             array_shift($to);
217 212
         }
218 213
 
219 214
         while (($token = array_shift($from)) !== NULL) {
220  
-            $diff[] = array($token, self::REMOVED);
  215
+            $diff[] = array($token, 2 /* REMOVED */);
221 216
         }
222 217
 
223 218
         while (($token = array_shift($to)) !== NULL) {
224  
-            $diff[] = array($token, self::ADDED);
  219
+            $diff[] = array($token, 1 /* ADDED */);
225 220
         }
226 221
 
227 222
         foreach ($end as $token) {
228  
-            $diff[] = array($token, self::OLD);
  223
+            $diff[] = array($token, 0 /* OLD */);
229 224
         }
230 225
         
231 226
         return $diff;
37  Tests/Util/DiffTest.php
@@ -55,6 +55,11 @@
55 55
  */
56 56
 class Util_DiffTest extends PHPUnit_Framework_TestCase
57 57
 {
  58
+  
  59
+   const REMOVED = 2;
  60
+   const ADDED = 1;
  61
+   const OLD = 0;
  62
+   
58 63
     /**
59 64
      * @covers PHPUnit_Util_Diff::diff
60 65
      */
@@ -72,8 +77,8 @@ public function testComparisonErrorMessage()
72 77
     public function testComparisonErrorMessage_toArray()
73 78
     {
74 79
         $diff = array();
75  
-        $diff[] = array('a', PHPUnit_Util_DIFF::REMOVED);
76  
-        $diff[] = array('b', PHPUnit_Util_DIFF::ADDED);
  80
+        $diff[] = array('a', self::REMOVED);
  81
+        $diff[] = array('b', self::ADDED);
77 82
         
78 83
         $this->assertEquals(
79 84
           $diff,
@@ -98,8 +103,8 @@ public function testComparisonErrorStartSame()
98 103
     public function testComparisonErrorStartSame_toArray()
99 104
     {
100 105
         $diff = array();
101  
-        $diff[] = array('ba', PHPUnit_Util_DIFF::REMOVED);
102  
-        $diff[] = array('bc', PHPUnit_Util_DIFF::ADDED);
  106
+        $diff[] = array('ba', self::REMOVED);
  107
+        $diff[] = array('bc', self::ADDED);
103 108
         
104 109
         $this->assertEquals(
105 110
           $diff,
@@ -124,8 +129,8 @@ public function testComparisonErrorEndSame()
124 129
     public function testComparisonErrorEndSame_toArray()
125 130
     {
126 131
         $diff = array();
127  
-        $diff[] = array('ab', PHPUnit_Util_DIFF::REMOVED);
128  
-        $diff[] = array('cb', PHPUnit_Util_DIFF::ADDED);
  132
+        $diff[] = array('ab', self::REMOVED);
  133
+        $diff[] = array('cb', self::ADDED);
129 134
         
130 135
         $this->assertEquals(
131 136
           $diff,
@@ -150,8 +155,8 @@ public function testComparisonErrorStartAndEndSame()
150 155
     public function testComparisonErrorStartAndEndSame_toArray()
151 156
     {
152 157
         $diff = array();
153  
-        $diff[] = array('abc', PHPUnit_Util_DIFF::REMOVED);
154  
-        $diff[] = array('adc', PHPUnit_Util_DIFF::ADDED);
  158
+        $diff[] = array('abc', self::REMOVED);
  159
+        $diff[] = array('adc', self::ADDED);
155 160
         
156 161
         $this->assertEquals(
157 162
           $diff,
@@ -176,8 +181,8 @@ public function testComparisonErrorStartSameComplete()
176 181
     public function testComparisonErrorStartSameComplete_toArray()
177 182
     {
178 183
         $diff = array();
179  
-        $diff[] = array('ab', PHPUnit_Util_DIFF::REMOVED);
180  
-        $diff[] = array('abc', PHPUnit_Util_DIFF::ADDED);
  184
+        $diff[] = array('ab', self::REMOVED);
  185
+        $diff[] = array('abc', self::ADDED);
181 186
       
182 187
         $this->assertEquals(
183 188
           $diff,
@@ -202,8 +207,8 @@ public function testComparisonErrorEndSameComplete()
202 207
     public function testComparisonErrorEndSameComplete_toArray()
203 208
     {
204 209
         $diff = array();
205  
-        $diff[] = array('bc', PHPUnit_Util_DIFF::REMOVED);
206  
-        $diff[] = array('abc', PHPUnit_Util_DIFF::ADDED);
  210
+        $diff[] = array('bc', self::REMOVED);
  211
+        $diff[] = array('abc', self::ADDED);
207 212
         
208 213
         $this->assertEquals(
209 214
           $diff,
@@ -228,8 +233,8 @@ public function testComparisonErrorOverlapingMatches()
228 233
     public function testComparisonErrorOverlapingMatches_toArray()
229 234
     {
230 235
         $diff = array();
231  
-        $diff[] = array('abc', PHPUnit_Util_DIFF::REMOVED);
232  
-        $diff[] = array('abbc', PHPUnit_Util_DIFF::ADDED);
  236
+        $diff[] = array('abc', self::REMOVED);
  237
+        $diff[] = array('abbc', self::ADDED);
233 238
 
234 239
         $this->assertEquals(
235 240
           $diff,
@@ -254,8 +259,8 @@ public function testComparisonErrorOverlapingMatches2()
254 259
     public function testComparisonErrorOverlapingMatches2_toArray()
255 260
     {
256 261
         $diff = array();
257  
-        $diff[] = array('abcdde', PHPUnit_Util_DIFF::REMOVED);
258  
-        $diff[] = array('abcde', PHPUnit_Util_DIFF::ADDED);
  262
+        $diff[] = array('abcdde', self::REMOVED);
  263
+        $diff[] = array('abcde', self::ADDED);
259 264
 
260 265
         $this->assertEquals(
261 266
           $diff,

0 notes on commit 5b2cb84

Please sign in to comment.
Something went wrong with that request. Please try again.