Test Failed
Push — master ( 6bff04...e0da10 )
by Lyal
02:14
created

ListableTest   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 12
dl 0
loc 107
c 0
b 0
f 0
rs 10
1
<?php
2
namespace Tests\Unit;
3
4
use GuzzleHttp\Psr7\Response;
5
use Lyal\Checkr\Traits\Listable;
6
use Tests\UnitTestCase;
7
8
class ListableTest extends UnitTestCase
9
{
10
11
    private $listable;
12
    private $jsonString = '{"data": [
13
        {
14
            "id": "57ed4ce3057e0b002adc6d90",
15
            "object": "adverse_item",
16
            "text": "CHARGE: DELIVER COCAINE (STATUTE: 90-95(A)(1)) (DISPOSITION: DISMISSAL W/O LEAVE)"
17
        },
18
        {
19
            "id": "57ed4ce3057e0b002adc6d91",
20
            "object": "adverse_item",
21
            "text": "CHARGE: RESISTING PUBLIC OFFICER (STATUTE: 14-223) (DISPOSITION: DISMISSAL W/O LEAVE)"
22
         }
23
         ],
24
            "object": "list",
25
            "count": 2
26
         }';
27
28
    protected function setUp()
29
    {
30
        $this->listable = $this->getClient()->adverseItem();
31
    }
32
33
    public function testCheckListTrait()
34
    {
35
        $this->assertArrayHasKey(Listable::class, class_uses($this->listable));
36
    }
37
38
    public function testGetCurrentPage()
39
    {
40
        $page = $this->listable->getCurrentPage();
41
        $this->assertEquals('1', $page);
42
    }
43
44
    public function testSetPerPage()
45
    {
46
        $this->listable->setPerPage('100');
47
        $pageSize = $this->listable->getPerPage();
48
        $this->assertEquals('100', $pageSize);
49
    }
50
51
    public function testSetCurrentPage()
52
    {
53
        $this->listable->setCurrentPage(1);
54
        $page = $this->listable->getCurrentPage();
55
        $this->assertEquals('1', $page);
56
    }
57
58
59
    public function testNextPage()
60
    {
61
        $this->listable->setCurrentPage('1');
62
        $page = $this->listable->nextPage();
63
        $this->assertEquals(2, $page);
64
    }
65
66
    public function testCount()
67
    {
68
        $this->listable->setCount(1);
69
        $count = $this->listable->getCount();
70
        $this->assertEquals(1, $count);
71
    }
72
73
    public function testSetPagination()
74
    {
75
        $this->listable->setPagination(1, 1);
76
        $currentPage = $this->listable->getCurrentPage();
77
        $perPage = $this->listable->getPerPage();
78
        $this->assertEquals(1, $currentPage);
79
        $this->assertEquals(1, $perPage);
80
    }
81
82
    public function testHasNextPage()
83
    {
84
        $this->listable->setPagination(1, 1);
85
        $this->listable->setCount(100);
86
        $this->listable->setNextPage();
87
        $this->assertTrue($this->listable->hasNextPage());
88
    }
89
90
    public function testProcessList()
91
    {
92
93
        $payload = json_decode($this->jsonString);
94
95
96
        $collection = $this->listable->processList($payload);
97
98
        $this->assertEquals('57ed4ce3057e0b002adc6d90', $collection->first()->id);
99
    }
100
101
102
    public function testGetList($page = NULL, $perPage = NULL)
103
    {
104
105
        $responses = [new Response(200, [], $this->jsonString)];
106
        $adverseItems = $this->getClient($responses)->adverse_items()->getList();
107
        $this->assertEquals('Lyal\Checkr\Entities\Resources\AdverseItem', get_class($adverseItems->first()));
108
    }
109
110
    public function testAll()
111
    {
112
        $responses = [new Response(200, [], $this->jsonString), new Response(200, [], $this->jsonString)];
113
        $adverseItems = $this->getClient($responses)->adverse_items()->setPerPage(1)->all();
114
        $this->assertEquals('Lyal\Checkr\Entities\Resources\AdverseItem', get_class($adverseItems->first()));
115
    }
116
}