Test Failed
Push — master ( 90f1e5...8cd561 )
by Jim
02:25
created

JsonTest::testDecode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: lenovo
5
 * Date: 6/14/2018
6
 * Time: 3:05 PM
7
 */
8
9
namespace TimSDK\Tests\Support;
10
11
use TimSDK\Core\Exceptions\JsonParseException;
12
use TimSDK\Support\Json;
13
use TimSDK\Tests\TestCase;
14
15
class JsonTest extends TestCase
16
{
17
    public function testEncode()
18
    {
19
        $array = ['foo' => 'bar'];
20
21
        $this->assertEquals('{"foo":"bar"}', Json::encode($array));
22
23
        try {
24
            Json::encode('');
25
        } catch (\Exception $e) {
26
            $this->assertInstanceOf(JsonParseException::class, $e);
27
        }
28
    }
29
30
    public function testDecode()
31
    {
32
        $json = '{"foo":"bar"}';
33
34
        $this->assertEquals(['foo' => 'bar'], Json::decode($json, true));
35
36
        try {
37
            Json::decode('{"foo":"bar"');
38
        } catch (\Exception $e) {
39
            $this->assertInstanceOf(JsonParseException::class, $e);
40
        }
41
    }
42
}
43