From 1f77a33ea9b83dae1fe5d7ade625bdcd4f42ade3 Mon Sep 17 00:00:00 2001 From: Joby Elliott Date: Fri, 11 Jan 2019 18:23:22 -0700 Subject: [PATCH] more tests to verify that falsey values are working right The bug I'm chasing may actually be in Destructr --- tests/FlatArrayTest.php | 19 ++++++++++++++++--- tests/SelfReferencingFlatArrayTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/tests/FlatArrayTest.php b/tests/FlatArrayTest.php index b9c457c..81b42db 100644 --- a/tests/FlatArrayTest.php +++ b/tests/FlatArrayTest.php @@ -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() diff --git a/tests/SelfReferencingFlatArrayTest.php b/tests/SelfReferencingFlatArrayTest.php index 127ce7e..7e3b35c 100644 --- a/tests/SelfReferencingFlatArrayTest.php +++ b/tests/SelfReferencingFlatArrayTest.php @@ -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']); + } }