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: Adapt to php8.1 and Optimize unit test case #30

Open
wants to merge 2 commits into
base: 2.x
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
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/tests export-ignore
/example export-ignore
/docker-compose.yml export-ignore
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
],
"require": {
"php": ">=7.1.0",
"ext-swoole": "^4.4.5",
"ext-swoole": "^4.4.5|^5.0",
"easyswoole/component": "^2.0",
"easyswoole/spl": "^1.1"
"easyswoole/spl": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
13 changes: 13 additions & 0 deletions test/Protocol/CommitOffsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace EasySwoole\test\Protocol;

use EasySwoole\Kafka\Exception\Protocol as ProtocolException;
use EasySwoole\Kafka\Protocol\CommitOffset;
use PHPUnit\Framework\TestCase;
use function bin2hex;
Expand Down Expand Up @@ -87,6 +88,8 @@ public function testEncodeNoData(): void
{
$data = ['group_id' => 'test'];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given commit data invalid. `data` is undefined.');
$this->commit->encode($data);
}

Expand All @@ -100,6 +103,8 @@ public function testEncodeNoGroupId(): void
'data' => [],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given commit offset data invalid. `group_id` is undefined.');
$this->commit->encode($data);
}

Expand All @@ -116,6 +121,8 @@ public function testEncodeNoTopicName(): void
],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given commit offset data invalid. `topic_name` is undefined.');
$this->commit->encode($data);
}

Expand All @@ -132,6 +139,8 @@ public function testEncodeNoPartitions(): void
],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given commit offset data invalid. `partitions` is undefined.');
$this->commit->encode($data);
}

Expand All @@ -153,6 +162,8 @@ public function testEncodeNoPartition(): void
],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given commit offset data invalid. `partition` is undefined.');
$this->commit->encode($data);
}

Expand All @@ -174,6 +185,8 @@ public function testEncodeNoOffset(): void
],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given commit offset data invalid. `offset` is undefined.');
$this->commit->encode($data);
}

Expand Down
9 changes: 9 additions & 0 deletions test/Protocol/FetchOffsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace EasySwoole\test\Protocol;

use EasySwoole\Kafka\Exception\Protocol as ProtocolException;
use EasySwoole\Kafka\Protocol\FetchOffset;
use PHPUnit\Framework\TestCase;
use function bin2hex;
Expand Down Expand Up @@ -49,6 +50,8 @@ public function testEncode(): void
*/
public function testEncodeNoData(): void
{
$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given fetch offset data invalid. `data` is undefined.');
$this->offset->encode();
}

Expand All @@ -62,6 +65,8 @@ public function testEncodeNoGroupId(): void
'data' => [],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given fetch offset data invalid. `group_id` is undefined.');
$this->offset->encode($data);
}

Expand All @@ -78,6 +83,8 @@ public function testEncodeNoTopicName(): void
],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given fetch offset data invalid. `topic_name` is undefined.');
$this->offset->encode($data);
}

Expand All @@ -94,6 +101,8 @@ public function testEncodeNoPartitions(): void
],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given fetch offset data invalid. `partitions` is undefined.');
$this->offset->encode($data);
}

Expand Down
9 changes: 9 additions & 0 deletions test/Protocol/FetchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace EasySwoole\test\Protocol;

use EasySwoole\Kafka\Exception\Protocol as ProtocolException;
use EasySwoole\Kafka\Protocol\Fetch;
use PHPUnit\Framework\TestCase;
use function bin2hex;
Expand Down Expand Up @@ -57,6 +58,8 @@ public function testEncode(): void
*/
public function testEncodeNoData(): void
{
$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given fetch kafka data invalid. `data` is undefined.');
$this->fetch->encode();
}

Expand Down Expand Up @@ -98,6 +101,8 @@ public function testEncodeNoTopicName(): void
],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given fetch data invalid. `topic_name` is undefined.');
$this->fetch->encode($data);
}

Expand All @@ -113,6 +118,8 @@ public function testEncodeNoPartitions(): void
],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given fetch data invalid. `partitions` is undefined.');
$this->fetch->encode($data);
}

Expand All @@ -133,6 +140,8 @@ public function testEncodeNoPartitionId(): void
],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given fetch data invalid. `partition_id` is undefined.');
$this->fetch->encode($data);
}

Expand Down
3 changes: 3 additions & 0 deletions test/Protocol/GroupCoordinatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace EasySwoole\test\Protocol;

use EasySwoole\Kafka\Exception\Protocol as ProtocolException;
use EasySwoole\Kafka\Protocol\GroupCoordinator;
use PHPUnit\Framework\TestCase;
use function bin2hex;
Expand Down Expand Up @@ -39,6 +40,8 @@ public function testEncode(): void
*/
public function testEncodeNoGroupId(): void
{
$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given group coordinator invalid. `group_id` is undefined.');
$this->group->encode();
}

