Closed maxm86545 closed 2 years ago
The following code:
<?php class Example { public function __construct(private \RdKafka\KafkaConsumer $kafkaConsumer) {} public function getMetadata(): \RdKafka\Metadata { return $this->kafkaConsumer->getMetadata(true, null, 5000); } } $kafkaConsumer = new \RdKafka\KafkaConsumer(/** ... **/) $example = new Example($kafkaConsumer); $metadata = $example->getMetadata(); // <- Works successfully $class = new \ReflectionClass($kafkaConsumer); $method = $class->getMethod('getMetadata'); $onlyTopicParameter = $method->getParameters()[1]; $onlyTopicParameter->allowsNull(); // = false
PHPUnit 9.5.20:
<?php // ... public function testGetMetadata(): void { $kafkaMetadataMock = $this->createMock(\RdKafka\Metadata::class); $kafkaConsumerMock = $this->createMock(\RdKafka\KafkaConsumer::class); $kafkaConsumerMock ->expects($this->once()) ->method('getMetadata') ->with( $this->isTrue(), $this->isNull(), $this->identicalTo(5000) ) ->willReturn($kafkaMetadataMock); $class = new \ReflectionClass($kafkaConsumerMock); $method = $class->getMethod('getMetadata'); $onlyTopicParameter = $method->getParameters()[1]; $onlyTopicParameter->allowsNull(); // = false $example = new \Example($kafkaConsumerMock); $metadata = $example->getMetadata(); // <- TypeError $this->assertSame($kafkaMetadataMock, $metadata); } // ...
Resulted in this output:
TypeError: Mock_KafkaConsumer_edc85dc5::getMetadata(): Argument #2 ($only_topic) must be of type RdKafka\Topic, null given
But I expected this output instead:
Test succeeds
Null allowed: https://arnaud.le-blanc.net/php-rdkafka-doc/phpdoc/rdkafka-kafkaconsumer.getmetadata.html
RdKafka\KafkaConsumerTopic|null $only_topic
6.0.1
1.8.2
8.1.6 and 8.0.19
Official php alpine docker container
2.8
Thank you! This should be fixed now, I will push a release soon
Description
The following code:
PHPUnit 9.5.20:
Resulted in this output:
But I expected this output instead:
Null allowed: https://arnaud.le-blanc.net/php-rdkafka-doc/phpdoc/rdkafka-kafkaconsumer.getmetadata.html
php-rdkafka Version
6.0.1
librdkafka Version
1.8.2
PHP Version
8.1.6 and 8.0.19
Operating System
Official php alpine docker container
Kafka Version
2.8