Skip to content

Fix: Tests throwing warnings #1374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ jobs:
fail-fast: false
matrix:
php: ['8.1', '8.2']
symfony_version: ['6.2.*', '6.3.*', '6.4.*', '7.0.*']
symfony_version: ['6.4.*', '7.0.*', '7.1.*', '7.2.*']
dependencies: ['--prefer-lowest', '--prefer-dist']
exclude:
- php: '8.1'
symfony_version: '7.0.*'
- php: '8.1'
symfony_version: '7.1.*'
- php: '8.1'
symfony_version: '7.2.*'

name: PHP ${{ matrix.php }} unit tests on Sf ${{ matrix.symfony_version }}, deps=${{ matrix.dependencies }}

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
},
"require-dev": {
"ext-pcntl": "*",
"phpunit/phpunit": "^9.5.28",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^9.6.23",
"phpstan/phpstan": "^2.1",
"queue-interop/queue-spec": "^0.6.2",
"symfony/browser-kit": "^6.2|^7.0",
"symfony/config": "^6.2|^7.0",
Expand All @@ -70,7 +70,7 @@
"doctrine/mongodb-odm-bundle": "^4.7|^5.0",
"alcaeus/mongo-php-adapter": "^1.0",
"kwn/php-rdkafka-stubs": "^2.0.3",
"friendsofphp/php-cs-fixer": "^3.4",
"friendsofphp/php-cs-fixer": "^3.64",
"dms/phpunit-arraysubset-asserts": "^0.2.1",
"phpspec/prophecy-phpunit": "^2.0"
},
Expand Down
18 changes: 9 additions & 9 deletions pkg/amqp-lib/Tests/AmqpContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,19 @@ public function testShouldPurgeQueue()
$context->purgeQueue($queue);
}