Expand Down
7 changes: 7 additions & 0 deletions test/Protocol/HeartbeatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace EasySwoole\test\Protocol;

use EasySwoole\Kafka\Exception\Protocol as ProtocolException;
use EasySwoole\Kafka\Protocol\Heartbeat;
use PHPUnit\Framework\TestCase;
use function bin2hex;
Expand Down Expand Up @@ -45,6 +46,8 @@ public function testEncode(): void
*/
public function testEncodeNoGroupId(): void
{
$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given heartbeat data invalid. `group_id` is undefined.');
$this->heart->encode();
}

Expand All @@ -56,6 +59,8 @@ public function testEncodeNoGenerationId(): void
{
$data = ['group_id' => 'test'];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given heartbeat data invalid. `generation_id` is undefined.');
$this->heart->encode($data);
}

Expand All @@ -70,6 +75,8 @@ public function testEncodeNoMemberId(): void
'generation_id' => '1',
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given heartbeat data invalid. `member_id` is undefined.');
$this->heart->encode($data);
}

Expand Down
15 changes: 15 additions & 0 deletions test/Protocol/JoinGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace EasySwoole\test\Protocol;

use EasySwoole\Kafka\Exception\Protocol as ProtocolException;
use EasySwoole\Kafka\Protocol\JoinGroup;
use PHPUnit\Framework\TestCase;
use function bin2hex;
Expand Down Expand Up @@ -52,6 +53,8 @@ public function testEncode(): void
*/
public function testEncodeNoGroupId(): void
{
$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given join group data invalid. `group_id` is undefined.');
$this->group->encode();
}

Expand All @@ -63,6 +66,8 @@ public function testEncodeNoSessionTimeout(): void
{
$data = ['group_id' => 'test'];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given join group data invalid. `session_timeout` is undefined.');
$this->group->encode($data);
}

Expand All @@ -77,6 +82,8 @@ public function testEncodeNoMemberId(): void
'session_timeout' => 6000,
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given join group data invalid. `member_id` is undefined.');
$test = $this->group->encode($data);
}

Expand All @@ -92,6 +99,8 @@ public function testEncodeNoData(): void
'member_id' => '',
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given join group data invalid. `data` is undefined.');
$this->group->encode($data);
}

Expand Down Expand Up @@ -139,6 +148,8 @@ public function testEncodeNoProtocolName(): void
],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given join group data invalid. `protocol_name` is undefined.');
$this->group->encode($data);
}

Expand All @@ -158,6 +169,8 @@ public function testEncodeNoVersion(): void
],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given data invalid. `version` is undefined.');
$test = $this->group->encode($data);
}

Expand All @@ -180,6 +193,8 @@ public function testEncodeNoSubscription(): void
],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given data invalid. `subscription` is undefined.');
$this->group->encode($data);
}

Expand Down
5 changes: 5 additions & 0 deletions test/Protocol/LeaveGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace EasySwoole\test\Protocol;

use EasySwoole\Kafka\Exception\Protocol as ProtocolException;
use EasySwoole\Kafka\Protocol\LeaveGroup;
use PHPUnit\Framework\TestCase;
use function bin2hex;
Expand Down Expand Up @@ -44,6 +45,8 @@ public function testEncode(): void
*/
public function testEncodeNoGroupId(): void
{
$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given leave group data invalid. `group_id` is undefined.');
$this->leave->encode();
}

Expand All @@ -55,6 +58,8 @@ public function testEncodeNoMemberId(): void
{
$data = ['group_id' => 'test'];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given leave group data invalid. `member_id` is undefined.');
$this->leave->encode($data);
}

Expand Down
9 changes: 9 additions & 0 deletions test/Protocol/OffsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace EasySwoole\test\Protocol;

use EasySwoole\Kafka\Exception\Protocol as ProtocolException;
use EasySwoole\Kafka\Protocol\Offset;
use PHPUnit\Framework\TestCase;
use function bin2hex;
Expand Down Expand Up @@ -52,6 +53,8 @@ public function testEncode(): void
*/
public function testEncodeNoData(): void
{
$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given offset data invalid. `data` is undefined.');
$this->offset->encode();
}

Expand All @@ -67,6 +70,8 @@ public function testEncodeNoTopicName(): void
],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given offset data invalid. `topic_name` is undefined.');
$this->offset->encode($data);
}

Expand All @@ -82,6 +87,8 @@ public function testEncodeNoPartitions(): void
],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given offset data invalid. `partitions` is undefined.');
$this->offset->encode($data);
}

Expand All @@ -102,6 +109,8 @@ public function testEncodeNoPartitionId(): void
],
];

$this->expectException(ProtocolException::class);
$this->expectExceptionMessage('given offset data invalid. `partition_id` is undefined.');
$this->offset->encode($data);
}

Expand Down
Loading