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

JsonTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 25
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testEncode() 0 10 2
A testDecode() 0 10 2
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