FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
framework/tests/Queue/QueueSqsQueueTest.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
/
QueueSqsQueueTest.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
117 lines (101 loc) · 7.12 KB
Breadcrumbs
framework
/
tests
/
Queue
/
QueueSqsQueueTest.php
Copy path
File metadata and controls
executable file
·
117 lines (101 loc) · 7.12 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
<?php
use
Aws
\
Result
;
use
Mockery
as
m
;
use
Aws
\
Sqs
\
SqsClient
;
class
QueueSqsQueueTest
extends
PHPUnit_Framework_TestCase
{
public
function
tearDown
()
{
m::
close
();
}
public
function
setUp
()
{
// Use Mockery to mock the SqsClient
$
this
->
sqs
= m::
mock
(
'
Aws\Sqs\SqsClient
'
);
$
this
->
account
=
'
1234567891011
'
;
$
this
->
queueName
=
'
emails
'
;
$
this
->
baseUrl
=
'
https://sqs.someregion.amazonaws.com
'
;
// This is how the modified getQueue builds the queueUrl
$
this
->
prefix
=
$
this
->
baseUrl
.
'
/
'
.
$
this
->
account
.
'
/
'
;
$
this
->
queueUrl
=
$
this
->
prefix
.
$
this
->
queueName
;
$
this
->
mockedJob
=
'
foo
'
;
$
this
->
mockedData
= [
'
data
'
];
$
this
->
mockedPayload
=
json_encode
([
'
job
'
=>
$
this
->
mockedJob
,
'
data
'
=>
$
this
->
mockedData
]);
$
this
->
mockedDelay
=
10
;
$
this
->
mockedMessageId
=
'
e3cd03ee-59a3-4ad8-b0aa-ee2e3808ac81
'
;
$
this
->
mockedReceiptHandle
=
'
0NNAq8PwvXuWv5gMtS9DJ8qEdyiUwbAjpp45w2m6M4SJ1Y+PxCh7R930NRB8ylSacEmoSnW18bgd4nK\/O6ctE+VFVul4eD23mA07vVoSnPI4F\/voI1eNCp6Iax0ktGmhlNVzBwaZHEr91BRtqTRM3QKd2ASF8u+IQaSwyl\/DGK+P1+dqUOodvOVtExJwdyDLy1glZVgm85Yw9Jf5yZEEErqRwzYz\/qSigdvW4sm2l7e4phRol\/+IjMtovOyH\/ukueYdlVbQ4OshQLENhUKe7RNN5i6bE\/e5x9bnPhfj2gbM
'
;
$
this
->
mockedSendMessageResponseModel
=
new
Result
([
'
Body
'
=>
$
this
->
mockedPayload
,
'
MD5OfBody
'
=>
md5
(
$
this
->
mockedPayload
),
'
ReceiptHandle
'
=>
$
this
->
mockedReceiptHandle
,
'
MessageId
'
=>
$
this
->
mockedMessageId
,
'
Attributes
'
=> [
'
ApproximateReceiveCount
'
=>
1
], ]);
$
this
->
mockedReceiveMessageResponseModel
=
new
Result
([
'
Messages
'
=> [
0
=> [
'
Body
'
=>
$
this
->
mockedPayload
,
'
MD5OfBody
'
=>
md5
(
$
this
->
mockedPayload
),
'
ReceiptHandle
'
=>
$
this
->
mockedReceiptHandle
,
'
MessageId
'
=>
$
this
->
mockedMessageId
, ]]]);
}
public
function
testPopProperlyPopsJobOffOfSqs
()
{
$
queue
=
$
this
->
getMock
(
'
Illuminate\Queue\SqsQueue
'
, [
'
getQueue
'
], [
$
this
->
sqs
,
$
this
->
queueName
,
$
this
->
account
]);
$
queue
->
setContainer
(m::
mock
(
'
Illuminate\Container\Container
'
));
$
queue
->
expects
(
$
this
->
once
())->
method
(
'
getQueue
'
)->
with
(
$
this
->
queueName
)->
will
(
$
this
->
returnValue
(
$
this
->
queueUrl
));
$
this
->
sqs
->
shouldReceive
(
'
receiveMessage
'
)->
once
()->
with
([
'
QueueUrl
'
=>
$
this
->
queueUrl
,
'
AttributeNames
'
=> [
'
ApproximateReceiveCount
'
]])->
andReturn
(
$
this
->
mockedReceiveMessageResponseModel
);
$
result
=
$
queue
->
pop
(
$
this
->
queueName
);
$
this
->
assertInstanceOf
(
'
Illuminate\Queue\Jobs\SqsJob
'
,
$
result
);
}
public
function
testPopProperlyPopsJobOffOfSqsWithCustomJobCreator
()
{
$
queue
=
$
this
->
getMock
(
'
Illuminate\Queue\SqsQueue
'
, [
'
getQueue
'
], [
$
this
->
sqs
,
$
this
->
queueName
,
$
this
->
account
]);
$
queue
->
createJobsUsing
(
function
() {
return
'
job!
'
; });
$
queue
->
setContainer
(m::
mock
(
'
Illuminate\Container\Container
'
));
$
queue
->
expects
(
$
this
->
once
())->
method
(
'
getQueue
'
)->
with
(
$
this
->
queueName
)->
will
(
$
this
->
returnValue
(
$
this
->
queueUrl
));
$
this
->
sqs
->
shouldReceive
(
'
receiveMessage
'
)->
once
()->
with
([
'
QueueUrl
'
=>
$
this
->
queueUrl
,
'
AttributeNames
'
=> [
'
ApproximateReceiveCount
'
]])->
andReturn
(
$
this
->
mockedReceiveMessageResponseModel
);
$
result
=
$
queue
->
pop
(
$
this
->
queueName
);
$
this
->
assertEquals
(
'
job!
'
,
$
result
);
}
public
function
testDelayedPushWithDateTimeProperlyPushesJobOntoSqs
()
{
$
now
=
Carbon
\Carbon::
now
();
$
queue
=
$
this
->
getMock
(
'
Illuminate\Queue\SqsQueue
'
, [
'
createPayload
'
,
'
getSeconds
'
,
'
getQueue
'
], [
$
this
->
sqs
,
$
this
->
queueName
,
$
this
->
account
]);
$
queue
->
expects
(
$
this
->
once
())->
method
(
'
createPayload
'
)->
with
(
$
this
->
mockedJob
,
$
this
->
mockedData
)->
will
(
$
this
->
returnValue
(
$
this
->
mockedPayload
));
$
queue
->
expects
(
$
this
->
once
())->
method
(
'
getSeconds
'
)->
with
(
$
now
)->
will
(
$
this
->
returnValue
(
5
));
$
queue
->
expects
(
$
this
->
once
())->
method
(
'
getQueue
'
)->
with
(
$
this
->
queueName
)->
will
(
$
this
->
returnValue
(
$
this
->
queueUrl
));
$
this
->
sqs
->
shouldReceive
(
'
sendMessage
'
)->
once
()->
with
([
'
QueueUrl
'
=>
$
this
->
queueUrl
,
'
MessageBody
'
=>
$
this
->
mockedPayload
,
'
DelaySeconds
'
=>
5
])->
andReturn
(
$
this
->
mockedSendMessageResponseModel
);
$
id
=
$
queue
->
later
(
$
now
->
addSeconds
(
5
),
$
this
->
mockedJob
,
$
this
->
mockedData
,
$
this
->
queueName
);
$
this
->
assertEquals
(
$
this
->
mockedMessageId
,
$
id
);
}
public
function
testDelayedPushProperlyPushesJobOntoSqs
()
{
$
queue
=
$
this
->
getMock
(
'
Illuminate\Queue\SqsQueue
'
, [
'
createPayload
'
,
'
getSeconds
'
,
'
getQueue
'
], [
$
this
->
sqs
,
$
this
->
queueName
,
$
this
->
account
]);
$
queue
->
expects
(
$
this
->
once
())->
method
(
'
createPayload
'
)->
with
(
$
this
->
mockedJob
,
$
this
->
mockedData
)->
will
(
$
this
->
returnValue
(
$
this
->
mockedPayload
));
$
queue
->
expects
(
$
this
->
once
())->
method
(
'
getSeconds
'
)->
with
(
$
this
->
mockedDelay
)->
will
(
$
this
->
returnValue
(
$
this
->
mockedDelay
));
$
queue
->
expects
(
$
this
->
once
())->
method
(
'
getQueue
'
)->
with
(
$
this
->
queueName
)->
will
(
$
this
->
returnValue
(
$
this
->
queueUrl
));
$
this
->
sqs
->
shouldReceive
(
'
sendMessage
'
)->
once
()->
with
([
'
QueueUrl
'
=>
$
this
->
queueUrl
,
'
MessageBody
'
=>
$
this
->
mockedPayload
,
'
DelaySeconds
'
=>
$
this
->
mockedDelay
])->
andReturn
(
$
this
->
mockedSendMessageResponseModel
);
$
id
=
$
queue
->
later
(
$
this
->
mockedDelay
,
$
this
->
mockedJob
,
$
this
->
mockedData
,
$
this
->
queueName
);
$
this
->
assertEquals
(
$
this
->
mockedMessageId
,
$
id
);
}
public
function
testPushProperlyPushesJobOntoSqs
()
{
$
queue
=
$
this
->
getMock
(
'
Illuminate\Queue\SqsQueue
'
, [
'
createPayload
'
,
'
getQueue
'
], [
$
this
->
sqs
,
$
this
->
queueName
,
$
this
->
account
]);
$
queue
->
expects
(
$
this
->
once
())->
method
(
'
createPayload
'
)->
with
(
$
this
->
mockedJob
,
$
this
->
mockedData
)->
will
(
$
this
->
returnValue
(
$
this
->
mockedPayload
));
$
queue
->
expects
(
$
this
->
once
())->
method
(
'
getQueue
'
)->
with
(
$
this
->
queueName
)->
will
(
$
this
->
returnValue
(
$
this
->
queueUrl
));
$
this
->
sqs
->
shouldReceive
(
'
sendMessage
'
)->
once
()->
with
([
'
QueueUrl
'
=>
$
this
->
queueUrl
,
'
MessageBody
'
=>
$
this
->
mockedPayload
])->
andReturn
(
$
this
->
mockedSendMessageResponseModel
);
$
id
=
$
queue
->
push
(
$
this
->
mockedJob
,
$
this
->
mockedData
,
$
this
->
queueName
);
$
this
->
assertEquals
(
$
this
->
mockedMessageId
,
$
id
);
}
public
function
testGetQueueProperlyResolvesUrlWithPrefix
()
{
$
queue
=
new
Illuminate
\
Queue
\
SqsQueue
(
$
this
->
sqs
,
$
this
->
queueName
,
$
this
->
prefix
);
$
this
->
assertEquals
(
$
this
->
queueUrl
,
$
queue
->
getQueue
(
null
));
$
queueUrl
=
$
this
->
baseUrl
.
'
/
'
.
$
this
->
account
.
'
/test
'
;
$
this
->
assertEquals
(
$
queueUrl
,
$
queue
->
getQueue
(
'
test
'
));
}
public
function
testGetQueueProperlyResolvesUrlWithoutPrefix
()
{
$
queue
=
new
Illuminate
\
Queue
\
SqsQueue
(
$
this
->
sqs
,
$
this
->
queueUrl
);
$
this
->
assertEquals
(
$
this
->
queueUrl
,
$
queue
->
getQueue
(
null
));
$
queueUrl
=
$
this
->
baseUrl
.
'
/
'
.
$
this
->
account
.
'
/test
'
;
$
this
->
assertEquals
(
$
queueUrl
,
$
queue
->
getQueue
(
$
queueUrl
));
}
}
Back
|
FazBrowse Home
|
New Git URL