diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..bd2d610 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +/.gitattributes export-ignore +/.gitignore export-ignore +/tests export-ignore +/example export-ignore +/docker-compose.yml export-ignore diff --git a/composer.json b/composer.json index d39aaa4..a1a79ce 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/test/Protocol/CommitOffsetTest.php b/test/Protocol/CommitOffsetTest.php index 4c776ba..fb9cff5 100644 --- a/test/Protocol/CommitOffsetTest.php +++ b/test/Protocol/CommitOffsetTest.php @@ -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; @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } diff --git a/test/Protocol/FetchOffsetTest.php b/test/Protocol/FetchOffsetTest.php index 2954085..cb6e3d5 100644 --- a/test/Protocol/FetchOffsetTest.php +++ b/test/Protocol/FetchOffsetTest.php @@ -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; @@ -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(); } @@ -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); } @@ -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); } @@ -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); } diff --git a/test/Protocol/FetchTest.php b/test/Protocol/FetchTest.php index 03185d9..457c567 100644 --- a/test/Protocol/FetchTest.php +++ b/test/Protocol/FetchTest.php @@ -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; @@ -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(); } @@ -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); } @@ -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); } @@ -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); } diff --git a/test/Protocol/GroupCoordinatorTest.php b/test/Protocol/GroupCoordinatorTest.php index ffe4be3..e27d5f4 100644 --- a/test/Protocol/GroupCoordinatorTest.php +++ b/test/Protocol/GroupCoordinatorTest.php @@ -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; @@ -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(); } diff --git a/test/Protocol/HeartbeatTest.php b/test/Protocol/HeartbeatTest.php index 20209f5..30d7a5e 100644 --- a/test/Protocol/HeartbeatTest.php +++ b/test/Protocol/HeartbeatTest.php @@ -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; @@ -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(); } @@ -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); } @@ -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); } diff --git a/test/Protocol/JoinGroupTest.php b/test/Protocol/JoinGroupTest.php index 620efb2..3d6d57c 100644 --- a/test/Protocol/JoinGroupTest.php +++ b/test/Protocol/JoinGroupTest.php @@ -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; @@ -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(); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -180,6 +193,8 @@ public function testEncodeNoSubscription(): void ], ]; + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('given data invalid. `subscription` is undefined.'); $this->group->encode($data); } diff --git a/test/Protocol/LeaveGroupTest.php b/test/Protocol/LeaveGroupTest.php index 310d9f6..97f5eb5 100644 --- a/test/Protocol/LeaveGroupTest.php +++ b/test/Protocol/LeaveGroupTest.php @@ -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; @@ -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(); } @@ -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); } diff --git a/test/Protocol/OffsetTest.php b/test/Protocol/OffsetTest.php index 8670e66..fcd818b 100644 --- a/test/Protocol/OffsetTest.php +++ b/test/Protocol/OffsetTest.php @@ -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; @@ -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(); } @@ -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); } @@ -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); } @@ -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); } diff --git a/test/Protocol/ProduceTest.php b/test/Protocol/ProduceTest.php index 33b1751..2ef6466 100644 --- a/test/Protocol/ProduceTest.php +++ b/test/Protocol/ProduceTest.php @@ -3,6 +3,7 @@ namespace EasySwoole\test\Protocol; +use EasySwoole\Kafka\Exception\Protocol as ProtocolException; use EasySwoole\Kafka\Protocol\Produce; use PHPUnit\Framework\TestCase; use function bin2hex; @@ -145,6 +146,8 @@ public function testEncodeNotTimeoutAndRequired(): void */ public function testEncodeNoData(): void { + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage("given produce data invalid, 'data' is undefined."); $this->produce->encode(); } @@ -160,6 +163,8 @@ public function testEncodeNoTopicName(): void ], ]; + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('given produce data invalid. `topic_name` is undefined.'); $this->produce->encode($data); } @@ -175,6 +180,8 @@ public function testEncodeNoPartitions(): void ], ]; + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('given produce data invalid. `partitions` is undefined.'); $this->produce->encode($data); } @@ -195,6 +202,8 @@ public function testEncodeNoPartitionId(): void ], ]; + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('given produce data invalid. `partition_id` is undefined.'); $this->produce->encode($data); } @@ -217,6 +226,8 @@ public function testEncodeNoMessage(): void ], ]; + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('given produce data invalid. `messages` is undefined.'); $this->produce->encode($data); } diff --git a/test/Protocol/SaslHandShakeTest.php b/test/Protocol/SaslHandShakeTest.php index effe20f..e500b14 100644 --- a/test/Protocol/SaslHandShakeTest.php +++ b/test/Protocol/SaslHandShakeTest.php @@ -3,6 +3,7 @@ namespace EasySwoole\test\Protocol; +use EasySwoole\Kafka\Exception\Protocol as ProtocolException; use EasySwoole\Kafka\Protocol\SaslHandShake; use PHPUnit\Framework\TestCase; use function bin2hex; @@ -38,6 +39,8 @@ public function testEncode(): void */ public function testEncodeNoMechanismGiven(): void { + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('Invalid request SASL hand shake mechanism given.'); $this->sasl->encode(); } @@ -47,6 +50,8 @@ public function testEncodeNoMechanismGiven(): void */ public function testEncodeInvalidMechanism(): void { + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('Invalid request SASL hand shake mechanism given, it must be one of: GSSAPI|PLAIN|SCRAM-SHA-256|SCRAM-SHA-512'); $this->sasl->encode(['NOTALLOW']); } diff --git a/test/Protocol/SyncGroupTest.php b/test/Protocol/SyncGroupTest.php index 18da89a..2b6f009 100644 --- a/test/Protocol/SyncGroupTest.php +++ b/test/Protocol/SyncGroupTest.php @@ -3,6 +3,7 @@ namespace EasySwoole\test\Protocol; +use EasySwoole\Kafka\Exception\Protocol as ProtocolException; use EasySwoole\Kafka\Protocol\SyncGroup; use PHPUnit\Framework\TestCase; use function bin2hex; @@ -44,6 +45,8 @@ public function testEncode(): void */ public function testEncodeNoGroupId(): void { + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('given sync group data invalid. `group_id` is undefined.'); $this->sync->encode(); } @@ -55,6 +58,8 @@ public function testEncodeNoGenerationId(): void { $data = ['group_id' => 'test']; + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('given sync group data invalid. `generation_id` is undefined.'); $this->sync->encode($data); } @@ -69,6 +74,8 @@ public function testEncodeNoMemberId(): void 'generation_id' => '1', ]; + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('given sync group data invalid. `member_id` is undefined.'); $this->sync->encode($data); } @@ -84,6 +91,8 @@ public function testEncodeNoData(): void 'member_id' => 'Easyswoole-kafka-bd5d5bb2-2a1f-43d4-b831-b1510d81ac5c', ]; + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('given sync group data invalid. `data` is undefined.'); $this->sync->encode($data); } @@ -102,6 +111,8 @@ public function testEncodeNoVersion(): void ], ]; + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('given data invalid. `version` is undefined.'); $this->sync->encode($data); } @@ -120,6 +131,8 @@ public function testEncodeNoDataMemberId(): void ], ]; + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('given data invalid. `member_id` is undefined.'); $this->sync->encode($data); } @@ -141,6 +154,8 @@ public function testEncodeNoDataAssignments(): void ], ]; + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('given data invalid. `assignments` is undefined.'); $this->sync->encode($data); } @@ -165,6 +180,8 @@ public function testEncodeNoTopicName(): void ], ]; + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('given data invalid. `topic_name` is undefined.'); $this->sync->encode($data); } @@ -189,6 +206,8 @@ public function testEncodeNoPartitions(): void ], ]; + $this->expectException(ProtocolException::class); + $this->expectExceptionMessage('given data invalid. `partitions` is undefined.'); $this->sync->encode($data); }