Skip to content

Commit 4525db8

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

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

tests/IsJsonTest.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,64 @@ public function it_returns_false_with_non_json_string_and_second_argument_passed
6969
}
7070

7171
/** @test */
72-
public function it_returns_true_with_json_string_passed()
72+
public function it_returns_true_with_json_encoded_null_passed()
73+
{
74+
$json = json_encode(null);
75+
$this->assertTrue(is_json($json));
76+
}
77+
78+
/** @test */
79+
public function it_returns_true_with_json_encoded_boolean_true_passed()
80+
{
81+
$json = json_encode(true);
82+
$this->assertTrue(is_json($json));
83+
}
84+
85+
/** @test */
86+
public function it_returns_true_with_json_encoded_boolean_false_passed()
87+
{
88+
$json = json_encode(false);
89+
$this->assertTrue(is_json($json));
90+
}
91+
92+
/** @test */
93+
public function it_returns_true_with_json_encoded_integer_passed()
94+
{
95+
$json = json_encode(123);
96+
$this->assertTrue(is_json($json));
97+
}
98+
99+
/** @test */
100+
public function it_returns_true_with_json_encoded_float_passed()
101+
{
102+
$json = json_encode(123.45);
103+
$this->assertTrue(is_json($json));
104+
}
105+
106+
/** @test */
107+
public function it_returns_true_with_json_encoded_array_passed()
73108
{
74109
$json = json_encode(['foo' => 'bar']);
75110
$this->assertTrue(is_json($json));
76111
}
77112

113+
/** @test */
114+
public function it_returns_true_with_json_encoded_object_passed()
115+
{
116+
$object = new StdClass();
117+
$object->foo = 'bar';
118+
$object->baz = 'bax';
119+
$json = json_encode($object);
120+
$this->assertTrue(is_json($json));
121+
}
122+
123+
/** @test */
124+
public function it_returns_true_with_json_encoded_string_passed()
125+
{
126+
$json = json_encode('string to encode');
127+
$this->assertTrue(is_json($json));
128+
}
129+
78130
/** @test */
79131
public function it_returns_decoded_json_with_second_argument_passed()
80132
{

0 commit comments

Comments
 (0)