1
|
|
|
<?php declare( strict_types = 1 ); |
2
|
|
|
|
3
|
|
|
namespace Coco\SourceWatcher\Tests\Vendors\StackOverflow; |
4
|
|
|
|
5
|
|
|
use Coco\SourceWatcher\Vendors\StackOverflow\StackOverflowJob; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class StackOverflowJobTest |
10
|
|
|
* @package Coco\SourceWatcher\Tests\Vendors\StackOverflow |
11
|
|
|
*/ |
12
|
|
|
class StackOverflowJobTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* |
16
|
|
|
*/ |
17
|
|
|
public function testSetGetJobId () : void |
18
|
|
|
{ |
19
|
|
|
$stackOverflowJob = new StackOverflowJob(); |
20
|
|
|
|
21
|
|
|
$givenJobId = "123456"; |
22
|
|
|
$expectedJobId = "123456"; |
23
|
|
|
|
24
|
|
|
$stackOverflowJob->setJobId( $givenJobId ); |
25
|
|
|
$this->assertNotNull( $stackOverflowJob->getJobId() ); |
26
|
|
|
$this->assertEquals( $expectedJobId, $stackOverflowJob->getJobId() ); |
27
|
|
|
|
28
|
|
|
$stackOverflowJob->setJobId( null ); |
29
|
|
|
$this->assertNull( $stackOverflowJob->getJobId() ); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* |
34
|
|
|
*/ |
35
|
|
|
public function testSetGetResultId () : void |
36
|
|
|
{ |
37
|
|
|
$stackOverflowJob = new StackOverflowJob(); |
38
|
|
|
|
39
|
|
|
$givenResultId = "123456"; |
40
|
|
|
$expectedResultId = "123456"; |
41
|
|
|
|
42
|
|
|
$stackOverflowJob->setResultId( $givenResultId ); |
43
|
|
|
$this->assertNotNull( $stackOverflowJob->getResultId() ); |
44
|
|
|
$this->assertEquals( $expectedResultId, $stackOverflowJob->getResultId() ); |
45
|
|
|
|
46
|
|
|
$stackOverflowJob->setResultId( null ); |
47
|
|
|
$this->assertNull( $stackOverflowJob->getResultId() ); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* |
52
|
|
|
*/ |
53
|
|
|
public function testSetGetPreviewURL () : void |
54
|
|
|
{ |
55
|
|
|
$stackOverflowJob = new StackOverflowJob(); |
56
|
|
|
|
57
|
|
|
$givenPreviewUrl = "https://stackoverflow.com/jobs/123456/some-developer-role"; |
58
|
|
|
$expectedPreviewUrl = "https://stackoverflow.com/jobs/123456/some-developer-role"; |
59
|
|
|
|
60
|
|
|
$stackOverflowJob->setPreviewUrl( $givenPreviewUrl ); |
61
|
|
|
$this->assertNotNull( $stackOverflowJob->getPreviewUrl() ); |
62
|
|
|
$this->assertEquals( $expectedPreviewUrl, $stackOverflowJob->getPreviewUrl() ); |
63
|
|
|
|
64
|
|
|
$stackOverflowJob->setPreviewUrl( null ); |
65
|
|
|
$this->assertNull( $stackOverflowJob->getPreviewUrl() ); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* |
70
|
|
|
*/ |
71
|
|
|
public function testSetGetLogo () : void |
72
|
|
|
{ |
73
|
|
|
$stackOverflowJob = new StackOverflowJob(); |
74
|
|
|
|
75
|
|
|
$givenLogo = "https://some-website.com/assets/some-logo.svg"; |
76
|
|
|
$expectedLogo = "https://some-website.com/assets/some-logo.svg"; |
77
|
|
|
|
78
|
|
|
$stackOverflowJob->setLogo( $givenLogo ); |
79
|
|
|
$this->assertNotNull( $stackOverflowJob->getLogo() ); |
80
|
|
|
$this->assertEquals( $expectedLogo, $stackOverflowJob->getLogo() ); |
81
|
|
|
|
82
|
|
|
$stackOverflowJob->setLogo( null ); |
83
|
|
|
$this->assertNull( $stackOverflowJob->getLogo() ); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* |
88
|
|
|
*/ |
89
|
|
|
public function testSetGetTitle () : void |
90
|
|
|
{ |
91
|
|
|
$stackOverflowJob = new StackOverflowJob(); |
92
|
|
|
|
93
|
|
|
$givenTitle = "Some Developer Role"; |
94
|
|
|
$expectedTitle = "Some Developer Role"; |
95
|
|
|
|
96
|
|
|
$stackOverflowJob->setTitle( $givenTitle ); |
97
|
|
|
$this->assertNotNull( $stackOverflowJob->getTitle() ); |
98
|
|
|
$this->assertEquals( $expectedTitle, $stackOverflowJob->getTitle() ); |
99
|
|
|
|
100
|
|
|
$stackOverflowJob->setTitle( null ); |
101
|
|
|
$this->assertNull( $stackOverflowJob->getTitle() ); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* |
106
|
|
|
*/ |
107
|
|
|
public function testSetGetCompany () : void |
108
|
|
|
{ |
109
|
|
|
$stackOverflowJob = new StackOverflowJob(); |
110
|
|
|
|
111
|
|
|
$givenCompany = "Acme Corporation"; |
112
|
|
|
$expectedCompany = "Acme Corporation"; |
113
|
|
|
|
114
|
|
|
$stackOverflowJob->setCompany( $givenCompany ); |
115
|
|
|
$this->assertNotNull( $stackOverflowJob->getCompany() ); |
116
|
|
|
$this->assertEquals( $expectedCompany, $stackOverflowJob->getCompany() ); |
117
|
|
|
|
118
|
|
|
$stackOverflowJob->setCompany( null ); |
119
|
|
|
$this->assertNull( $stackOverflowJob->getCompany() ); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* |
124
|
|
|
*/ |
125
|
|
|
public function testSetGetLocation () : void |
126
|
|
|
{ |
127
|
|
|
$stackOverflowJob = new StackOverflowJob(); |
128
|
|
|
|
129
|
|
|
$givenLocation = "Saint Denis"; |
130
|
|
|
$expectedLocation = "Saint Denis"; |
131
|
|
|
|
132
|
|
|
$stackOverflowJob->setLocation( $givenLocation ); |
133
|
|
|
$this->assertNotNull( $stackOverflowJob->getLocation() ); |
134
|
|
|
$this->assertEquals( $expectedLocation, $stackOverflowJob->getLocation() ); |
135
|
|
|
|
136
|
|
|
$stackOverflowJob->setLocation( null ); |
137
|
|
|
$this->assertNull( $stackOverflowJob->getLocation() ); |
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* |
142
|
|
|
*/ |
143
|
|
|
public function testGetRefinedUrl () : void |
144
|
|
|
{ |
145
|
|
|
$stackOverflowJob = new StackOverflowJob(); |
146
|
|
|
|
147
|
|
|
// test full URL with query parameters |
148
|
|
|
|
149
|
|
|
$givenPreviewUrl = "https://stackoverflow.com/jobs/123456/some-developer-role?param1=a¶m2=b¶m3=c"; |
150
|
|
|
$expectedPreviewUrl = "https://stackoverflow.com/jobs/123456/some-developer-role"; |
151
|
|
|
|
152
|
|
|
$stackOverflowJob->setPreviewUrl( $givenPreviewUrl ); |
153
|
|
|
|
154
|
|
|
$this->assertNotNull( $stackOverflowJob->getRefinedUrl() ); |
155
|
|
|
$this->assertEquals( $expectedPreviewUrl, $stackOverflowJob->getRefinedUrl() ); |
156
|
|
|
|
157
|
|
|
// test full URL |
158
|
|
|
|
159
|
|
|
$givenPreviewUrl = "https://stackoverflow.com/jobs/123456/some-developer-role"; |
160
|
|
|
$expectedPreviewUrl = "https://stackoverflow.com/jobs/123456/some-developer-role"; |
161
|
|
|
|
162
|
|
|
$stackOverflowJob->setPreviewUrl( $givenPreviewUrl ); |
163
|
|
|
|
164
|
|
|
$this->assertNotNull( $stackOverflowJob->getRefinedUrl() ); |
165
|
|
|
$this->assertEquals( $expectedPreviewUrl, $stackOverflowJob->getRefinedUrl() ); |
166
|
|
|
|
167
|
|
|
// test partial URL with query parameters |
168
|
|
|
|
169
|
|
|
$givenPreviewUrl = "/jobs/123456/some-developer-role?param1=a¶m2=b¶m3=c"; |
170
|
|
|
$expectedPreviewUrl = "https://stackoverflow.com/jobs/123456/some-developer-role"; |
171
|
|
|
|
172
|
|
|
$stackOverflowJob->setPreviewUrl( $givenPreviewUrl ); |
173
|
|
|
|
174
|
|
|
$this->assertNotNull( $stackOverflowJob->getRefinedUrl() ); |
175
|
|
|
$this->assertEquals( $expectedPreviewUrl, $stackOverflowJob->getRefinedUrl() ); |
176
|
|
|
|
177
|
|
|
// test partial URL |
178
|
|
|
|
179
|
|
|
$givenPreviewUrl = "/jobs/123456/some-developer-role"; |
180
|
|
|
$expectedPreviewUrl = "https://stackoverflow.com/jobs/123456/some-developer-role"; |
181
|
|
|
|
182
|
|
|
$stackOverflowJob->setPreviewUrl( $givenPreviewUrl ); |
183
|
|
|
|
184
|
|
|
$this->assertNotNull( $stackOverflowJob->getRefinedUrl() ); |
185
|
|
|
$this->assertEquals( $expectedPreviewUrl, $stackOverflowJob->getRefinedUrl() ); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* |
190
|
|
|
*/ |
191
|
|
|
public function testAllAttributesDefinedNoAttributes () : void |
192
|
|
|
{ |
193
|
|
|
$stackOverflowJob = new StackOverflowJob(); |
194
|
|
|
|
195
|
|
|
$this->assertFalse( $stackOverflowJob->allAttributesDefined() ); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* |
200
|
|
|
*/ |
201
|
|
|
public function testAllAttributesDefinedSomeAttributes () : void |
202
|
|
|
{ |
203
|
|
|
$stackOverflowJob = new StackOverflowJob(); |
204
|
|
|
$stackOverflowJob->setJobId( "123456" ); |
205
|
|
|
|
206
|
|
|
$this->assertFalse( $stackOverflowJob->allAttributesDefined() ); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* |
211
|
|
|
*/ |
212
|
|
|
public function testAllAttributesDefinedAllAttributes () : void |
213
|
|
|
{ |
214
|
|
|
$stackOverflowJob = new StackOverflowJob(); |
215
|
|
|
$stackOverflowJob->setJobId( "123456" ); |
216
|
|
|
$stackOverflowJob->setResultId( "123456" ); |
217
|
|
|
$stackOverflowJob->setPreviewUrl( "https://stackoverflow.com/jobs/123456/some-developer-role" ); |
218
|
|
|
$stackOverflowJob->setLogo( "https://some-website.com/assets/some-logo.svg" ); |
219
|
|
|
$stackOverflowJob->setTitle( "Some Developer Role" ); |
220
|
|
|
$stackOverflowJob->setCompany( "Acme Corporation" ); |
221
|
|
|
$stackOverflowJob->setLocation( "Saint Denis" ); |
222
|
|
|
$stackOverflowJob->setPreviewUrl( "https://stackoverflow.com/jobs/123456/some-developer-role" ); |
223
|
|
|
|
224
|
|
|
$this->assertTrue( $stackOverflowJob->allAttributesDefined() ); |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.