Skip to content
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

Fix: Tests throwing warnings #1374

Open
wants to merge 5 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
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"google/cloud-pubsub": "^1.4.3",
"doctrine/orm": "^2.12",
"doctrine/persistence": "^2.0|^3.0",
"mongodb/mongodb": "^1.2",
"mongodb/mongodb": "^1.17",
"pda/pheanstalk": "^3.1",
"aws/aws-sdk-php": "^3.290",
"stomp-php/stomp-php": "^4.5|^5",
Expand All @@ -50,8 +50,8 @@
},
"require-dev": {
"ext-pcntl": "*",
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^9.6.22",
"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": "^3.5|^4.3|^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 Expand Up @@ -127,7 +127,7 @@
"ext-rdkafka": "4.0",
"ext-bcmath": "1",
"ext-mbstring": "1",
"ext-mongo": "1.6.14",
"ext-mongodb": "1.17",
"ext-sockets": "1"
},
"prefer-stable": true,
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
2 changes: 1 addition & 1 deletion pkg/enqueue/Client/DriverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private function findDriverInfo(Dsn $dsn, array $factories): ?array
private function createRabbitMqStompDriver(ConnectionFactory $factory, Dsn $dsn, Config $config, RouteCollection $collection): RabbitMqStompDriver
{
$defaultManagementHost = $dsn->getHost() ?: $config->getTransportOption('host', 'localhost');
$managementVast = ltrim($dsn->getPath(), '/') ?: $config->getTransportOption('vhost', '/');
$managementVast = ltrim($dsn->getPath() ?? '', '/') ?: $config->getTransportOption('vhost', '/');

$managementClient = StompManagementClient::create(
urldecode($managementVast),
Expand Down
2 changes: 1 addition & 1 deletion pkg/enqueue/Symfony/Client/ConsumeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
try {
$consumer = $this->getQueueConsumer($client);
} catch (NotFoundExceptionInterface $e) {
throw new \LogicException(sprintf('Client "%s" is not supported.', $client), null, $e);
throw new \LogicException(sprintf('Client "%s" is not supported.', $client), 0, $e);
}

$driver = $this->getDriver($client);
Expand Down
2 changes: 1 addition & 1 deletion pkg/enqueue/Symfony/Client/ProduceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
try {
$producer = $this->getProducer($client);
} catch (NotFoundExceptionInterface $e) {
throw new \LogicException(sprintf('Client "%s" is not supported.', $client), null, $e);
throw new \LogicException(sprintf('Client "%s" is not supported.', $client), 0, $e);
}

if ($topic) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/enqueue/Symfony/Client/RoutesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
try {
$this->driver = $this->getDriver($input->getOption('client'));
} catch (NotFoundExceptionInterface $e) {
throw new \LogicException(sprintf('Client "%s" is not supported.', $input->getOption('client')), null, $e);
throw new \LogicException(sprintf('Client "%s" is not supported.', $input->getOption('client')), 0, $e);
}

$routes = $this->driver->getRouteCollection()->all();
Expand Down
2 changes: 1 addition & 1 deletion pkg/enqueue/Symfony/Client/SetupBrokerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
try {
$this->getDriver($client)->setupBroker(new ConsoleLogger($output));
} catch (NotFoundExceptionInterface $e) {
throw new \LogicException(sprintf('Client "%s" is not supported.', $client), null, $e);
throw new \LogicException(sprintf('Client "%s" is not supported.', $client), 0, $e);
}

$output->writeln('Broker set up');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
try {
$consumer = $this->getQueueConsumer($transport);
} catch (NotFoundExceptionInterface $e) {
throw new \LogicException(sprintf('Transport "%s" is not supported.', $transport), null, $e);
throw new \LogicException(sprintf('Transport "%s" is not supported.', $transport), 0, $e);
}

$this->setQueueConsumerOptions($consumer, $input);
Expand Down
2 changes: 1 addition & 1 deletion pkg/enqueue/Symfony/Consumption/ConsumeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
// QueueConsumer must be pre configured outside of the command!
$consumer = $this->getQueueConsumer($transport);
} catch (NotFoundExceptionInterface $e) {
throw new \LogicException(sprintf('Transport "%s" is not supported.', $transport), null, $e);
throw new \LogicException(sprintf('Transport "%s" is not supported.', $transport), 0, $e);
}

$this->setQueueConsumerOptions($consumer, $input);
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
Loading
Loading