-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
THRIFT-5757 Unit tests for php lib #2942
Conversation
@pkvach take a look please |
lib/php/lib/Transport/TSSLSocket.php
Outdated
if ($this->context_ === null) { | ||
$this->context_ = stream_context_create(); | ||
} else { | ||
$this->context_ = $context; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
giving null to stream_socket_client as a context generate a warning, so it's better to create an empty context if it does not provided
@@ -87,7 +92,8 @@ public function open() | |||
throw new TTransportException('Socket already connected', TTransportException::ALREADY_OPEN); | |||
} | |||
|
|||
if (empty($this->host_)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it does not work because ssl:// always added to hostname
@@ -253,7 +253,9 @@ public function open() | |||
if (function_exists('socket_import_stream') && function_exists('socket_set_option')) { | |||
// warnings silenced due to bug https://bugs.php.net/bug.php?id=70939 | |||
$socket = @socket_import_stream($this->handle_); | |||
@socket_set_option($socket, SOL_TCP, TCP_NODELAY, 1); | |||
if ($socket !== false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previous function can return false, and in php 8.0 it trigger a type error, so i added a check.
In future it will be great to remove all @ and work correctly with all warning and error generated by stream functions
I found a library https://github.com/php-mock/php-mock-phpunit so I will try to rewrite tests with better coverage and best readability |
$transport | ||
->expects($this->exactly(count($lowLevelTransportReadAllParams))) | ||
->method('readAll') | ||
->withConsecutive(...$lowLevelTransportReadAllParams) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withConsecutive()
is deprecated and has been removed in PHPUnit 10.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will read about it. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sebastianbergmann/phpunit#4026 i read this long discussion. As I understand it's possible to use something like taht
->with(self::callback(function (string $message) {
static $i = 0;
return match (++$i) {
1 => $message === 'Removing audio files started.',
2 => $message === "Removing audio files that older than '2018-01-01 00:00:00'.",
};
}));
But maybe someone will offer solution which will be accepted by phpunit maintainers.
I prefer to leave using of this method till migration to php8, where we can use match, maybe to this moment we will have bettre replacement for withConsecutive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I agree to leave it as is for now. Thanks.
build/docker/ubuntu-focal/Dockerfile
Outdated
re2c \ | ||
composer | ||
|
||
RUN pecl install xdebug-3.1.1 && \ | ||
echo "zend_extension=xdebug.so" > /etc/php/7.4/cli/conf.d/20-xdebug.ini |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for some docker builds was missed extensions and xdebug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there may be an issue here.
The Dockerfile installs PHP without specifying a version, so it will install the latest version available in the package repository. However, the Xdebug configuration is written to a specific PHP 7.4 directory. If the installed PHP version is not 7.4, the Xdebug configuration will not be applied because PHP won't be able to find it.
Same for other Dockerfiles as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was easier than I thought :)
RUN apt-get install -y --no-install-recommends php-xdebug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -227,7 +228,6 @@ public function flush() | |||
register_shutdown_function(array('Thrift\\Transport\\TCurlClient', 'closeCurlHandle')); | |||
self::$curlHandle = curl_init(); | |||
curl_setopt(self::$curlHandle, CURLOPT_RETURNTRANSFER, true); | |||
curl_setopt(self::$curlHandle, CURLOPT_BINARYTRANSFER, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CURLOPT_BINARYTRANSFER This constant had no effect since PHP 5.1.2
5709382
to
4be2491
Compare
Can we squash that bunch of commits please? If it is work in progress consider marking it as "draft". If it is otherwise unrelated PRs that you want to stay separated for some reason or another, do that. |
@pkvach currently I have a trouble when running all tests together
i added var_dump(error_get_last()); and it showed me such error.
Maybe you have any idea how to fix of how to debug it? |
Marked as a draft, when i will finish coverage of folder Transport i will squash all commits and mark pull request as ready for review. |
@sveneld Regarding the falling Looks like the issue is due to the fact that the To fix this, I think we can move the creation of the file resource into the test method itself. I'm attaching an example solution with changes for Maybe you'll have another option. |
You was right, moving creation of file resource into the test method helped to solve the trouble. One more class left to cover with test in folder Transport and this pull request will be ready :) |
Great progress! Thank you for all the good work you do. |
* installed, then these null functions will step in and act like cache | ||
* misses. | ||
*/ | ||
if (!function_exists('apcu_fetch')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move it inside class as private methods. Global redeclare is not very good.
Update of docker images will be in #2937 |
protected function setUp(): void | ||
{ | ||
#need to be defined before the TSocketPool class definition | ||
$this->defineFunctionMock('Thrift\Transport', 'function_exists'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->defineFunctionMock('Thrift\Transport', 'function_exists'); | |
self::defineFunctionMock('Thrift\Transport', 'function_exists'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
LGTM |
@Jens-G let's merge this pull request |
After running PHP unit tests for each pull request THRIFT-5756
Next step is writing test for php lib.
It will be several pull request for this task.
[skip ci]
anywhere in the commit message to free up build resources.