Skip to content

Commit f49f79e

Browse files
authored
Merge pull request #31 from WebFiori/dev
Update JsonTest.php: Added More Test Cases
2 parents 0832307 + 7dcef43 commit f49f79e

2 files changed

Lines changed: 36 additions & 21 deletions

File tree

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
],
88
"license": "MIT",
99
"require": {
10-
"php": ">=5.6"
10+
"php": ">=7.0"
1111
},
1212
"require-dev": {
13-
"phpunit/phpunit": "^5"
1413
}
1514
}

tests/JsonTest.php

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -676,24 +676,7 @@ public function testAddMultiple00() {
676676
]);
677677
$this->assertEquals('{"user-id":5,"an-array":[1,2,3],"float":1.6,"bool":true}',$j.'');
678678
}
679-
/**
680-
* @test
681-
*/
682-
public function testAdd00() {
683-
$j = new Json();
684-
$this->assertTrue($j->add('a-string','This is a string.'));
685-
$this->assertTrue($j->add('string-as-bool-1','NO',['string-as-boolean' => true]));
686-
$this->assertTrue($j->add('string-as-bool-2',-1,['string-as-boolean' => true]));
687-
$this->assertTrue($j->add('string-as-bool-3',0,['string-as-boolean' => true]));
688-
$this->assertTrue($j->add('string-as-bool-4',1,['string-as-boolean' => true]));
689-
$this->assertTrue($j->add('string-as-bool-5','t',['string-as-boolean' => true]));
690-
$this->assertTrue($j->add('string-as-bool-6','Yes',['string-as-boolean' => true]));
691-
$this->assertTrue($j->add('string-not-as-bool','Yes'));
692-
$this->assertTrue($j->add('null-value',null));
693-
$this->assertTrue($j->add('infinity',INF));
694-
$this->assertTrue($j->add('not-a-number',INF));
695-
$this->assertFalse($j->addObject('ok', null));
696-
}
679+
697680

698681
/**
699682
* @test
@@ -709,7 +692,7 @@ public function testAdd03() {
709692
new Obj1('1','Hello','No',true,false),
710693
$subJ,
711694
[[new Obj0('p0','p1','p2','p3','p4'),$subJ,new Obj1('p0','p1','p2','p3','p4')]]];
712-
$j->add('big-array',$arr);
695+
$j->add('big-array', $arr);
713696
$this->assertEquals('{'
714697
.'"big-array":["world",'
715698
.'{"Property00":"Nice","Property01":"To","Property02":99,"Property04":"NaN"},'
@@ -828,6 +811,8 @@ public function testAdd09() {
828811
$j->add('one', 'not one');
829812
$this->assertEquals(2, count($j->getPropsNames()));
830813
$this->assertEquals('not one', $j->get('one'));
814+
$j->addNumber('one', 1);
815+
$this->assertEquals(1, $j->get('one'));
831816
}
832817
/**
833818
* @test
@@ -922,6 +907,18 @@ public function testAddArray06() {
922907
. ' ]'."\r\n"
923908
. '}', $j.'');
924909
}
910+
/**
911+
* @test
912+
*/
913+
public function testAddArray07() {
914+
$j = new Json();
915+
$j->addArray('my-val', [1]);
916+
$this->assertEquals([1], $j->get('my-val'));
917+
$j->addArray('my-val', [2]);
918+
$this->assertEquals([2], $j->get('my-val'));
919+
$j->add('my-val', [1, 2, 3]);
920+
$this->assertEquals([1, 2, 3], $j->get('my-val'));
921+
}
925922
/**
926923
* @test
927924
*/
@@ -930,6 +927,16 @@ public function testAddBoolean00() {
930927
$j->addBoolean('bool ',true);
931928
$this->assertEquals('{"bool":true}',$j.'');
932929
}
930+
/**
931+
* @test
932+
*/
933+
public function testAddBoolean01() {
934+
$j = new Json();
935+
$j->addBoolean('my-val', true);
936+
$this->assertTrue($j->get('my-val'));
937+
$j->addBoolean('my-val', false);
938+
$this->assertFalse($j->get('my-val'));
939+
}
933940
/**
934941
* @test
935942
*/
@@ -957,6 +964,15 @@ public function testAddObj01() {
957964
$j->addObject('object',$obj);
958965
$this->assertEquals('{"object":{"property-00":"Hello","property-01":0,"property-02":true}}',$j.'');
959966
}
967+
public function testAddObj02() {
968+
$obj = new Obj1('Hello',0,true,null,'he');
969+
$obj2 = new Obj0('Hello',0,true,null,'he');
970+
$j = new Json();
971+
$j->addObject('my-val', $obj2);
972+
$this->assertEquals('{"my-val":{"Property00":"Hello","Property01":0,"Property02":true,"Property04":"he"}}',$j.'');
973+
$j->addObject('my-val', $obj);
974+
$this->assertEquals('{"my-val":{"property-00":"Hello","property-01":0,"property-02":true}}',$j.'');
975+
}
960976
/**
961977
* @test
962978
*/

0 commit comments

Comments
 (0)