Skip to content

Commit

Permalink
update stubs for 4.0 (#24)
Browse files Browse the repository at this point in the history
* update stubs for 4.0

* move offset positions to right place

* throw exceptions on deprecated functions

* expect deprecated

* remove return types

* remove function typeremove function types

* update ext version
  • Loading branch information
nick-zh authored and kwn committed Oct 22, 2019
1 parent 0938520 commit b93d562
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
],
"require": {
"ext-rdkafka": ">=3.1"
"ext-rdkafka": ">=4.0"
},
"require-dev": {
"phpunit/phpunit": "^8.2.4"
Expand Down
32 changes: 25 additions & 7 deletions stubs/RdKafka.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ public function getOutQLen()
{
}

/**
* @return Queue
*/
public function newQueue()
{
}

/**
* @param string $topic_name
* @param TopicConf $topic_conf
Expand Down Expand Up @@ -81,4 +74,29 @@ public function setLogLevel($level)
public function queryWatermarkOffsets($topic, $partition, &$low, &$high, $timeout_ms)
{
}

/**
* @param array $topicPartitions
* @param int $timeout_ms
* @return array
*/
public function offsetsForTimes ($topicPartitions , $timeout_ms)
{
}

/**
* @param int $purge_flags
* @return int
*/
public function purge($purge_flags)
{
}

/**
* @param int $timeout_ms
* @return int
*/
public function flush($timeout_ms)
{
}
}
9 changes: 9 additions & 0 deletions stubs/RdKafka/Conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,13 @@ public function setConsumeCb(callable $callback)
public function setOffsetCommitCb(callable $callback)
{
}

/**
* @param callable $callback
*
* @return void
*/
public function setLogCb(callable $callback)
{
}
}
7 changes: 7 additions & 0 deletions stubs/RdKafka/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ public function __construct(Conf $conf = null)
public function newTopic($topic_name, TopicConf $topic_conf = null)
{
}

/**
* @return Queue
*/
public function newQueue()
{
}
}
10 changes: 10 additions & 0 deletions stubs/RdKafka/ConsumerTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,14 @@ public function consumeStop($partition)
public function offsetStore($partition, $offset)
{
}

/**
* @param int $partition
* @param int $timeout_ms
* @param int $batch_size
* @return array
*/
public function consumeBatch($partition, $timeout_ms, $batch_size)
{
}
}
35 changes: 35 additions & 0 deletions stubs/RdKafka/KafkaConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,39 @@ public function unsubscribe()
public function getCommittedOffsets($topics, $timeout)
{
}

/**
* @param array $topicPartitions
* @param int $timeout_ms
* @return array
*/
public function offsetsForTimes ($topicPartitions , $timeout_ms)
{
}

/**
* @param string $topic
* @param int $partition
* @param int $low
* @param int $high
* @param int $timeout_ms
*/
public function queryWatermarkOffsets($topic, $partition, &$low, &$high, $timeout_ms)
{
}

/**
* @param array $topics
* @return array
*/
public function getOffsetPositions($topics)
{
}

/**
* @return void
*/
public function close()
{
}
}
11 changes: 9 additions & 2 deletions stubs/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,15 @@
const RD_KAFKA_CONF_UNKNOWN = -2;
const RD_KAFKA_CONF_INVALID = -1;
const RD_KAFKA_CONF_OK = 0;
const RD_KAFKA_MSG_PARTITIONER_RANDOM = 0;
const RD_KAFKA_MSG_PARTITIONER_CONSISTENT = 0;
const RD_KAFKA_MSG_PARTITIONER_RANDOM = 2;
const RD_KAFKA_MSG_PARTITIONER_CONSISTENT = 3;
const RD_KAFKA_MSG_PARTITIONER_CONSISTENT_RANDOM = 4;
const RD_KAFKA_MSG_PARTITIONER_MURMUR2 = 5;
const RD_KAFKA_MSG_PARTITIONER_MURMUR2_RANDOM = 6;
const RD_KAFKA_LOG_PRINT = 0;
const RD_KAFKA_LOG_SYSLOG = 0;
const RD_KAFKA_LOG_SYSLOG_PRINT = 0;
const RD_KAFKA_PURGE_F_QUEUE = 0x1;
const RD_KAFKA_PURGE_F_INFLIGHT = 0x2;
const RD_KAFKA_PURGE_F_NON_BLOCKING = 0x4;
const RD_KAFKA_MSG_F_BLOCK = 0x4;
3 changes: 3 additions & 0 deletions tests/RdKafka/ConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace RdKafka;

use PHPUnit\Framework\Error\Deprecated;
use PHPUnit\Framework\TestCase;

class ConsumerTest extends TestCase
Expand Down Expand Up @@ -69,6 +70,8 @@ public function testPoll()

public function testSetLogLevel()
{
$this->expectException(Deprecated::class);

$this->consumer->setLogLevel(LOG_DEBUG);

$this->markTestIncomplete('Create real test');
Expand Down
3 changes: 3 additions & 0 deletions tests/RdKafka/ProducerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace RdKafka;

use PHPUnit\Framework\Error\Deprecated;
use PHPUnit\Framework\TestCase;

class ProducerTest extends TestCase
Expand Down Expand Up @@ -75,6 +76,8 @@ public function testPoll()

public function testSetLogLevel()
{
$this->expectException(Deprecated::class);

$this->producer->setLogLevel(LOG_DEBUG);

self::markTestIncomplete('Create real test');
Expand Down

0 comments on commit b93d562

Please sign in to comment.