Test Failed
Push — master ( 7c4720...fd955c )
by Lyal
04:00 queued 14s
created

AbstractEntityTest::testIsset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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 = '{
0 ignored issues
show
Unused Code introduced by
The property $jsonAdverseItem is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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 = '  {
0 ignored issues
show
Unused Code introduced by
The property $jsonProgram is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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;
0 ignored issues
show
Bug Best Practice introduced by
The property testBadValue does not exist on Lyal\Checkr\Entities\Resources\AdverseItem. Since you implemented __set, consider adding a @property annotation.
Loading history...
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);
0 ignored issues
show
Bug Best Practice introduced by
The property candidate_id does not exist on Lyal\Checkr\Entities\Resources\Document. Since you implemented __get, consider adding a @property annotation.
Loading history...
97
    }
98
99 View Code Duplication
    public function testCreateObject()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
    {
101
        $responses = [
102
            new Response(201, [], $this->jsonReport),
103
        ];
104
        $report = $this->getReport([], $responses)->create();
105
106
        $this->assertEquals('4722c07dd9a10c3985ae432a', $report->id);
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on Lyal\Checkr\Entities\Resources\Report. Since you implemented __get, consider adding a @property annotation.
Loading history...
107
    }
108
109 View Code Duplication
    public function testFailedCreateObject()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111
        $this->expectException(ResourceNotCreated::class);
112
        $responses = [
113
            new Response(200, [], $this->jsonReport),
114
        ];
115
        $report = $this->getReport([], $responses)->create();
0 ignored issues
show
Unused Code introduced by
The assignment to $report is dead and can be removed.
Loading history...
116
117
    }
118
119 View Code Duplication
    public function testSaveObject()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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);
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on Lyal\Checkr\Entities\Resources\Report. Since you implemented __get, consider adding a @property annotation.
Loading history...
128
    }
129
130
    public function testFailedSaveObject()
131
    {
132
        $this->expectException(IdMissing::class);
133
        $report = $this->getReport()->save();
0 ignored issues
show
Unused Code introduced by
The assignment to $report is dead and can be removed.
Loading history...
134
    }
135
136
137
    public function testSetBadAttribute()
138
    {
139
        $this->expectException(InvalidAttributeException::class);
140
        $adverseItem = $this->getAdverseItem();
141
        $adverseItem->testBadValue = 1;
0 ignored issues
show
Bug Best Practice introduced by
The property testBadValue does not exist on Lyal\Checkr\Entities\Resources\AdverseItem. Since you implemented __set, consider adding a @property annotation.
Loading history...
142
    }
143
144
145
    public function testGetBadAttribute()
146
    {
147
        $this->expectException(InvalidAttributeException::class);
148
        $adverseItem = $this->getAdverseItem();
149
        $p = $adverseItem->testBadValue;
0 ignored issues
show
Bug Best Practice introduced by
The property testBadValue does not exist on Lyal\Checkr\Entities\Resources\AdverseItem. Since you implemented __get, consider adding a @property annotation.
Loading history...
Unused Code introduced by
The assignment to $p is dead and can be removed.
Loading history...
150
    }
151
152
    public function testIsset()
153
    {
154
        $adverseItem = $this->getAdverseItem();
155
        $adverseItem->id = '1';
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on Lyal\Checkr\Entities\Resources\AdverseItem. Since you implemented __set, consider adding a @property annotation.
Loading history...
156
        $this->assertTrue(isset($adverseItem->id));
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on Lyal\Checkr\Entities\Resources\AdverseItem. Since you implemented __get, consider adding a @property annotation.
Loading history...
157
158
        $this->assertFalse(isset($adverseItem->object));
0 ignored issues
show
Bug Best Practice introduced by
The property object does not exist on Lyal\Checkr\Entities\Resources\AdverseItem. Since you implemented __get, consider adding a @property annotation.
Loading history...
159
160
    }
161
162
163
    public function testClientMethod()
164
    {
165
        $report = $this->getReport()->adverseItem();
0 ignored issues
show
Bug introduced by
The method adverseItem() does not exist on Lyal\Checkr\Entities\Resources\Report. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

165
        $report = $this->getReport()->/** @scrutinizer ignore-call */ adverseItem();
Loading history...
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';
0 ignored issues
show
Bug Best Practice introduced by
The property id3 does not exist on Lyal\Checkr\Entities\Resources\Geo. Since you implemented __set, consider adding a @property annotation.
Loading history...
201
        $this->assertEquals('hi', $geo->id3);
0 ignored issues
show
Bug Best Practice introduced by
The property id3 does not exist on Lyal\Checkr\Entities\Resources\Geo. Since you implemented __get, consider adding a @property annotation.
Loading history...
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
}