Skip to content
This repository was archived by the owner on Oct 27, 2025. It is now read-only.

Commit 0ee9076

Browse files
committed
Add support for rd_kafka_err2name
1 parent 7626b71 commit 0ee9076

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/functions.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@
77
/**
88
* @param int $err Error code
99
*
10-
* @return string Returns the error as a string.
10+
* @return string The error name as a string.
11+
*/
12+
function rd_kafka_err2name(int $err): string
13+
{
14+
return Library::rd_kafka_err2name($err);
15+
}
16+
17+
/**
18+
* @param int $err Error code
19+
*
20+
* @return string The error description a string.
1121
*/
1222
function rd_kafka_err2str(int $err): string
1323
{
@@ -17,7 +27,7 @@ function rd_kafka_err2str(int $err): string
1727
/**
1828
* @param int $errnox A system errno
1929
*
20-
* @return int Returns a kafka error code as an integer.
30+
* @return int A kafka error code as an integer.
2131
* @deprecated
2232
*/
2333
function rd_kafka_errno2err(int $errnox): int
@@ -26,7 +36,7 @@ function rd_kafka_errno2err(int $errnox): int
2636
}
2737

2838
/**
29-
* @return int Returns the system errno as an integer.
39+
* @return int The system errno as an integer.
3040
* @deprecated
3141
*/
3242
function rd_kafka_errno(): int
@@ -51,7 +61,7 @@ function rd_kafka_thread_cnt(): int
5161
}
5262

5363
/**
54-
* @return string Returns librdkafka version.
64+
* @return string The librdkafka version.
5565
*/
5666
function rd_kafka_version(): string
5767
{

tests/FunctionsTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,29 @@
1515
*/
1616
class FunctionsTest extends TestCase
1717
{
18+
use RequireVersionTrait;
19+
20+
public function testErr2name(): void
21+
{
22+
$this->assertSame('NO_ERROR', rd_kafka_err2name(RD_KAFKA_RESP_ERR_NO_ERROR));
23+
}
24+
1825
public function testErr2str(): void
1926
{
2027
$this->assertSame('Success', rd_kafka_err2str(RD_KAFKA_RESP_ERR_NO_ERROR));
2128
}
2229

2330
public function testErrno2err(): void
2431
{
32+
$this->requiresRdKafkaExtensionVersion('<', '5');
33+
2534
$this->assertSame(RD_KAFKA_RESP_ERR__FAIL, rd_kafka_errno2err(999));
2635
}
2736

2837
public function testErrno(): void
2938
{
39+
$this->requiresRdKafkaExtensionVersion('<', '5');
40+
3041
$this->assertSame(0, rd_kafka_errno());
3142
}
3243

0 commit comments

Comments
 (0)