FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
queue/tests/Payloads/PayloadTest.php at develop · codeigniter4/queue · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
codeigniter4
/
queue
Public
Notifications
You must be signed in to change notification settings
Fork
25
Star
75
Code
Issues
2
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
queue
/
tests
/
Payloads
/
PayloadTest.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
297 lines (229 loc) · 8.76 KB
Breadcrumbs
queue
/
tests
/
Payloads
/
PayloadTest.php
Copy path
File metadata and controls
297 lines (229 loc) · 8.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<?php
declare
(strict_types=
1
);
/**
* This file is part of CodeIgniter Queue.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace
Tests
\
Payloads
;
use
CodeIgniter
\
Queue
\
Exceptions
\
QueueException
;
use
CodeIgniter
\
Queue
\
Payloads
\
Payload
;
use
CodeIgniter
\
Queue
\
Payloads
\
PayloadCollection
;
use
CodeIgniter
\
Queue
\
Payloads
\
PayloadMetadata
;
use
Tests
\
Support
\
TestCase
;
/**
* @internal
*/
final
class
PayloadTest
extends
TestCase
{
private
Payload
$
payload
;
protected
function
setUp
():
void
{
parent
::
setUp
();
$
this
->
payload
=
new
Payload
(
'
job
'
, [
'
key
'
=>
'
value
'
]);
}
public
function
testConstructor
():
void
{
$
this
->
assertSame
(
'
job
'
,
$
this
->
payload
->
getJob
());
$
this
->
assertSame
([
'
key
'
=>
'
value
'
],
$
this
->
payload
->
getData
());
}
public
function
testConstructorWithMetadata
():
void
{
$
metadata
=
new
PayloadMetadata
();
$
metadata
->
set
(
'
priority
'
,
'
high
'
);
$
payload
=
new
Payload
(
'
job
'
, [
'
key
'
=>
'
value
'
],
$
metadata
);
$
this
->
assertSame
(
'
high
'
,
$
payload
->
getMetadata
()->
get
(
'
priority
'
));
}
public
function
testGetJob
():
void
{
$
this
->
assertSame
(
'
job
'
,
$
this
->
payload
->
getJob
());
}
public
function
testGetData
():
void
{
$
this
->
assertSame
([
'
key
'
=>
'
value
'
],
$
this
->
payload
->
getData
());
}
public
function
testGetMetadata
():
void
{
$
metadata
=
$
this
->
payload
->
getMetadata
();
$
this
->
assertInstanceOf
(PayloadMetadata::class,
$
metadata
);
}
public
function
testSetMetadata
():
void
{
$
metadata
=
new
PayloadMetadata
();
$
metadata
->
set
(
'
priority
'
,
'
high
'
);
$
result
=
$
this
->
payload
->
setMetadata
(
$
metadata
);
$
this
->
assertInstanceOf
(Payload::class,
$
result
);
$
this
->
assertSame
(
'
high
'
,
$
this
->
payload
->
getMetadata
()->
get
(
'
priority
'
));
}
public
function
testSetQueue
():
void
{
$
result
=
$
this
->
payload
->
setQueue
(
'
queue
'
);
$
this
->
assertInstanceOf
(Payload::class,
$
result
);
$
this
->
assertSame
(
'
queue
'
,
$
this
->
payload
->
getQueue
());
}
public
function
testSetQueueWithInvalidFormat
():
void
{
$
this
->
expectException
(QueueException::class);
$
this
->
payload
->
setQueue
(
'
invalid queue name!
'
);
}
public
function
testSetQueueWithTooLongName
():
void
{
$
this
->
expectException
(QueueException::class);
$
this
->
payload
->
setQueue
(
str_repeat
(
'
a
'
,
65
));
// 65 characters, too long
}
public
function
testGetQueue
():
void
{
$
this
->
payload
->
setQueue
(
'
queue
'
);
$
this
->
assertSame
(
'
queue
'
,
$
this
->
payload
->
getQueue
());
}
public
function
testSetPriority
():
void
{
$
result
=
$
this
->
payload
->
setPriority
(
'
high
'
);
$
this
->
assertInstanceOf
(Payload::class,
$
result
);
$
this
->
assertSame
(
'
high
'
,
$
this
->
payload
->
getPriority
());
}
public
function
testSetPriorityWithInvalidFormat
():
void
{
$
this
->
expectException
(QueueException::class);
$
this
->
payload
->
setPriority
(
'
invalid priority!
'
);
}
public
function
testSetPriorityWithTooLongName
():
void
{
$
this
->
expectException
(QueueException::class);
$
this
->
payload
->
setPriority
(
str_repeat
(
'
a
'
,
65
));
// 65 characters, too long
}
public
function
testGetPriority
():
void
{
$
this
->
payload
->
setPriority
(
'
high
'
);
$
this
->
assertSame
(
'
high
'
,
$
this
->
payload
->
getPriority
());
}
public
function
testSetDelay
():
void
{
$
result
=
$
this
->
payload
->
setDelay
(
60
);
$
this
->
assertInstanceOf
(Payload::class,
$
result
);
$
this
->
assertSame
(
60
,
$
this
->
payload
->
getDelay
());
}
public
function
testSetDelayWithNegativeValue
():
void
{
$
this
->
expectException
(QueueException::class);
$
this
->
payload
->
setDelay
(-
1
);
}
public
function
testGetDelay
():
void
{
$
this
->
payload
->
setDelay
(
60
);
$
this
->
assertSame
(
60
,
$
this
->
payload
->
getDelay
());
}
public
function
testSetChainedJobs
():
void
{
$
payloads
=
new
PayloadCollection
();
$
payloads
->
add
(
new
Payload
(
'
nextJob
'
, [
'
nextKey
'
=>
'
nextValue
'
]));
$
result
=
$
this
->
payload
->
setChainedJobs
(
$
payloads
);
$
this
->
assertInstanceOf
(Payload::class,
$
result
);
$
this
->
assertTrue
(
$
this
->
payload
->
hasChainedJobs
());
}
public
function
testGetChainedJobs
():
void
{
$
payloads
=
new
PayloadCollection
();
$
payloads
->
add
(
new
Payload
(
'
nextJob
'
, [
'
nextKey
'
=>
'
nextValue
'
]));
$
this
->
payload
->
setChainedJobs
(
$
payloads
);
$
chainedJobs
=
$
this
->
payload
->
getChainedJobs
();
$
this
->
assertInstanceOf
(PayloadCollection::class,
$
chainedJobs
);
$
this
->
assertCount
(
1
,
$
chainedJobs
);
}
public
function
testHasChainedJobs
():
void
{
$
this
->
assertFalse
(
$
this
->
payload
->
hasChainedJobs
());
$
payloads
=
new
PayloadCollection
();
$
payloads
->
add
(
new
Payload
(
'
nextJob
'
, [
'
nextKey
'
=>
'
nextValue
'
]));
$
this
->
payload
->
setChainedJobs
(
$
payloads
);
$
this
->
assertTrue
(
$
this
->
payload
->
hasChainedJobs
());
}
public
function
testJsonSerialize
():
void
{
$
this
->
payload
->
setQueue
(
'
queue
'
);
$
this
->
payload
->
setPriority
(
'
high
'
);
$
json
=
json_encode
(
$
this
->
payload
);
$
decoded
=
json_decode
(
$
json
,
true
);
$
this
->
assertIsArray
(
$
decoded
);
$
this
->
assertSame
(
'
job
'
,
$
decoded
[
'
job
'
]);
$
this
->
assertSame
([
'
key
'
=>
'
value
'
],
$
decoded
[
'
data
'
]);
$
this
->
assertIsArray
(
$
decoded
[
'
metadata
'
]);
$
this
->
assertSame
(
'
queue
'
,
$
decoded
[
'
metadata
'
][
'
queue
'
]);
$
this
->
assertSame
(
'
high
'
,
$
decoded
[
'
metadata
'
][
'
priority
'
]);
}
public
function
testJsonSerializeWithChainedJobs
():
void
{
$
this
->
payload
->
setQueue
(
'
queue
'
);
$
nextPayload
=
new
Payload
(
'
nextJob
'
, [
'
nextKey
'
=>
'
nextValue
'
]);
$
nextPayload
->
setQueue
(
'
queue
'
);
$
payloads
=
new
PayloadCollection
();
$
payloads
->
add
(
$
nextPayload
);
$
this
->
payload
->
setChainedJobs
(
$
payloads
);
$
json
=
json_encode
(
$
this
->
payload
);
$
decoded
=
json_decode
(
$
json
,
true
);
$
this
->
assertIsArray
(
$
decoded
);
$
this
->
assertArrayHasKey
(
'
metadata
'
,
$
decoded
);
$
this
->
assertArrayHasKey
(
'
chainedJobs
'
,
$
decoded
[
'
metadata
'
]);
$
this
->
assertIsArray
(
$
decoded
[
'
metadata
'
][
'
chainedJobs
'
]);
$
this
->
assertCount
(
1
,
$
decoded
[
'
metadata
'
][
'
chainedJobs
'
]);
$
this
->
assertSame
(
'
nextJob
'
,
$
decoded
[
'
metadata
'
][
'
chainedJobs
'
][
0
][
'
job
'
]);
$
this
->
assertSame
([
'
nextKey
'
=>
'
nextValue
'
],
$
decoded
[
'
metadata
'
][
'
chainedJobs
'
][
0
][
'
data
'
]);
}
public
function
testFromArray
():
void
{
$
data
= [
'
job
'
=>
'
job
'
,
'
data
'
=> [
'
key
'
=>
'
value
'
],
'
metadata
'
=> [
'
queue
'
=>
'
queue
'
,
'
priority
'
=>
'
high
'
,
],
];
$
payload
= Payload::
fromArray
(
$
data
);
$
this
->
assertSame
(
'
job
'
,
$
payload
->
getJob
());
$
this
->
assertSame
([
'
key
'
=>
'
value
'
],
$
payload
->
getData
());
$
this
->
assertSame
(
'
queue
'
,
$
payload
->
getQueue
());
$
this
->
assertSame
(
'
high
'
,
$
payload
->
getPriority
());
}
public
function
testFromArrayWithChainedJobs
():
void
{
$
data
= [
'
job
'
=>
'
job
'
,
'
data
'
=> [
'
key
'
=>
'
value
'
],
'
metadata
'
=> [
'
queue
'
=>
'
queue
'
,
'
chainedJobs
'
=> [
[
'
job
'
=>
'
nextJob
'
,
'
data
'
=> [
'
nextKey
'
=>
'
nextValue
'
],
'
metadata
'
=> [
'
queue
'
=>
'
nextQueue
'
],
],
],
],
];
$
payload
= Payload::
fromArray
(
$
data
);
$
this
->
assertTrue
(
$
payload
->
hasChainedJobs
());
$
chainedJobs
=
$
payload
->
getChainedJobs
();
$
this
->
assertCount
(
1
,
$
chainedJobs
);
$
this
->
assertInstanceOf
(PayloadCollection::class,
$
chainedJobs
);
$
nextJob
=
$
chainedJobs
->
shift
();
$
this
->
assertInstanceOf
(Payload::class,
$
nextJob
);
$
this
->
assertSame
(
'
nextJob
'
,
$
nextJob
->
getJob
());
$
this
->
assertSame
([
'
nextKey
'
=>
'
nextValue
'
],
$
nextJob
->
getData
());
$
this
->
assertSame
(
'
nextQueue
'
,
$
nextJob
->
getQueue
());
}
public
function
testMultipleValidations
():
void
{
$
payload
=
new
Payload
(
'
job
'
, [
'
key
'
=>
'
value
'
]);
// Test that all validations pass
$
payload
->
setQueue
(
'
valid-queue
'
);
$
payload
->
setPriority
(
'
valid-priority
'
);
$
payload
->
setDelay
(
30
);
$
this
->
assertSame
(
'
valid-queue
'
,
$
payload
->
getQueue
());
$
this
->
assertSame
(
'
valid-priority
'
,
$
payload
->
getPriority
());
$
this
->
assertSame
(
30
,
$
payload
->
getDelay
());
}
}
Back
|
FazBrowse Home
|
New Git URL