more tests to verify that falsey values are working right

The bug I'm chasing may actually be in Destructr
This commit is contained in:
Joby 2019-01-11 18:23:22 -07:00
parent 373238d055
commit 1f77a33ea9
2 changed files with 42 additions and 3 deletions

View file

@ -95,11 +95,24 @@ class FlatArrayTest extends TestCase
$a['foo.bar'] = false;
$this->assertFalse($a['foo.bar']);
$a['foo.bar'] = 0;
$this->assertEquals(0, $a['foo.bar']);
$this->assertSame(0, $a['foo.bar']);
$a['foo.bar'] = '';
$this->assertEquals('', $a['foo.bar']);
$this->assertSame('', $a['foo.bar']);
$a['foo.bar'] = [];
$this->assertEquals([], $a['foo.bar']);
$this->assertSame([], $a['foo.bar']);
}
public function testMerginFalseyValues()
{
$a = new FlatArray(['foo'=>['bar'=>'baz']]);
$a->merge(['foo'=>['bar'=>false]], null, true);
$this->assertFalse($a['foo.bar']);
$a->merge(['foo'=>['bar'=>0]], null, true);
$this->assertSame(0, $a['foo.bar']);
$a->merge(['foo'=>['bar'=>'']], null, true);
$this->assertSame('', $a['foo.bar']);
$a->merge(['foo'=>['bar'=>[]]], null, true);
$this->assertSame([], $a['foo.bar']);
}
public function testCaseSensitivity()

View file

@ -50,4 +50,30 @@ class SelfReferencingFlatArrayTest extends TestCase
$this->assertEquals('${foo}', $f['nested.escaped.left']);
$this->assertEquals('${foo}', $f['nested.escaped.right']);
}
public function testSettingFalseyValues()
{
$a = new SelfReferencingFlatArray(['foo'=>['bar'=>'baz']]);
$a['foo.bar'] = false;
$this->assertFalse($a['foo.bar']);
$a['foo.bar'] = 0;
$this->assertSame(0, $a['foo.bar']);
$a['foo.bar'] = '';
$this->assertSame('', $a['foo.bar']);
$a['foo.bar'] = [];
$this->assertSame([], $a['foo.bar']);
}
public function testMerginFalseyValues()
{
$a = new SelfReferencingFlatArray(['foo'=>['bar'=>'baz']]);
$a->merge(['foo'=>['bar'=>false]], null, true);
$this->assertFalse($a['foo.bar']);
$a->merge(['foo'=>['bar'=>0]], null, true);
$this->assertSame(0, $a['foo.bar']);
$a->merge(['foo'=>['bar'=>'']], null, true);
$this->assertSame('', $a['foo.bar']);
$a->merge(['foo'=>['bar'=>[]]], null, true);
$this->assertSame([], $a['foo.bar']);
}
}