Skip to content

Commit

Permalink
Merge pull request #31 from WebFiori/dev
Browse files Browse the repository at this point in the history
Update JsonTest.php: Added More Test Cases
  • Loading branch information
usernane authored Apr 27, 2022
2 parents 0832307 + 7dcef43 commit f49f79e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
],
"license": "MIT",
"require": {
"php": ">=5.6"
"php": ">=7.0"
},
"require-dev": {
"phpunit/phpunit": "^5"
}
}
54 changes: 35 additions & 19 deletions tests/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"},'
Expand Down Expand Up @@ -828,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
Expand Down Expand Up @@ -922,6 +907,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
*/
Expand All @@ -930,6 +927,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
*/
Expand Down Expand Up @@ -957,6 +964,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
*/
Expand Down

0 comments on commit f49f79e

Please sign in to comment.