@@ -66,6 +66,155 @@ public function testShouldJsonEncodeMessageAndPutToExpectedTube()
6666 );
6767 }
6868
69+ public function testMessagePriorityPrecedesPriority ()
70+ {
71+ $ message = new PheanstalkMessage ('theBody ' );
72+ $ message ->setPriority (100 );
73+
74+ $ pheanstalk = $ this ->createPheanstalkMock ();
75+ $ pheanstalk
76+ ->expects ($ this ->once ())
77+ ->method ('useTube ' )
78+ ->with ('theQueueName ' )
79+ ->willReturnSelf ()
80+ ;
81+ $ pheanstalk
82+ ->expects ($ this ->once ())
83+ ->method ('put ' )
84+ ->with ('{"body":"theBody","properties":[],"headers":{"priority":100}} ' , 100 , Pheanstalk::DEFAULT_DELAY , Pheanstalk::DEFAULT_TTR )
85+ ;
86+
87+ $ producer = new PheanstalkProducer ($ pheanstalk );
88+ $ producer ->setPriority (50 );
89+
90+ $ producer ->send (
91+ new PheanstalkDestination ('theQueueName ' ),
92+ $ message
93+ );
94+ }
95+
96+ public function testAccessDeliveryDelayAsMilliseconds ()
97+ {
98+ $ producer = new PheanstalkProducer ($ this ->createPheanstalkMock ());
99+ $ producer ->setDeliveryDelay (5000 );
100+
101+ $ this ->assertEquals (5000 , $ producer ->getDeliveryDelay ());
102+ }
103+
104+ public function testDeliveryDelayResolvesToSeconds ()
105+ {
106+ $ message = new PheanstalkMessage ('theBody ' );
107+
108+ $ pheanstalk = $ this ->createPheanstalkMock ();
109+ $ pheanstalk
110+ ->expects ($ this ->once ())
111+ ->method ('useTube ' )
112+ ->with ('theQueueName ' )
113+ ->willReturnSelf ()
114+ ;
115+ $ pheanstalk
116+ ->expects ($ this ->once ())
117+ ->method ('put ' )
118+ ->with ('{"body":"theBody","properties":[],"headers":[]} ' , Pheanstalk::DEFAULT_PRIORITY , 5 , Pheanstalk::DEFAULT_TTR )
119+ ;
120+
121+ $ producer = new PheanstalkProducer ($ pheanstalk );
122+ $ producer ->setDeliveryDelay (5000 );
123+
124+ $ producer ->send (
125+ new PheanstalkDestination ('theQueueName ' ),
126+ $ message
127+ );
128+ }
129+
130+ public function testMessageDelayPrecedesDeliveryDelay ()
131+ {
132+ $ message = new PheanstalkMessage ('theBody ' );
133+ $ message ->setDelay (25 );
134+
135+ $ pheanstalk = $ this ->createPheanstalkMock ();
136+ $ pheanstalk
137+ ->expects ($ this ->once ())
138+ ->method ('useTube ' )
139+ ->with ('theQueueName ' )
140+ ->willReturnSelf ()
141+ ;
142+ $ pheanstalk
143+ ->expects ($ this ->once ())
144+ ->method ('put ' )
145+ ->with ('{"body":"theBody","properties":[],"headers":{"delay":25}} ' , Pheanstalk::DEFAULT_PRIORITY , 25 , Pheanstalk::DEFAULT_TTR )
146+ ;
147+
148+ $ producer = new PheanstalkProducer ($ pheanstalk );
149+ $ producer ->setDeliveryDelay (1000 );
150+
151+ $ producer ->send (
152+ new PheanstalkDestination ('theQueueName ' ),
153+ $ message
154+ );
155+ }
156+
157+ public function testAccessTimeToLiveAsMilliseconds ()
158+ {
159+ $ producer = new PheanstalkProducer ($ this ->createPheanstalkMock ());
160+ $ producer ->setTimeToLive (5000 );
161+
162+ $ this ->assertEquals (5000 , $ producer ->getTimeToLive ());
163+ }
164+
165+ public function testTimeToLiveResolvesToSeconds ()
166+ {
167+ $ message = new PheanstalkMessage ('theBody ' );
168+
169+ $ pheanstalk = $ this ->createPheanstalkMock ();
170+ $ pheanstalk
171+ ->expects ($ this ->once ())
172+ ->method ('useTube ' )
173+ ->with ('theQueueName ' )
174+ ->willReturnSelf ()
175+ ;
176+ $ pheanstalk
177+ ->expects ($ this ->once ())
178+ ->method ('put ' )
179+ ->with ('{"body":"theBody","properties":[],"headers":[]} ' , Pheanstalk::DEFAULT_PRIORITY , Pheanstalk::DEFAULT_DELAY , 5 )
180+ ;
181+
182+ $ producer = new PheanstalkProducer ($ pheanstalk );
183+ $ producer ->setTimeToLive (5000 );
184+
185+ $ producer ->send (
186+ new PheanstalkDestination ('theQueueName ' ),
187+ $ message
188+ );
189+ }
190+
191+ public function testMessageTimeToRunPrecedesTimeToLive ()
192+ {
193+ $ message = new PheanstalkMessage ('theBody ' );
194+ $ message ->setTimeToRun (25 );
195+
196+ $ pheanstalk = $ this ->createPheanstalkMock ();
197+ $ pheanstalk
198+ ->expects ($ this ->once ())
199+ ->method ('useTube ' )
200+ ->with ('theQueueName ' )
201+ ->willReturnSelf ()
202+ ;
203+ $ pheanstalk
204+ ->expects ($ this ->once ())
205+ ->method ('put ' )
206+ ->with ('{"body":"theBody","properties":[],"headers":{"ttr":25}} ' , Pheanstalk::DEFAULT_PRIORITY , Pheanstalk::DEFAULT_DELAY , 25 )
207+ ;
208+
209+ $ producer = new PheanstalkProducer ($ pheanstalk );
210+ $ producer ->setTimeToLive (1000 );
211+
212+ $ producer ->send (
213+ new PheanstalkDestination ('theQueueName ' ),
214+ $ message
215+ );
216+ }
217+
69218 /**
70219 * @return MockObject|Pheanstalk
71220 */
0 commit comments