Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-lb committed Dec 3, 2015
1 parent 2a498d7 commit a8a0ec2
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/conf.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
--TEST--
RdKafka\Conf
--FILE--
<?php

$conf = new RdKafka\Conf();

echo "Setting a string property\n";
$conf->set("client.id", "acme");

echo "Setting an integer property\n";
$conf->set("message.max.bytes", 1 << 20);

echo "Setting a boolean property\n";
$conf->set("topic.metadata.refresh.sparse", "true");

echo "Setting a boolean property to an invalid value\n";
try {
$conf->set("topic.metadata.refresh.sparse", "xx");
} catch(Exception $e) {
printf("Caught a %s: %s\n", get_class($e), $e->getMessage());
}

echo "Setting an invalid property\n";
try {
$conf->set("invalid", "xx");
} catch(Exception $e) {
printf("Caught a %s: %s\n", get_class($e), $e->getMessage());
}

echo "Setting error callback\n";
$conf->setErrorCb(function () { });
$dump = $conf->dump();
var_dump(isset($dump["error_cb"]));

echo "Dumping conf\n";
var_dump(array_intersect_key($conf->dump(), array(
"client.id" => true,
"message.max.bytes" => true,
"topic.metadata.refresh.sparse" => true,
)));

--EXPECT--
Setting a string property
Setting an integer property
Setting a boolean property
Setting a boolean property to an invalid value
Caught a RdKafka\Exception: Expected bool value for "topic.metadata.refresh.sparse": true or false
Setting an invalid property
Caught a RdKafka\Exception: No such configuration property: "invalid"
Setting error callback
bool(true)
Dumping conf
array(3) {
["client.id"]=>
string(4) "acme"
["message.max.bytes"]=>
string(7) "1048576"
["topic.metadata.refresh.sparse"]=>
string(4) "true"
}
12 changes: 12 additions & 0 deletions tests/topic_conf.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
RdKafka\TopicConf
--FILE--
<?php

$conf = new RdKafka\TopicConf();

echo "Setting partitioner\n";
$conf->setPartitioner(RD_KAFKA_MSG_PARTITIONER_RANDOM);

--EXPECT--
Setting partitioner

0 comments on commit a8a0ec2

Please sign in to comment.