array merge fixes

This commit is contained in:
Taras Machyshyn
2014-10-10 10:33:04 +03:00
parent 363aea4c96
commit d12ae68bf4
2 changed files with 141 additions and 30 deletions

View File

@@ -142,7 +142,7 @@ class Util
if ($appendKey !== false) {
unset($newArray[$currentName][$appendKey]);
$newArray[$currentName] = array_merge($currentValue, $newArray[$currentName]);
} else {
} else if (!static::isSingleArray($newArray[$currentName])) {
$newArray[$currentName] = static::merge($currentValue, $newArray[$currentName]);
}
@@ -411,6 +411,18 @@ class Util
return true;
}
public static function isSingleArray(array $array)
{
foreach ($array as $key => $value) {
if (!is_int($key)) {
return false;
}
}
return true;
}
}

View File

@@ -449,38 +449,137 @@ class UtilTest extends \PHPUnit_Framework_TestCase
$result = array (
'fields' =>
array (
'accountName' =>
array (
'type' => 'foreign',
'relation' => 'account',
'foreign' => 'name',
),
'accountId' =>
array (
'type' => 'foreignId',
'index' => true,
'where' =>
array (
'=' => 'contact.id IN ({value})',
),
'len' => 255,
),
'deleted' =>
array (
'type' => 'bool',
'default' => false,
'trueValue' => true,
),
'accountName' =>
array (
'type' => 'foreign',
'relation' => 'account',
'foreign' => 'name',
),
'accountId' =>
array (
'type' => 'foreignId',
'index' => true,
'where' =>
array (
'=' => 'contact.id IN ({value})',
),
'len' => 255,
),
'deleted' =>
array (
'type' => 'bool',
'default' => false,
'trueValue' => true,
),
),
'relations' =>
array (
'createdBy' =>
array (
'type' => 'belongsTo',
'entity' => 'User',
'key' => 'createdById',
'foreignKey' => 'id',
),
'createdBy' =>
array (
'type' => 'belongsTo',
'entity' => 'User',
'key' => 'createdById',
'foreignKey' => 'id',
),
),
);
$this->assertEquals($result, Util::merge($currentArray, $newArray));
}
public function testMergeWithFieldsDefs()
{
$currentArray = array (
'fields' =>
array (
'aaa1' =>
array (
'type' => 'enum',
'required' => false,
'options' =>
array (
0 => 'a1',
1 => 'a3',
2 => 'a3',
),
'isCustom' => true,
),
'hfghgfh' =>
array (
'type' => 'varchar',
'required' => false,
'isCustom' => true,
'default' => 'hfghfgh',
),
'jghjghj' =>
array (
'type' => 'varchar',
'required' => false,
'isCustom' => true,
'default' => 'jghjghjhg',
),
'gdfgdfg' =>
array (
'type' => 'varchar',
'required' => false,
'isCustom' => true,
'default' => 'gdfgdfg',
'maxLength' => 70,
),
),
);
$newArray = array (
'fields' =>
array (
'aaa1' =>
array (
'type' => 'enum',
'required' => false,
'options' =>
array (
0 => 'a1',
),
'isCustom' => true,
),
),
);
$result = array (
'fields' =>
array (
'aaa1' =>
array (
'type' => 'enum',
'required' => false,
'options' =>
array (
0 => 'a1',
),
'isCustom' => true,
),
'hfghgfh' =>
array (
'type' => 'varchar',
'required' => false,
'isCustom' => true,
'default' => 'hfghfgh',
),
'jghjghj' =>
array (
'type' => 'varchar',
'required' => false,
'isCustom' => true,
'default' => 'jghjghjhg',
),
'gdfgdfg' =>
array (
'type' => 'varchar',
'required' => false,
'isCustom' => true,
'default' => 'gdfgdfg',
'maxLength' => 70,
),
),
);