public function testShouldSetQos()
public function testShouldSetQos(): void
{
$invoked = $this->exactly(2);
$channel = $this->createChannelMock();
$channel
->expects($this->at(0))
->expects($invoked)
->method('basic_qos')
->with($this->identicalTo(0), $this->identicalTo(1), $this->isFalse())
;
$channel
->expects($this->at(1))
->method('basic_qos')
->with($this->identicalTo(123), $this->identicalTo(456), $this->isTrue())
;
->willReturnCallback(function ($prefetch_size, $prefetch_count, $a_global) use ($invoked) {
match ($invoked->getInvocationCount()) {
1 => $this->assertSame([0, 1, false], [$prefetch_size, $prefetch_count, $a_global]),
2 => $this->assertSame([123, 456, true], [$prefetch_size, $prefetch_count, $a_global]),
};
});

$connection = $this->createConnectionMock();
$connection
Expand Down
56 changes: 22 additions & 34 deletions pkg/enqueue/Tests/Client/Driver/AmqpDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Interop\Queue\Message as InteropMessage;
use Interop\Queue\Producer as InteropProducer;
use Interop\Queue\Queue as InteropQueue;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class AmqpDriverTest extends TestCase
Expand Down Expand Up @@ -190,56 +191,43 @@ public function testShouldSetupBroker()
$context = $this->createContextMock();
// setup router
$context
->expects($this->at(0))
->expects($this->once())
->method('createTopic')
->with($this->identicalTo($this->getRouterTransportName()))
->willReturn($routerTopic)
;
$context
->expects($this->at(1))
->expects($this->once())
->method('declareTopic')
->with($this->identicalTo($routerTopic))
;

$context
->expects($this->at(2))
->method('createQueue')
->willReturn($routerQueue)
;
$context
->expects($this->at(3))
->method('declareQueue')
->with($this->identicalTo($routerQueue))
;

$context
->expects($this->at(4))
->expects($this->once())
->method('bind')
->with($this->isInstanceOf(AmqpBind::class))
;

// setup processor with default queue
$context
->expects($this->at(5))
->method('createQueue')
->with($this->getDefaultQueueTransportName())
->willReturn($processorWithDefaultQueue)
;
$context
->expects($this->at(6))
->method('declareQueue')
->with($this->identicalTo($processorWithDefaultQueue))
;

$context
->expects($this->at(7))
->expects($this->exactly(3))
->method('createQueue')
->with($this->getCustomQueueTransportName())
->willReturn($processorWithCustomQueue)
->with($this->logicalOr(
$this->getDefaultQueueTransportName(),
$this->getCustomQueueTransportName(),
))
->willReturnOnConsecutiveCalls(
$routerQueue,
$processorWithDefaultQueue,
$processorWithCustomQueue
)
;
$context
->expects($this->at(8))
->expects($this->exactly(3))
->method('declareQueue')
->with($this->identicalTo($processorWithCustomQueue))
->with($this->logicalOr(
$this->identicalTo($routerQueue),
$this->identicalTo($processorWithDefaultQueue),
$this->identicalTo($processorWithCustomQueue)
))
;

$driver = new AmqpDriver(
Expand Down Expand Up @@ -290,7 +278,7 @@ protected function createDriver(...$args): DriverInterface
}

/**
* @return AmqpContext
* @return AmqpContext&MockObject
*/
protected function createContextMock(): Context
{
Expand Down
26 changes: 10 additions & 16 deletions pkg/enqueue/Tests/Client/Driver/FsDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Interop\Queue\Queue as InteropQueue;
use Interop\Queue\Topic as InteropTopic;
use Makasim\File\TempFile;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class FsDriverTest extends TestCase
Expand All @@ -44,25 +45,18 @@ public function testShouldSetupBroker()
$context = $this->createContextMock();
// setup router
$context
->expects($this->at(0))
->expects($this->exactly(2))
->method('createQueue')
->willReturn($routerQueue)
->with($this->getDefaultQueueTransportName())
->willReturnOnConsecutiveCalls($routerQueue, $processorQueue)
;
$context
->expects($this->at(1))
->expects($this->exactly(2))
->method('declareDestination')
->with($this->identicalTo($routerQueue))
;
// setup processor queue
$context
->expects($this->at(2))
->method('createQueue')
->willReturn($processorQueue)
;
$context
->expects($this->at(3))
->method('declareDestination')
->with($this->identicalTo($processorQueue))
->with($this->logicalOr(
$this->identicalTo($routerQueue),
$this->identicalTo($processorQueue)
))
;

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

/**
* @return FsContext
* @return FsContext&MockObject
*/
protected function createContextMock(): Context
{
Expand Down
44 changes: 19 additions & 25 deletions pkg/enqueue/Tests/Client/Driver/GpsDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Interop\Queue\Producer as InteropProducer;
use Interop\Queue\Queue as InteropQueue;
use Interop\Queue\Topic as InteropTopic;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class GpsDriverTest extends TestCase
Expand Down Expand Up @@ -46,38 +47,31 @@ public function testShouldSetupBroker()
$context = $this->createContextMock();
// setup router
$context
->expects($this->at(0))
->expects($this->exactly(2))
->method('createTopic')
->willReturn($routerTopic)
->with($this->logicalOr(
'aprefix.router',
$this->getDefaultQueueTransportName(),
))
->willReturnOnConsecutiveCalls($routerTopic, $processorTopic)
;
$context
->expects($this->at(1))
->method('createQueue')
->willReturn($routerQueue)
;
$context
->expects($this->at(2))
->method('subscribe')
->with($this->identicalTo($routerTopic), $this->identicalTo($routerQueue))
;
$context
->expects($this->at(3))
->expects($this->exactly(2))
->method('createQueue')
->with($this->getDefaultQueueTransportName())
->willReturn($processorQueue)
;
// setup processor queue
$context
->expects($this->at(4))
->method('createTopic')
->with($this->getDefaultQueueTransportName())
->willReturn($processorTopic)
->willReturnOnConsecutiveCalls($routerQueue, $processorQueue)
;

$invoked = $this->exactly(2);
$context
->expects($this->at(5))
->expects($invoked)
->method('subscribe')
->with($this->identicalTo($processorTopic), $this->identicalTo($processorQueue))
;
->willReturnCallback(function ($topic, $queue) use ($invoked, $routerTopic, $processorTopic, $routerQueue, $processorQueue) {
match ($invoked->getInvocationCount()) {
1 => $this->assertSame([$routerTopic, $routerQueue], [$topic, $queue]),
2 => $this->assertSame([$processorTopic, $processorQueue], [$topic, $queue]),
};
});

$driver = new GpsDriver(
$context,
Expand All @@ -96,7 +90,7 @@ protected function createDriver(...$args): DriverInterface
}

/**
* @return GpsContext
* @return GpsContext&MockObject
*/
protected function createContextMock(): Context
{
Expand Down
67 changes: 34 additions & 33 deletions pkg/enqueue/Tests/Client/Driver/RabbitMqStompDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,9 @@ public function shouldSendMessageToDelayExchangeIfDelaySet()

$producer = $this->createProducerMock();
$producer
->expects($this->at(0))
->expects($this->exactly(2))
->method('setDeliveryDelay')
->with(10000)
;
$producer
->expects($this->at(1))
->method('setDeliveryDelay')
->with(null)
->with($this->logicalOr(10000, null))
;
$producer
->expects($this->once())
Expand Down Expand Up @@ -300,7 +295,7 @@ public function testShouldSetupBroker()

$managementClient = $this->createManagementClientMock();
$managementClient
->expects($this->at(0))
->expects($this->once())
->method('declareExchange')
->with('aprefix.router', [
'type' => 'fanout',
Expand All @@ -309,7 +304,7 @@ public function testShouldSetupBroker()
])
;
$managementClient
->expects($this->at(1))
->expects($this->exactly(2))
->method('declareQueue')
->with('aprefix.default', [
'durable' => true,
Expand All @@ -320,21 +315,10 @@ public function testShouldSetupBroker()
])
;
$managementClient
->expects($this->at(2))
->expects($this->once())
->method('bind')
->with('aprefix.router', 'aprefix.default', 'aprefix.default')
;
$managementClient
->expects($this->at(3))
->method('declareQueue')
->with('aprefix.default', [
'durable' => true,
'auto_delete' => false,
'arguments' => [
'x-max-priority' => 4,
],
])
;

$contextMock = $this->createContextMock();
$contextMock
Expand Down Expand Up @@ -400,22 +384,39 @@ public function testSetupBrokerShouldCreateDelayExchangeIfEnabled()
]);

$managementClient = $this->createManagementClientMock();
$invoked = $this->exactly(2);
$managementClient
->expects($this->at(4))
->expects($invoked)
->method('declareExchange')
->with('aprefix.default.delayed', [
'type' => 'x-delayed-message',
'durable' => true,
'auto_delete' => false,
'arguments' => [
'x-delayed-type' => 'direct',
],
])
;
->willReturnCallback(function (string $name, array $options) use ($invoked) {
match ($invoked->getInvocationCount()) {
1 => $this->assertSame([
'aprefix.router',
['type' => 'fanout', 'durable' => true, 'auto_delete' => false],
], [$name, $options]),
2 => $this->assertSame([
'aprefix.default.delayed',
['type' => 'x-delayed-message', 'durable' => true, 'auto_delete' => false, 'arguments' => ['x-delayed-type' => 'direct']],
], [$name, $options]),
};
});

$bindInvoked = $this->exactly(2);
$managementClient
->expects($this->at(5))
->expects($bindInvoked)
->method('bind')
->with('aprefix.default.delayed', 'aprefix.default', 'aprefix.default')
->willReturnCallback(function (string $exchange, string $queue, ?string $routingKey = null, $arguments = null) use ($bindInvoked) {
match ($bindInvoked->getInvocationCount()) {
1 => $this->assertSame(
['aprefix.router', 'aprefix.default', 'aprefix.default', null],
[$exchange, $queue, $routingKey, $arguments],
),
2 => $this->assertSame(
['aprefix.default.delayed', 'aprefix.default', 'aprefix.default', null],
[$exchange, $queue, $routingKey, $arguments],
),
};
})
;

$config = Config::create(
Expand Down
Loading
Loading