Skip to content
Merged
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: 0 additions & 10 deletions .github/.kodiak.toml

This file was deleted.

20 changes: 13 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,33 @@ on:
- cron: "0 8 * * 1"

jobs:
test83:
test85:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
with:
php: "8.3"
php: "8.5"

test82:
test84:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
with:
php: "8.2"
php: "8.4"

test81:
test83:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
with:
php: "8.1"
php: "8.3"

test82:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
with:
php: "8.2"

testlower:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
with:
php: "8.1"
php: "8.2"
composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest"
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
}
],
"require": {
"php": ">=8.1",
"bunny/bunny": "^0.5",
"php": ">=8.2",
"bunny/bunny": "~0.5.0",
"symfony/console": "^6.4.2 || ^7.0.2",
"nette/di": "^3.0.7",
"nette/utils": "^4.0.0"
},
"require-dev": {
"contributte/phpstan": "~0.1.0",
"contributte/qa": "~0.4.0",
"contributte/tester": "~0.4.0",
"mockery/mockery": "^1.6.6",
"contributte/qa": "^0.4",
"contributte/tester": "^0.4",
"contributte/phpstan": "^0.1",
"nette/neon": "^3.2.1",
"tracy/tracy": "^2.10.5"
},
Expand All @@ -57,6 +57,7 @@
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
Expand Down
4 changes: 1 addition & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ includes:

parameters:
level: 8
phpVersion: 80100
phpVersion: 80200

scanDirectories:
- src
Expand All @@ -14,5 +14,3 @@ parameters:
paths:
- src
- .docs

ignoreErrors:
9 changes: 7 additions & 2 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Contributte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<!-- Rulesets -->
<rule ref="./vendor/contributte/qa/ruleset-8.0.xml"/>
<rule ref="./vendor/contributte/qa/ruleset-8.2.xml"/>

<!-- Rules -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
Expand All @@ -17,6 +17,11 @@
</properties>
</rule>

<!-- Bunny library does not have native type hints, suppress for test mocks -->
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint">
<exclude-pattern>/tests</exclude-pattern>
</rule>

<!-- Excludes -->
<exclude-pattern>/tests</exclude-pattern>
<exclude-pattern>/tests/tmp</exclude-pattern>
</ruleset>
51 changes: 33 additions & 18 deletions tests/Cases/BulkConsumerTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ final class BulkConsumerTest extends TestCase
->shouldReceive('getConnection')->andReturn($connectionMock)->getMock()
->shouldReceive('getName')->andReturn('testQueue')->getMock();

$countOfConsumerCallbackCalls = 0;
$callback = function ($messages) use (&$countOfConsumerCallbackCalls) {
$countOfConsumerCallbackCalls++;
$counter = (object) ['value' => 0];
$callback = function (array $messages) use ($counter): array {
$counter->value++;

return array_map(fn ($message) => IConsumer::MESSAGE_ACK, $messages);
return array_map(fn (Message $message): int => IConsumer::MESSAGE_ACK, $messages);
};

$instance = new BulkConsumer('bulkTest', $queueMock, $callback, null, null, 3, 2);

$instance->consume(2);

Assert::same(2, $countOfConsumerCallbackCalls, 'Number of consumer callback calls');
Assert::same(2, $counter->value, 'Number of consumer callback calls');
Assert::count(2, $channelMock->acks, 'Number of ACKs');
Assert::same([
1 => [
Expand Down Expand Up @@ -72,9 +72,9 @@ final class BulkConsumerTest extends TestCase
->shouldReceive('getConnection')->andReturn($connectionMock)->getMock()
->shouldReceive('getName')->andReturn('testQueue')->getMock();

$countOfConsumerCallbackCalls = 0;
$callback = function ($messages) use (&$countOfConsumerCallbackCalls): void {
$countOfConsumerCallbackCalls++;
$counter = (object) ['value' => 0];
$callback = function (array $messages) use ($counter): void {
$counter->value++;

throw new \Exception('test');
};
Expand All @@ -83,7 +83,7 @@ final class BulkConsumerTest extends TestCase

$instance->consume(2);

Assert::same(2, $countOfConsumerCallbackCalls, 'Number of consumer callback calls');
Assert::same(2, $counter->value, 'Number of consumer callback calls');
Assert::count(2, $channelMock->nacks, 'Number of NACKs');
Assert::same([
1 => [
Expand Down Expand Up @@ -112,9 +112,9 @@ final class BulkConsumerTest extends TestCase
->shouldReceive('getConnection')->andReturn($connectionMock)->getMock()
->shouldReceive('getName')->andReturn('testQueue')->getMock();

$countOfConsumerCallbackCalls = 0;
$callback = function ($messages) use (&$countOfConsumerCallbackCalls) {
$countOfConsumerCallbackCalls++;
$counter = (object) ['value' => 0];
$callback = function (array $messages) use ($counter): bool {
$counter->value++;

return true;
};
Expand All @@ -123,7 +123,7 @@ final class BulkConsumerTest extends TestCase

Assert::exception(fn () => $instance->consume(2), UnexpectedConsumerResultTypeException::class);

Assert::same(1, $countOfConsumerCallbackCalls, 'Number of consumer callback calls');
Assert::same(1, $counter->value, 'Number of consumer callback calls');
Assert::count(1, $channelMock->nacks, 'Number of NACKs');
Assert::same([
1 => [
Expand All @@ -144,31 +144,44 @@ final class BulkConsumerTest extends TestCase
['key' => '5', 'content' => '{"test":"5"}'],
]) extends Client {

/** @var array<array{key: string, content: string}> */
private array $dataToConsume;

private $callback;
/** @var callable|null */
private mixed $callback = null;

private $channel;
private ?ChannelMock $channel = null;

public function __construct($dataToConsume)
/**
* @param array<array{key: string, content: string}> $dataToConsume
*/
public function __construct(array $dataToConsume)
{
$this->dataToConsume = $dataToConsume;
}

public function setCallback($callback): void
public function setCallback(callable $callback): void
{
$this->callback = $callback;
}

public function setChannel($channel): void
public function setChannel(ChannelMock $channel): void
{
$this->channel = $channel;
}

/**
* @param int $replyCode
* @param string $replyText
*/
public function disconnect($replyCode = 0, $replyText = ''): void
{
// intentionally empty - mock
}

/**
* @param float|null $maxSeconds
*/
public function run($maxSeconds = null): void
{
$this->channel->ackPos++;
Expand All @@ -186,10 +199,12 @@ final class BulkConsumerTest extends TestCase

protected function feedReadBuffer(): void
{
// intentionally empty - mock
}

protected function flushWriteBuffer(): void
{
// intentionally empty - mock
}

};
Expand Down
Loading