Completed
Push — master ( b8ee44...86e435 )
by Jim
02:27
created

ResponseBagTest::testResponseBagIsConstructed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: lenovo
5
 * Date: 6/17/2018
6
 * Time: 9:41 AM
7
 */
8
9
namespace TimSDK\Tests\Foundation;
10
11
use TimSDK\Foundation\ResponseBag;
12
use TimSDK\Tests\TestCase;
13
14
class ResponseBagTest extends TestCase
15
{
16
    public function testResponseBagIsConstructed()
17
    {
18
        $bag = new ResponseBag('foo', 'bar');
19
        $this->assertSame(['foo'], $bag->getContents()->all());
20
        $this->assertSame(['bar'], $bag->getHeaders()->all());
21
22
        $bag = new ResponseBag('{"foo": "bar"}', '{"key": "value"}');
23
        $this->assertSame(['foo' => 'bar'], $bag->getContents()->all());
24
        $this->assertSame(['key' => 'value'], $bag->getHeaders()->all());
25
26
        $bag = new ResponseBag(
27
            new TestJsonSerializeObject(['foo' => 'bar']),
28
            new TestJsonSerializeObject(['key' => 'value'])
29
        );
30
        $this->assertSame(['foo' => 'bar'], $bag->getContents()->all());
31
        $this->assertSame(['key' => 'value'], $bag->getHeaders()->all());
32
33
        $bag = new ResponseBag(false, true);
34
        $this->assertSame([false], $bag->getContents()->all());
35
        $this->assertSame([true], $bag->getHeaders()->all());
36
37
        $bag = new ResponseBag(null, null);
38
        $this->assertSame([], $bag->getContents()->all());
39
        $this->assertSame([], $bag->getHeaders()->all());
40
    }
41
}
42
43
class TestJsonSerializeObject implements \JsonSerializable
44
{
45
    protected $items = [];
46
47
    public function __construct($items)
48
    {
49
        $this->items = $items;
50
    }
51
52
    public function jsonSerialize()
53
    {
54
        return $this->items;
55
    }
56
}
57