Skip to content

Commit 4501538

Browse files
committed
IHF: More tests added for is_json.
1 parent e4a9490 commit 4501538

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/IsJsonTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public function it_returns_false_with_non_empty_array_passed()
4444
$this->assertFalse(is_json(['foo' => 'bar']));
4545
}
4646

47+
/** @test */
48+
public function it_returns_false_with_object_passed()
49+
{
50+
$this->assertFalse(is_json(new StdClass()));
51+
}
52+
4753
/** @test */
4854
public function it_returns_false_with_an_empty_string_passed()
4955
{
@@ -56,10 +62,24 @@ public function it_returns_false_with_non_json_string_passed()
5662
$this->assertFalse(is_json('non-json string'));
5763
}
5864

65+
/** @test */
66+
public function it_returns_false_with_non_json_string_and_second_argument_passed()
67+
{
68+
$this->assertFalse(is_json('non-json string', true));
69+
}
70+
5971
/** @test */
6072
public function it_returns_true_with_json_string_passed()
6173
{
6274
$json = json_encode(['foo' => 'bar']);
6375
$this->assertTrue(is_json($json));
6476
}
77+
78+
/** @test */
79+
public function it_returns_decoded_json_with_second_argument_passed()
80+
{
81+
$array = ['foo' => 'bar', 'baz' => 'bax'];
82+
$json = json_encode($array);
83+
$this->assertEquals($array, is_json($json, true));
84+
}
6585
}

0 commit comments

Comments
 (0)