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