Skip to content

Commit 25c6484

Browse files
committed
fix: fixing unit test warnings
fixing unit test warnings that are throwing deprecation errors for PHPUnit 10
1 parent aa85cc0 commit 25c6484

19 files changed

+326
-351
lines changed

pkg/amqp-lib/Tests/AmqpContextTest.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -318,19 +318,19 @@ public function testShouldPurgeQueue()
318318
$context->purgeQueue($queue);
319319
}
320320

321-
public function testShouldSetQos()
321+
public function testShouldSetQos(): void
322322
{
323+
$invoked = $this->exactly(2);
323324
$channel = $this->createChannelMock();
324325
$channel
325-
->expects($this->at(0))
326+
->expects($invoked)
326327
->method('basic_qos')
327-
->with($this->identicalTo(0), $this->identicalTo(1), $this->isFalse())
328-
;
329-
$channel
330-
->expects($this->at(1))
331-
->method('basic_qos')
332-
->with($this->identicalTo(123), $this->identicalTo(456), $this->isTrue())
333-
;
328+
->willReturnCallback(function ($prefetch_size, $prefetch_count, $a_global) use ($invoked) {
329+
match ($invoked->getInvocationCount()) {
330+
1 => $this->assertSame([0, 1, false], [$prefetch_size, $prefetch_count, $a_global]),
331+
2 => $this->assertSame([123, 456, true], [$prefetch_size, $prefetch_count, $a_global]),
332+
};
333+
});
334334

335335
$connection = $this->createConnectionMock();
336336
$connection

pkg/enqueue/Tests/Client/Driver/AmqpDriverTest.php

+22-34
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Interop\Queue\Message as InteropMessage;
2323
use Interop\Queue\Producer as InteropProducer;
2424
use Interop\Queue\Queue as InteropQueue;
25+
use PHPUnit\Framework\MockObject\MockObject;
2526
use PHPUnit\Framework\TestCase;
2627

2728
class AmqpDriverTest extends TestCase
@@ -190,56 +191,43 @@ public function testShouldSetupBroker()
190191
$context = $this->createContextMock();
191192
// setup router
192193
$context
193-
->expects($this->at(0))
194+
->expects($this->once())
194195
->method('createTopic')
196+
->with($this->identicalTo($this->getRouterTransportName()))
195197
->willReturn($routerTopic)
196198
;
197199
$context
198-
->expects($this->at(1))
200+
->expects($this->once())
199201
->method('declareTopic')
200202
->with($this->identicalTo($routerTopic))
201203
;
202-
203-
$context
204-
->expects($this->at(2))
205-
->method('createQueue')
206-
->willReturn($routerQueue)
207-
;
208-
$context
209-
->expects($this->at(3))
210-
->method('declareQueue')
211-
->with($this->identicalTo($routerQueue))
212-
;
213-
214204
$context
215-
->expects($this->at(4))
205+
->expects($this->once())
216206
->method('bind')
217207
->with($this->isInstanceOf(AmqpBind::class))
218208
;
219209

220-
// setup processor with default queue
221-
$context
222-
->expects($this->at(5))
223-
->method('createQueue')
224-
->with($this->getDefaultQueueTransportName())
225-
->willReturn($processorWithDefaultQueue)
226-
;
227-
$context
228-
->expects($this->at(6))
229-
->method('declareQueue')
230-
->with($this->identicalTo($processorWithDefaultQueue))
231-
;
232-
233210
$context
234-
->expects($this->at(7))
211+
->expects($this->exactly(3))
235212
->method('createQueue')
236-
->with($this->getCustomQueueTransportName())
237-
->willReturn($processorWithCustomQueue)
213+
->with($this->logicalOr(
214+
$this->getDefaultQueueTransportName(),
215+
$this->getCustomQueueTransportName(),
216+
))
217+
->willReturnOnConsecutiveCalls(
218+
$routerQueue,
219+
$processorWithDefaultQueue,
220+
$processorWithCustomQueue
221+
)
238222
;
239223
$context
240-
->expects($this->at(8))
224+
->expects($this->exactly(3))
241225
->method('declareQueue')
242-
->with($this->identicalTo($processorWithCustomQueue))
226+
->with($this->logicalOr(
227+
$this->identicalTo($routerQueue),
228+
$this->identicalTo($processorWithDefaultQueue),
229+
$this->identicalTo($processorWithCustomQueue)
230+
))
243231
;
244232

245233
$driver = new AmqpDriver(
@@ -290,7 +278,7 @@ protected function createDriver(...$args): DriverInterface
290278
}
291279

292280
/**
293-
* @return AmqpContext
281+
* @return AmqpContext&MockObject
294282
*/
295283
protected function createContextMock(): Context
296284
{

pkg/enqueue/Tests/Client/Driver/FsDriverTest.php

+10-16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Interop\Queue\Queue as InteropQueue;
1919
use Interop\Queue\Topic as InteropTopic;
2020
use Makasim\File\TempFile;
21+
use PHPUnit\Framework\MockObject\MockObject;
2122
use PHPUnit\Framework\TestCase;
2223

2324
class FsDriverTest extends TestCase
@@ -44,25 +45,18 @@ public function testShouldSetupBroker()
4445
$context = $this->createContextMock();
4546
// setup router
4647
$context
47-
->expects($this->at(0))
48+
->expects($this->exactly(2))
4849
->method('createQueue')
49-
->willReturn($routerQueue)
50+
->with($this->getDefaultQueueTransportName())
51+
->willReturnOnConsecutiveCalls($routerQueue, $processorQueue)
5052
;
5153
$context
52-
->expects($this->at(1))
54+
->expects($this->exactly(2))
5355
->method('declareDestination')
54-
->with($this->identicalTo($routerQueue))
55-
;
56-
// setup processor queue
57-
$context
58-
->expects($this->at(2))
59-
->method('createQueue')
60-
->willReturn($processorQueue)
61-
;
62-
$context
63-
->expects($this->at(3))
64-
->method('declareDestination')
65-
->with($this->identicalTo($processorQueue))
56+
->with($this->logicalOr(
57+
$this->identicalTo($routerQueue),
58+
$this->identicalTo($processorQueue)
59+
))
6660
;
6761

6862
$routeCollection = new RouteCollection([
@@ -84,7 +78,7 @@ protected function createDriver(...$args): DriverInterface
8478
}
8579

8680
/**
87-
* @return FsContext
81+
* @return FsContext&MockObject
8882
*/
8983
protected function createContextMock(): Context
9084
{

pkg/enqueue/Tests/Client/Driver/GpsDriverTest.php

+19-25
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Interop\Queue\Producer as InteropProducer;
1919
use Interop\Queue\Queue as InteropQueue;
2020
use Interop\Queue\Topic as InteropTopic;
21+
use PHPUnit\Framework\MockObject\MockObject;
2122
use PHPUnit\Framework\TestCase;
2223

2324
class GpsDriverTest extends TestCase
@@ -46,38 +47,31 @@ public function testShouldSetupBroker()
4647
$context = $this->createContextMock();
4748
// setup router
4849
$context
49-
->expects($this->at(0))
50+
->expects($this->exactly(2))
5051
->method('createTopic')
51-
->willReturn($routerTopic)
52+
->with($this->logicalOr(
53+
'aprefix.router',
54+
$this->getDefaultQueueTransportName(),
55+
))
56+
->willReturnOnConsecutiveCalls($routerTopic, $processorTopic)
5257
;
5358
$context
54-
->expects($this->at(1))
55-
->method('createQueue')
56-
->willReturn($routerQueue)
57-
;
58-
$context
59-
->expects($this->at(2))
60-
->method('subscribe')
61-
->with($this->identicalTo($routerTopic), $this->identicalTo($routerQueue))
62-
;
63-
$context
64-
->expects($this->at(3))
59+
->expects($this->exactly(2))
6560
->method('createQueue')
6661
->with($this->getDefaultQueueTransportName())
67-
->willReturn($processorQueue)
68-
;
69-
// setup processor queue
70-
$context
71-
->expects($this->at(4))
72-
->method('createTopic')
73-
->with($this->getDefaultQueueTransportName())
74-
->willReturn($processorTopic)
62+
->willReturnOnConsecutiveCalls($routerQueue, $processorQueue)
7563
;
64+
65+
$invoked = $this->exactly(2);
7666
$context
77-
->expects($this->at(5))
67+
->expects($invoked)
7868
->method('subscribe')
79-
->with($this->identicalTo($processorTopic), $this->identicalTo($processorQueue))
80-
;
69+
->willReturnCallback(function ($topic, $queue) use ($invoked, $routerTopic, $processorTopic, $routerQueue, $processorQueue) {
70+
match ($invoked->getInvocationCount()) {
71+
1 => $this->assertSame([$routerTopic, $routerQueue], [$topic, $queue]),
72+
2 => $this->assertSame([$processorTopic, $processorQueue] , [$topic, $queue]),
73+
};
74+
});
8175

8276
$driver = new GpsDriver(
8377
$context,
@@ -96,7 +90,7 @@ protected function createDriver(...$args): DriverInterface
9690
}
9791

9892
/**
99-
* @return GpsContext
93+
* @return GpsContext&MockObject
10094
*/
10195
protected function createContextMock(): Context
10296
{

pkg/enqueue/Tests/Client/Driver/RabbitMqStompDriverTest.php

+34-33
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,9 @@ public function shouldSendMessageToDelayExchangeIfDelaySet()
196196

197197
$producer = $this->createProducerMock();
198198
$producer
199-
->expects($this->at(0))
199+
->expects($this->exactly(2))
200200
->method('setDeliveryDelay')
201-
->with(10000)
202-
;
203-
$producer
204-
->expects($this->at(1))
205-
->method('setDeliveryDelay')
206-
->with(null)
201+
->with($this->logicalOr(10000, null))
207202
;
208203
$producer
209204
->expects($this->once())
@@ -300,7 +295,7 @@ public function testShouldSetupBroker()
300295

301296
$managementClient = $this->createManagementClientMock();
302297
$managementClient
303-
->expects($this->at(0))
298+
->expects($this->once())
304299
->method('declareExchange')
305300
->with('aprefix.router', [
306301
'type' => 'fanout',
@@ -309,7 +304,7 @@ public function testShouldSetupBroker()
309304
])
310305
;
311306
$managementClient
312-
->expects($this->at(1))
307+
->expects($this->exactly(2))
313308
->method('declareQueue')
314309
->with('aprefix.default', [
315310
'durable' => true,
@@ -320,21 +315,10 @@ public function testShouldSetupBroker()
320315
])
321316
;
322317
$managementClient
323-
->expects($this->at(2))
318+
->expects($this->once())
324319
->method('bind')
325320
->with('aprefix.router', 'aprefix.default', 'aprefix.default')
326321
;
327-
$managementClient
328-
->expects($this->at(3))
329-
->method('declareQueue')
330-
->with('aprefix.default', [
331-
'durable' => true,
332-
'auto_delete' => false,
333-
'arguments' => [
334-
'x-max-priority' => 4,
335-
],
336-
])
337-
;
338322

339323
$contextMock = $this->createContextMock();
340324
$contextMock
@@ -400,22 +384,39 @@ public function testSetupBrokerShouldCreateDelayExchangeIfEnabled()
400384
]);
401385

402386
$managementClient = $this->createManagementClientMock();
387+
$invoked = $this->exactly(2);
403388
$managementClient
404-
->expects($this->at(4))
389+
->expects($invoked)
405390
->method('declareExchange')
406-
->with('aprefix.default.delayed', [
407-
'type' => 'x-delayed-message',
408-
'durable' => true,
409-
'auto_delete' => false,
410-
'arguments' => [
411-
'x-delayed-type' => 'direct',
412-
],
413-
])
414-
;
391+
->willReturnCallback(function (string $name, array $options) use ($invoked) {
392+
match($invoked->getInvocationCount()) {
393+
1 => $this->assertSame([
394+
'aprefix.router',
395+
['type' => 'fanout', 'durable' => true, 'auto_delete' => false],
396+
], [$name, $options]),
397+
2 => $this->assertSame([
398+
'aprefix.default.delayed',
399+
['type' => 'x-delayed-message', 'durable' => true, 'auto_delete' => false, 'arguments' => ['x-delayed-type' => 'direct']],
400+
], [$name, $options]),
401+
};
402+
});
403+
404+
$bindInvoked = $this->exactly(2);
415405
$managementClient
416-
->expects($this->at(5))
406+
->expects($bindInvoked)
417407
->method('bind')
418-
->with('aprefix.default.delayed', 'aprefix.default', 'aprefix.default')
408+
->willReturnCallback(function (string $exchange, string $queue, ?string $routingKey = null, $arguments = null) use ($bindInvoked) {
409+
match($bindInvoked->getInvocationCount()) {
410+
1 =>$this->assertSame(
411+
['aprefix.router', 'aprefix.default', 'aprefix.default', null],
412+
[$exchange, $queue, $routingKey, $arguments],
413+
),
414+
2 => $this->assertSame(
415+
['aprefix.default.delayed', 'aprefix.default', 'aprefix.default', null],
416+
[$exchange, $queue, $routingKey, $arguments],
417+
),
418+
};
419+
})
419420
;
420421

421422
$config = Config::create(

0 commit comments

Comments
 (0)