Browse Source

Port Hash::maxDimension() fixes to 3.0

Port fixes from #7040 and #7041 to 3.0.
Mark Story 10 years ago
parent
commit
742f85de80
2 changed files with 11 additions and 20 deletions
  1. 1 1
      src/Utility/Hash.php
  2. 10 19
      tests/TestCase/Utility/HashTest.php

+ 1 - 1
src/Utility/Hash.php

@@ -803,7 +803,7 @@ class Hash
         if (is_array($data) && reset($data) !== false) {
             foreach ($data as $value) {
                 if (is_array($value)) {
-                    $depth[] = static::dimensions($value) + 1;
+                    $depth[] = static::maxDimensions($value) + 1;
                 } else {
                     $depth[] = 1;
                 }

+ 10 - 19
tests/TestCase/Utility/HashTest.php

@@ -310,25 +310,16 @@ class HashTest extends TestCase
         $this->assertEquals($result, 4);
 
         $data = [
-            '1' => ['1.1' => '1.1.1'],
-            ['2' => ['2.1' => ['2.1.1' => ['2.1.1.1']]]],
-            '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]
-        ];
-        $result = Hash::maxDimensions($data);
-        $this->assertEquals($result, 5);
-
-        $data = [
-            '1' => ['1.1' => '1.1.1'],
-            ['2' => ['2.1' => ['2.1.1' => ['2.1.1.1' => '2.1.1.1.1']]]],
-            '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]
-        ];
-        $result = Hash::maxDimensions($data);
-        $this->assertEquals($result, 5);
-
-        $data = [
-            '1' => ['1.1' => '1.1.1'],
-            ['2' => ['2.1' => ['2.1.1' => ['2.1.1.1' => '2.1.1.1.1']]]],
-            '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]
+           '1' => [
+               '1.1' => '1.1.1',
+               '1.2' => [
+                   '1.2.1' => [
+                       '1.2.1.1',
+                       ['1.2.2.1']
+                   ]
+               ]
+           ],
+           '2' => ['2.1' => '2.1.1',]
         ];
         $result = Hash::maxDimensions($data);
         $this->assertEquals($result, 5);