1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Tests\Unit; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use GuzzleHttp\Psr7\Response; |
8
|
|
|
use Lyal\Checkr\Entities\Resources\AdverseItem; |
9
|
|
|
use Lyal\Checkr\Entities\Resources\Candidate; |
10
|
|
|
use Lyal\Checkr\Entities\Resources\Document; |
11
|
|
|
use Lyal\Checkr\Entities\Resources\Geo; |
12
|
|
|
use Lyal\Checkr\Entities\Resources\Report; |
13
|
|
|
use Lyal\Checkr\Exceptions\IdMissing; |
14
|
|
|
use Lyal\Checkr\Exceptions\InvalidAttributeException; |
15
|
|
|
use Lyal\Checkr\Exceptions\ResourceNotCreated; |
16
|
|
|
use Tests\UnitTestCase; |
17
|
|
|
|
18
|
|
|
class AbstractEntityTest extends UnitTestCase |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
private $jsonAdverseItem = '{ |
22
|
|
|
"id": "57ed4ce3057e0b002adc6d93", |
23
|
|
|
"object": "adverse_item", |
24
|
|
|
"text": "License status: Suspended" |
25
|
|
|
}'; |
26
|
|
|
|
27
|
|
|
private $jsonReport = '{ |
28
|
|
|
"id": "4722c07dd9a10c3985ae432a", |
29
|
|
|
"object": "report", |
30
|
|
|
"uri": "/v1/reports/4722c07dd9a10c3985ae432a", |
31
|
|
|
"status": "clear", |
32
|
|
|
"created_at": "2014-01-18T12:34:00Z", |
33
|
|
|
"completed_at": "2014-01-18T12:35:30Z", |
34
|
|
|
"revised_at": null, |
35
|
|
|
"turnaround_time": 90, |
36
|
|
|
"due_time": "2014-01-19T11:28:31Z", |
37
|
|
|
"adjudication": "engaged", |
38
|
|
|
"package": "driver_pro", |
39
|
|
|
"candidate_id": "e44aa283528e6fde7d542194", |
40
|
|
|
"ssn_trace_id": "539fd88c101897f7cd000001", |
41
|
|
|
"sex_offender_search_id": "539fd88c101897f7cd000008", |
42
|
|
|
"national_criminal_search_id": "539fd88c101897f7cd000006", |
43
|
|
|
"county_criminal_search_ids": [ |
44
|
|
|
"539fdcf335644a0ef4000001", |
45
|
|
|
"532e71cfe88a1d4e8d00000c" |
46
|
|
|
], |
47
|
|
|
"motor_vehicle_report_id": "539fd88c101897f7cd000007", |
48
|
|
|
"state_criminal_search_ids": [ |
49
|
|
|
"539fdcf335644a0ef4000003", |
50
|
|
|
"532e71cfe88a1d4e8d000004" |
51
|
|
|
], |
52
|
|
|
"document_ids": [], |
53
|
|
|
"geo_ids": [ |
54
|
|
|
"87f5bb4983eade22c55f4731" |
55
|
|
|
], |
56
|
|
|
"program_id": "00166f9ff39ec7b453adfaec" |
57
|
|
|
}'; |
58
|
|
|
|
59
|
|
|
private $jsonGeo = '{ |
60
|
|
|
"id": "87f5bb4983eade22c55f4731", |
61
|
|
|
"object": "geo", |
62
|
|
|
"uri": "/v1/geos/87f5bb4983eade22c55f4731", |
63
|
|
|
"created_at": "2015-01-18T12:34:00Z", |
64
|
|
|
"name": "San Francisco", |
65
|
|
|
"state": "CA", |
66
|
|
|
"deleted_at": null |
67
|
|
|
} |
68
|
|
|
'; |
69
|
|
|
|
70
|
|
|
private $jsonProgram = ' { |
71
|
|
|
"id": "00166f9ff39ec7b453adfaec", |
72
|
|
|
"object": "program", |
73
|
|
|
"name": "Program A", |
74
|
|
|
"created_at": "2017-08-07T16:51:09Z", |
75
|
|
|
"deleted_at": null, |
76
|
|
|
"geo_ids": [ |
77
|
|
|
"cbc37748bc6a45b41af5c3f5" |
78
|
|
|
], |
79
|
|
|
"package_ids": [ |
80
|
|
|
"a57a0cd15965a585ff7d5d35" |
81
|
|
|
] |
82
|
|
|
}'; |
83
|
|
|
|
84
|
|
|
public function testInvalidMethod() |
85
|
|
|
{ |
86
|
|
|
$this->expectException(InvalidAttributeException::class); |
87
|
|
|
$adverseItem = $this->getAdverseItem(); |
88
|
|
|
$adverseItem->testBadValue = 1; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testPreviousObject() |
92
|
|
|
{ |
93
|
|
|
$candidate = $this->getCandidate(['id' => 1]); |
94
|
|
|
$document = $this->getDocument(); |
95
|
|
|
$document->setPreviousObject($candidate); |
96
|
|
|
$this->assertEquals(1, $document->candidate_id); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testCreateObject() |
100
|
|
|
{ |
101
|
|
|
$responses = [ |
102
|
|
|
new Response(201, [], $this->jsonReport), |
103
|
|
|
]; |
104
|
|
|
$report = $this->getReport([], $responses)->create(); |
105
|
|
|
|
106
|
|
|
$this->assertEquals('4722c07dd9a10c3985ae432a', $report->id); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function testFailedCreateObject() |
110
|
|
|
{ |
111
|
|
|
$this->expectException(ResourceNotCreated::class); |
112
|
|
|
$responses = [ |
113
|
|
|
new Response(200, [], $this->jsonReport), |
114
|
|
|
]; |
115
|
|
|
$report = $this->getReport([], $responses)->create(); |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function testSaveObject() |
120
|
|
|
{ |
121
|
|
|
$responses = [ |
122
|
|
|
new Response(200, [], $this->jsonReport), |
123
|
|
|
new Response(200, [], $this->jsonReport), |
124
|
|
|
]; |
125
|
|
|
$report = $this->getReport([], $responses)->load(); |
126
|
|
|
$report->save(); |
127
|
|
|
$this->assertEquals('4722c07dd9a10c3985ae432a', $report->id); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function testFailedSaveObject() |
131
|
|
|
{ |
132
|
|
|
$this->expectException(IdMissing::class); |
133
|
|
|
$report = $this->getReport()->save(); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
public function testSetBadAttribute() |
138
|
|
|
{ |
139
|
|
|
$this->expectException(InvalidAttributeException::class); |
140
|
|
|
$adverseItem = $this->getAdverseItem(); |
141
|
|
|
$adverseItem->testBadValue = 1; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
public function testGetBadAttribute() |
146
|
|
|
{ |
147
|
|
|
$this->expectException(InvalidAttributeException::class); |
148
|
|
|
$adverseItem = $this->getAdverseItem(); |
149
|
|
|
$p = $adverseItem->testBadValue; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function testIsset() |
153
|
|
|
{ |
154
|
|
|
$adverseItem = $this->getAdverseItem(); |
155
|
|
|
$adverseItem->id = '1'; |
156
|
|
|
$this->assertTrue(isset($adverseItem->id)); |
157
|
|
|
|
158
|
|
|
$this->assertFalse(isset($adverseItem->object)); |
159
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
public function testClientMethod() |
164
|
|
|
{ |
165
|
|
|
$report = $this->getReport()->adverseItem(); |
166
|
|
|
$this->assertInstanceOf(get_class($this->getAdverseItem()), $report); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function testDeleteMethod() |
170
|
|
|
{ |
171
|
|
|
$responses = [ |
172
|
|
|
new Response(200, [], $this->jsonGeo), |
173
|
|
|
new Response(200, [], $this->jsonGeo), |
174
|
|
|
]; |
175
|
|
|
$geo = $this->getGeo([], $responses)->load(); |
176
|
|
|
$deleted = $geo->delete(); |
177
|
|
|
$this->assertInstanceOf('Lyal\Checkr\Client', $deleted); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function testEmbedMethod() |
181
|
|
|
{ |
182
|
|
|
$report = $this->getReport(); |
183
|
|
|
|
184
|
|
|
$fieldCheck = $report->checkField('include'); |
185
|
|
|
|
186
|
|
|
$this->assertTrue($fieldCheck); |
187
|
|
|
|
188
|
|
|
$report->embed('county_criminal_searches'); |
189
|
|
|
$this->assertEquals('county_criminal_searches', $report->getEmbeddedResources()); |
190
|
|
|
|
191
|
|
|
$report->embed(['motor_vehicle_report', 'county_criminal_searches']); |
192
|
|
|
$this->assertEquals('motor_vehicle_report,county_criminal_searches', $report->getEmbeddedResources()); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
|
196
|
|
|
public function testIgnoreFieldChecks() |
197
|
|
|
{ |
198
|
|
|
$geo = $this->getGeo(); |
199
|
|
|
$geo->checkFields = false; |
200
|
|
|
$geo->id3 = 'hi'; |
201
|
|
|
$this->assertEquals('hi', $geo->id3); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function getGeo($values = [], array $response = []) |
205
|
|
|
{ |
206
|
|
|
return new Geo($values, $this->getClient($response)); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
|
210
|
|
|
public function getAdverseItem($values = [], $responses = []) |
211
|
|
|
{ |
212
|
|
|
return new AdverseItem($values, $this->getClient($responses)); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
public function getCandidate($values = [], $responses = []) |
216
|
|
|
{ |
217
|
|
|
return new Candidate($values, $this->getClient($responses)); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function getDocument($values = [], $responses = []) |
221
|
|
|
{ |
222
|
|
|
return new Document($values, $this->getClient($responses)); |
223
|
|
|
|
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
public function getReport($values = [], $responses = []) |
227
|
|
|
{ |
228
|
|
|
return new Report($values, $this->getClient($responses)); |
229
|
|
|
|
230
|
|
|
} |
231
|
|
|
} |