From d4d1443e475e450084c2786558272b99c4105acf Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Wed, 27 Apr 2022 10:12:20 +0300 Subject: [PATCH 1/3] Update JsonTest.php --- tests/JsonTest.php | 52 +++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/tests/JsonTest.php b/tests/JsonTest.php index 8db112a..0a43b8a 100644 --- a/tests/JsonTest.php +++ b/tests/JsonTest.php @@ -676,24 +676,7 @@ public function testAddMultiple00() { ]); $this->assertEquals('{"user-id":5,"an-array":[1,2,3],"float":1.6,"bool":true}',$j.''); } - /** - * @test - */ - public function testAdd00() { - $j = new Json(); - $this->assertTrue($j->add('a-string','This is a string.')); - $this->assertTrue($j->add('string-as-bool-1','NO',['string-as-boolean' => true])); - $this->assertTrue($j->add('string-as-bool-2',-1,['string-as-boolean' => true])); - $this->assertTrue($j->add('string-as-bool-3',0,['string-as-boolean' => true])); - $this->assertTrue($j->add('string-as-bool-4',1,['string-as-boolean' => true])); - $this->assertTrue($j->add('string-as-bool-5','t',['string-as-boolean' => true])); - $this->assertTrue($j->add('string-as-bool-6','Yes',['string-as-boolean' => true])); - $this->assertTrue($j->add('string-not-as-bool','Yes')); - $this->assertTrue($j->add('null-value',null)); - $this->assertTrue($j->add('infinity',INF)); - $this->assertTrue($j->add('not-a-number',INF)); - $this->assertFalse($j->addObject('ok', null)); - } + /** * @test @@ -709,7 +692,7 @@ public function testAdd03() { new Obj1('1','Hello','No',true,false), $subJ, [[new Obj0('p0','p1','p2','p3','p4'),$subJ,new Obj1('p0','p1','p2','p3','p4')]]]; - $j->add('big-array',$arr); + $j->add('big-array', $arr); $this->assertEquals('{' .'"big-array":["world",' .'{"Property00":"Nice","Property01":"To","Property02":99,"Property04":"NaN"},' @@ -922,6 +905,18 @@ public function testAddArray06() { . ' ]'."\r\n" . '}', $j.''); } + /** + * @test + */ + public function testAddArray07() { + $j = new Json(); + $j->addArray('my-val', [1]); + $this->assertEquals([1], $j->get('my-val')); + $j->addArray('my-val', [2]); + $this->assertEquals([2], $j->get('my-val')); + $j->add('my-val', [1, 2, 3]); + $this->assertEquals([1, 2, 3], $j->get('my-val')); + } /** * @test */ @@ -930,6 +925,16 @@ public function testAddBoolean00() { $j->addBoolean('bool ',true); $this->assertEquals('{"bool":true}',$j.''); } + /** + * @test + */ + public function testAddBoolean01() { + $j = new Json(); + $j->addBoolean('my-val', true); + $this->assertTrue($j->get('my-val')); + $j->addBoolean('my-val', false); + $this->assertFalse($j->get('my-val')); + } /** * @test */ @@ -957,6 +962,15 @@ public function testAddObj01() { $j->addObject('object',$obj); $this->assertEquals('{"object":{"property-00":"Hello","property-01":0,"property-02":true}}',$j.''); } + public function testAddObj02() { + $obj = new Obj1('Hello',0,true,null,'he'); + $obj2 = new Obj0('Hello',0,true,null,'he'); + $j = new Json(); + $j->addObject('my-val', $obj2); + $this->assertEquals('{"my-val":{"Property00":"Hello","Property01":0,"Property02":true,"Property04":"he"}}',$j.''); + $j->addObject('my-val', $obj); + $this->assertEquals('{"my-val":{"property-00":"Hello","property-01":0,"property-02":true}}',$j.''); + } /** * @test */ From 43a5d17d095c8580ce49644d04f1c2e741c3a686 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Wed, 27 Apr 2022 10:15:05 +0300 Subject: [PATCH 2/3] Update JsonTest.php --- tests/JsonTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/JsonTest.php b/tests/JsonTest.php index 0a43b8a..0bfa61e 100644 --- a/tests/JsonTest.php +++ b/tests/JsonTest.php @@ -811,6 +811,8 @@ public function testAdd09() { $j->add('one', 'not one'); $this->assertEquals(2, count($j->getPropsNames())); $this->assertEquals('not one', $j->get('one')); + $j->addNumber('one', 1); + $this->assertEquals(1, $j->get('one')); } /** * @test From 7dcef434d676cf5a8ac3aa2d970f79559ab55921 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Wed, 27 Apr 2022 10:16:17 +0300 Subject: [PATCH 3/3] Update composer.json --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 4f651cf..592163f 100644 --- a/composer.json +++ b/composer.json @@ -7,9 +7,8 @@ ], "license": "MIT", "require": { - "php": ">=5.6" + "php": ">=7.0" }, "require-dev": { - "phpunit/phpunit": "^5" } } \ No newline at end of file