FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
framework/tests/Queue/QueueWorkerTest.php at master · JavaDevl/framework · GitHub
JavaDevl
/
framework
Public
forked from
laravel/framework
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
framework
/
tests
/
Queue
/
QueueWorkerTest.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
89 lines (75 loc) · 4.13 KB
Breadcrumbs
framework
/
tests
/
Queue
/
QueueWorkerTest.php
Copy path
File metadata and controls
executable file
·
89 lines (75 loc) · 4.13 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
<?php
use
Mockery
as
m
;
class
QueueWorkerTest
extends
PHPUnit_Framework_TestCase
{
public
function
tearDown
()
{
m::
close
();
}
public
function
testJobIsPoppedOffQueueAndProcessed
()
{
$
worker
=
$
this
->
getMock
(
'
Illuminate\Queue\Worker
'
, [
'
process
'
], [
$
manager
= m::
mock
(
'
Illuminate\Queue\QueueManager
'
)]);
$
manager
->
shouldReceive
(
'
connection
'
)->
once
()->
with
(
'
connection
'
)->
andReturn
(
$
connection
= m::
mock
(
'
StdClass
'
));
$
manager
->
shouldReceive
(
'
getName
'
)->
andReturn
(
'
connection
'
);
$
job
= m::
mock
(
'
Illuminate\Contracts\Queue\Job
'
);
$
connection
->
shouldReceive
(
'
pop
'
)->
once
()->
with
(
'
queue
'
)->
andReturn
(
$
job
);
$
worker
->
expects
(
$
this
->
once
())->
method
(
'
process
'
)->
with
(
$
this
->
equalTo
(
'
connection
'
),
$
this
->
equalTo
(
$
job
),
$
this
->
equalTo
(
0
),
$
this
->
equalTo
(
0
));
$
worker
->
pop
(
'
connection
'
,
'
queue
'
);
}
public
function
testJobIsPoppedOffFirstQueueInListAndProcessed
()
{
$
worker
=
$
this
->
getMock
(
'
Illuminate\Queue\Worker
'
, [
'
process
'
], [
$
manager
= m::
mock
(
'
Illuminate\Queue\QueueManager
'
)]);
$
manager
->
shouldReceive
(
'
connection
'
)->
once
()->
with
(
'
connection
'
)->
andReturn
(
$
connection
= m::
mock
(
'
StdClass
'
));
$
manager
->
shouldReceive
(
'
getName
'
)->
andReturn
(
'
connection
'
);
$
job
= m::
mock
(
'
Illuminate\Contracts\Queue\Job
'
);
$
connection
->
shouldReceive
(
'
pop
'
)->
once
()->
with
(
'
queue1
'
)->
andReturn
(
null
);
$
connection
->
shouldReceive
(
'
pop
'
)->
once
()->
with
(
'
queue2
'
)->
andReturn
(
$
job
);
$
worker
->
expects
(
$
this
->
once
())->
method
(
'
process
'
)->
with
(
$
this
->
equalTo
(
'
connection
'
),
$
this
->
equalTo
(
$
job
),
$
this
->
equalTo
(
0
),
$
this
->
equalTo
(
0
));
$
worker
->
pop
(
'
connection
'
,
'
queue1,queue2
'
);
}
public
function
testWorkerSleepsIfNoJobIsPresentAndSleepIsEnabled
()
{
$
worker
=
$
this
->
getMock
(
'
Illuminate\Queue\Worker
'
, [
'
process
'
,
'
sleep
'
], [
$
manager
= m::
mock
(
'
Illuminate\Queue\QueueManager
'
)]);
$
manager
->
shouldReceive
(
'
connection
'
)->
once
()->
with
(
'
connection
'
)->
andReturn
(
$
connection
= m::
mock
(
'
StdClass
'
));
$
connection
->
shouldReceive
(
'
pop
'
)->
once
()->
with
(
'
queue
'
)->
andReturn
(
null
);
$
worker
->
expects
(
$
this
->
never
())->
method
(
'
process
'
);
$
worker
->
expects
(
$
this
->
once
())->
method
(
'
sleep
'
)->
with
(
$
this
->
equalTo
(
3
));
$
worker
->
pop
(
'
connection
'
,
'
queue
'
,
0
,
3
);
}
public
function
testWorkerLogsJobToFailedQueueIfMaxTriesHasBeenExceeded
()
{
$
worker
=
new
Illuminate
\
Queue
\
Worker
(m::
mock
(
'
Illuminate\Queue\QueueManager
'
),
$
failer
= m::
mock
(
'
Illuminate\Queue\Failed\FailedJobProviderInterface
'
));
$
job
= m::
mock
(
'
Illuminate\Contracts\Queue\Job
'
);
$
job
->
shouldReceive
(
'
attempts
'
)->
once
()->
andReturn
(
10
);
$
job
->
shouldReceive
(
'
getQueue
'
)->
once
()->
andReturn
(
'
queue
'
);
$
job
->
shouldReceive
(
'
getRawBody
'
)->
once
()->
andReturn
(
'
body
'
);
$
job
->
shouldReceive
(
'
delete
'
)->
once
();
$
job
->
shouldReceive
(
'
failed
'
)->
once
();
$
failer
->
shouldReceive
(
'
log
'
)->
once
()->
with
(
'
connection
'
,
'
queue
'
,
'
body
'
);
$
worker
->
process
(
'
connection
'
,
$
job
,
3
,
0
);
}
/**
* @expectedException RuntimeException
*/
public
function
testJobIsReleasedWhenExceptionIsThrown
()
{
$
worker
=
new
Illuminate
\
Queue
\
Worker
(m::
mock
(
'
Illuminate\Queue\QueueManager
'
));
$
job
= m::
mock
(
'
Illuminate\Contracts\Queue\Job
'
);
$
job
->
shouldReceive
(
'
fire
'
)->
once
()->
andReturnUsing
(
function
() {
throw
new
RuntimeException
; });
$
job
->
shouldReceive
(
'
isDeleted
'
)->
once
()->
andReturn
(
false
);
$
job
->
shouldReceive
(
'
release
'
)->
once
()->
with
(
5
);
$
worker
->
process
(
'
connection
'
,
$
job
,
0
,
5
);
}
/**
* @expectedException RuntimeException
*/
public
function
testJobIsNotReleasedWhenExceptionIsThrownButJobIsDeleted
()
{
$
worker
=
new
Illuminate
\
Queue
\
Worker
(m::
mock
(
'
Illuminate\Queue\QueueManager
'
));
$
job
= m::
mock
(
'
Illuminate\Contracts\Queue\Job
'
);
$
job
->
shouldReceive
(
'
fire
'
)->
once
()->
andReturnUsing
(
function
() {
throw
new
RuntimeException
; });
$
job
->
shouldReceive
(
'
isDeleted
'
)->
once
()->
andReturn
(
true
);
$
job
->
shouldReceive
(
'
release
'
)->
never
();
$
worker
->
process
(
'
connection
'
,
$
job
,
0
,
5
);
}
}
Back
|
FazBrowse Home
|
New Git URL