88use Bdf \Queue \Message \Message ;
99use Bdf \Queue \Message \QueuedMessage ;
1010use Bdf \Queue \Serializer \JsonSerializer ;
11+ use Pheanstalk \Contract \PheanstalkInterface ;
12+ use Pheanstalk \Contract \ResponseInterface ;
1113use Pheanstalk \Exception \SocketException ;
1214use Pheanstalk \Job as PheanstalkJob ;
1315use Pheanstalk \Pheanstalk ;
14- use Pheanstalk \PheanstalkInterface ;
16+ use Pheanstalk \Response \ ArrayResponse ;
1517use PHPUnit \Framework \MockObject \MockObject ;
1618use PHPUnit \Framework \TestCase ;
1719
20+ use function class_exists ;
21+ use function method_exists ;
22+
1823/**
1924 * @group Bdf_Queue
2025 * @group Bdf_Queue_Connection
@@ -37,6 +42,7 @@ class PheanstalkQueueTest extends TestCase
3742 */
3843 public function setUp (): void
3944 {
45+ class_exists (PheanstalkConnection::class); // Autoload Pheanstalk classes to ensure that interface alias is defined
4046 $ this ->pheanstalk = $ this ->createMock (PheanstalkInterface::class);
4147
4248 $ connection = new PheanstalkConnection ('foo ' , new JsonSerializer ());
@@ -139,7 +145,12 @@ public function test_pop()
139145 $ job ->expects ($ this ->once ())->method ('getData ' )->willReturn ('{"data":"foo"} ' );
140146
141147 $ this ->pheanstalk ->expects ($ this ->once ())->method ('watchOnly ' )->with ('queue ' )->willReturnSelf ();
142- $ this ->pheanstalk ->expects ($ this ->once ())->method ('reserve ' )->with (1 )->willReturn ($ job );
148+
149+ if (method_exists (Pheanstalk::class, 'reserveWithTimeout ' )) {
150+ $ this ->pheanstalk ->expects ($ this ->once ())->method ('reserveWithTimeout ' )->with (1 )->willReturn ($ job );
151+ } else {
152+ $ this ->pheanstalk ->expects ($ this ->once ())->method ('reserve ' )->with (1 )->willReturn ($ job );
153+ }
143154
144155 $ message = $ this ->driver ->pop ('queue ' , 1 )->message ();
145156
@@ -156,7 +167,12 @@ public function test_pop()
156167 public function test_pop_end_of_queue ()
157168 {
158169 $ this ->pheanstalk ->expects ($ this ->once ())->method ('watchOnly ' )->willReturnSelf ();
159- $ this ->pheanstalk ->expects ($ this ->once ())->method ('reserve ' )->willReturn (null );
170+
171+ if (method_exists (Pheanstalk::class, 'reserveWithTimeout ' )) {
172+ $ this ->pheanstalk ->expects ($ this ->once ())->method ('reserveWithTimeout ' )->willReturn (null );
173+ } else {
174+ $ this ->pheanstalk ->expects ($ this ->once ())->method ('reserve ' )->willReturn (null );
175+ }
160176
161177 $ this ->assertSame (null , $ this ->driver ->pop ('queue ' , 1 ));
162178 }
@@ -168,7 +184,11 @@ public function test_pop_error($expected, $internal)
168184 {
169185 $ this ->expectException ($ expected );
170186 $ this ->pheanstalk ->expects ($ this ->once ())->method ('watchOnly ' )->willReturnSelf ();
171- $ this ->pheanstalk ->expects ($ this ->once ())->method ('reserve ' )->willThrowException ($ internal );
187+ if (method_exists (Pheanstalk::class, 'reserveWithTimeout ' )) {
188+ $ this ->pheanstalk ->expects ($ this ->once ())->method ('reserveWithTimeout ' )->willThrowException ($ internal );
189+ } else {
190+ $ this ->pheanstalk ->expects ($ this ->once ())->method ('reserve ' )->willThrowException ($ internal );
191+ }
172192
173193 $ this ->driver ->pop ('queue ' , 1 );
174194 }
@@ -236,7 +256,7 @@ public function test_release_error($expected, $internal)
236256 */
237257 public function test_count ()
238258 {
239- $ this ->pheanstalk ->expects ($ this ->once ())->method ('statsTube ' )->with ('queue ' )->willReturn (['current-jobs-ready ' => 1 ]);
259+ $ this ->pheanstalk ->expects ($ this ->once ())->method ('statsTube ' )->with ('queue ' )->willReturn (new ArrayResponse ( '' , ['current-jobs-ready ' => 1 ]) );
240260
241261 $ this ->assertSame (1 , $ this ->driver ->count ('queue ' ));
242262 }
0 commit comments