Skip to content
Permalink
Browse files

FIxed deletion of nested values in InstanceConfigTrait

  • Loading branch information...
sukihub committed May 9, 2015
1 parent aff1b8b commit 5872fc6b92c736883d4bca905c60b1ed3ab1e06e
Showing with 59 additions and 13 deletions.
  1. +1 −1 src/Core/InstanceConfigTrait.php
  2. +58 −12 tests/TestCase/Core/InstanceConfigTraitTest.php
@@ -250,7 +250,7 @@ protected function _configDelete($key)
break;
}
if ($i === $length - 2) {
if ($i === $length - 1) {
unset($update[$k]);
break;
}
@@ -35,7 +35,10 @@ class TestInstanceConfig
*/
protected $_defaultConfig = [
'some' => 'string',
'a' => ['nested' => 'value']
'a' => [
'nested' => 'value',
'other' => 'value'
]
];
}
@@ -56,7 +59,10 @@ class ReadOnlyTestInstanceConfig
*/
protected $_defaultConfig = [
'some' => 'string',
'a' => ['nested' => 'value']
'a' => [
'nested' => 'value',
'other' => 'value'
]
];
/**
@@ -101,7 +107,10 @@ public function testDefaultsAreSet()
$this->assertSame(
[
'some' => 'string',
'a' => ['nested' => 'value']
'a' => [
'nested' => 'value',
'other' => 'value'
]
],
$this->object->config(),
'runtime config should match the defaults if not overridden'
@@ -122,7 +131,7 @@ public function testGetSimple()
);
$this->assertSame(
['nested' => 'value'],
['nested' => 'value', 'other' => 'value'],
$this->object->config('a'),
'should return the key value only'
);
@@ -171,7 +180,7 @@ public function testSetSimple()
$this->assertSame(
[
'some' => 'zum',
'a' => ['nested' => 'value'],
'a' => ['nested' => 'value', 'other' => 'value'],
'foo' => 'bar',
],
$this->object->config(),
@@ -203,7 +212,7 @@ public function testSetNested()
$this->assertSame(
[
'some' => 'string',
'a' => ['nested' => 'zum'],
'a' => ['nested' => 'zum', 'other' => 'value'],
'new' => ['foo' => 'bar']
],
$this->object->config(),
@@ -228,7 +237,7 @@ public function testSetArray()
$this->assertSame(
[
'some' => 'string',
'a' => ['nested' => 'value'],
'a' => ['nested' => 'value', 'other' => 'value'],
'foo' => 'bar',
],
$this->object->config(),
@@ -245,7 +254,7 @@ public function testSetArray()
$this->assertSame(
[
'some' => 'string',
'a' => ['nested' => 'value'],
'a' => ['nested' => 'value', 'other' => 'value'],
'foo' => 'bar',
'new' => ['foo' => 'bar']
],
@@ -258,7 +267,7 @@ public function testSetArray()
$this->assertSame(
[
'some' => 'string',
'a' => ['nested' => 'value', 'values' => ['to' => 'set']],
'a' => ['nested' => 'value', 'other' => 'value', 'values' => ['to' => 'set']],
'foo' => 'bar',
'new' => ['foo' => 'bar'],
'multiple' => 'different'
@@ -315,6 +324,7 @@ public function testMerge()
'some' => 'string',
'a' => [
'nested' => 'value',
'other' => 'value',
'nother' => 'value'
]
],
@@ -337,6 +347,7 @@ public function testMergeDotKey()
'some' => 'string',
'a' => [
'nested' => 'value',
'other' => 'value',
'nother' => 'value'
]
],
@@ -351,6 +362,7 @@ public function testMergeDotKey()
'some' => 'string',
'a' => [
'nested' => 'value',
'other' => 'value',
'nother' => 'value',
'nextra' => 'value'
]
@@ -374,6 +386,7 @@ public function testSetDefaultsMerge()
'some' => 'string',
'a' => [
'nested' => 'value',
'other' => 'value',
'nother' => 'value'
]
],
@@ -421,7 +434,8 @@ public function testSetMergeNoClobber()
'a' => [
'nested' => [
'value' => 'it is possible'
]
],
'other' => 'value'
]
],
$this->object->config(),
@@ -443,7 +457,7 @@ public function testReadOnlyConfig()
$this->assertSame(
[
'some' => 'string',
'a' => ['nested' => 'value']
'a' => ['nested' => 'value', 'other' => 'value']
],
$object->config(),
'default config should be returned'
@@ -473,7 +487,7 @@ public function testDeleteSimple()
$this->assertSame(
[
'a' => ['nested' => 'value'],
'a' => ['nested' => 'value', 'other' => 'value'],
],
$this->object->config(),
'deleted keys should not be present'
@@ -498,10 +512,42 @@ public function testDeleteNested()
$this->object->config('a.nested'),
'should delete the existing value'
);
$this->assertSame(
[
'some' => 'string',
'a' => [
'other' => 'value'
]
],
$this->object->config(),
'deleted keys should not be present'
);
$this->object->config('a.other', null);
$this->assertNull(
$this->object->config('a.other'),
'should delete the existing value'
);
$this->assertSame(
[
'some' => 'string',
'a' => []
],
$this->object->config(),
'deleted keys should not be present'
);
}
public function testDeleteArray()
{
$this->object->config('a', null);
$this->assertNull(
$this->object->config('a'),
'should delete the existing value'
);
$this->assertSame(
[
'some' => 'string'
],
$this->object->config(),
'deleted keys should not be present'

0 comments on commit 5872fc6

Please sign in to comment.
You can’t perform that action at this time.