You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "sveneld (via GitHub)" <gi...@apache.org> on 2024/03/18 21:26:26 UTC
[PR] [THRIFT-5757] Unit tests for php lib [thrift]
sveneld opened a new pull request, #2949:
URL: https://github.com/apache/thrift/pull/2949
<!-- Explain the changes in the pull request below: -->
<!-- We recommend you review the checklist/tips before submitting a pull request. -->
- [ ] Did you create an [Apache Jira](https://issues.apache.org/jira/projects/THRIFT/issues/) ticket? ([Request account here](https://selfserve.apache.org/jira-account.html), not required for trivial changes)
- [ ] If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
- [ ] Did you squash your changes to a single commit? (not required, but preferred)
- [ ] Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
- [ ] If your change does not involve any code, include `[skip ci]` anywhere in the commit message to free up build resources.
<!--
The Contributing Guide at:
https://github.com/apache/thrift/blob/master/CONTRIBUTING.md
has more details and tips for committing properly.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] THRIFT-5757 Unit tests for php lib [thrift]
Posted by "sveneld (via GitHub)" <gi...@apache.org>.
sveneld commented on code in PR #2949:
URL: https://github.com/apache/thrift/pull/2949#discussion_r1531035530
##########
lib/php/test/Unit/Lib/Server/TSSLServerSocketTest.php:
##########
@@ -0,0 +1,151 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace Test\Thrift\Unit\Lib\Server;
+
+use phpmock\phpunit\PHPMock;
+use PHPUnit\Framework\TestCase;
+use Thrift\Exception\TTransportException;
+use Thrift\Server\TSSLServerSocket;
+use Thrift\Transport\TSocket;
+
+class TSSLServerSocketTest extends TestCase
+{
+ use PHPMock;
+
+ public function testGetSSLHost()
+ {
+ $socket = new TSSLServerSocket();
+
+ $this->assertEquals('ssl://localhost', $socket->getSSLHost('localhost'));
+ $this->assertEquals('ssl://localhost', $socket->getSSLHost('ssl://localhost'));
+ $this->assertEquals('tcp://localhost', $socket->getSSLHost('tcp://localhost'));
+ }
+
+ public function testListenAndClose(): void
+ {
+ $options = [
+ 'ssl' => [
+ 'verify_peer' => true,
+ 'verify_peer_name' => true,
+ 'allow_self_signed' => true,
+ ],
+ ];
+ $context = stream_context_create($options);
+ $socket = new TSSLServerSocket('somehost', 999, $context);
+
+ $listener = tmpfile();
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_server')
+ ->expects($this->once())
+ ->with(
+ 'ssl://somehost:999', #$address
+ $this->anything(), #&$error_code
+ $this->anything(), #&$error_string
+ STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, #int $flags
+ $this->callback(function ($context) use ($options) {
+ $contextOptions = stream_context_get_options($context);
+
+ return is_resource($context) && $options === $contextOptions;
+ })#resource $context
+ )->willReturn($listener);
+
+ $socket->listen();
+
+ $reflection = new \ReflectionClass($socket);
+ $property = $reflection->getProperty('listener_');
+ $property->setAccessible(true);
+
+ $this->assertIsResource($property->getValue($socket));
+
+ $this->getFunctionMock('Thrift\Server', 'fclose')
+ ->expects($this->once())
+ ->with($this->equalTo($listener))
+ ->willReturn(true);
+
+ $socket->close();
+ $this->assertNull($property->getValue($socket));
+ }
+
+ public function testAccept()
+ {
+ $socket = new TSSLServerSocket('somehost', 999);
+ $socket->setAcceptTimeout(1000);
+
+ $listener = tmpfile();
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_server')
+ ->expects($this->once())
+ ->with(
+ 'ssl://somehost:999', #$address
+ $this->anything(), #&$error_code
+ $this->anything(), #&$error_string
+ STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, #int $flags
+ $this->callback(function ($context) {
+ $contextOptions = stream_context_get_options($context);
+
+ return is_resource($context) && $contextOptions === [];
+ }) #resource $context
+ )->willReturn($listener);
+
+ $transportHandle = tmpfile();
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_accept')
+ ->expects($this->once())
+ ->with(
+ $this->equalTo($listener),
+ 1
+ )->willReturn($transportHandle);
+
+ $socket->listen();
+ $result = $socket->accept();
+ $this->assertInstanceOf(TSocket::class, $result);
+
+ $reflection = new \ReflectionClass($result);
+ $property = $reflection->getProperty('handle_');
+ $property->setAccessible(true);
+ $this->assertEquals($transportHandle, $property->getValue($result));
+ }
+
+ public function testAcceptFailed()
+ {
+ $socket = new TSSLServerSocket('somehost', 999);
+ $socket->setAcceptTimeout(1000);
+
+ $listener = tmpfile();
+
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_server')
+ ->expects($this->once())
+ ->with('ssl://somehost:999')
+ ->willReturn($listener);
+
+ $transportHandle = tmpfile();
Review Comment:
++
##########
lib/php/test/Unit/Lib/Server/TServerSocketTest.php:
##########
@@ -0,0 +1,129 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace Test\Thrift\Unit\Lib\Server;
+
+use phpmock\phpunit\PHPMock;
+use PHPUnit\Framework\TestCase;
+use Thrift\Exception\TTransportException;
+use Thrift\Server\TServerSocket;
+use Thrift\Transport\TSocket;
+
+class TServerSocketTest extends TestCase
+{
+ use PHPMock;
+
+ public function testSetAcceptTimeout(): void
+ {
+ $socket = new TServerSocket();
+ $socket->setAcceptTimeout(1000);
+
+ $reflection = new \ReflectionClass($socket);
+ $property = $reflection->getProperty('acceptTimeout_');
+ $property->setAccessible(true);
+
+ $this->assertEquals(1000, $property->getValue($socket));
+ }
+
+ public function testListenAndClose(): void
+ {
+ $socket = new TServerSocket('somehost', 999);
+
+ $listener = tmpfile();
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_server')
+ ->expects($this->once())
+ ->with('tcp://somehost:999')
+ ->willReturn($listener);
+
+ $socket->listen();
+
+ $reflection = new \ReflectionClass($socket);
+ $property = $reflection->getProperty('listener_');
+ $property->setAccessible(true);
+
+ $this->assertIsResource($property->getValue($socket));
+
+ $this->getFunctionMock('Thrift\Server', 'fclose')
+ ->expects($this->once())
+ ->with($this->equalTo($listener))
+ ->willReturn(true);
+
+ $socket->close();
+ $this->assertNull($property->getValue($socket));
+ }
+
+ public function testAccept()
+ {
+ $socket = new TServerSocket('somehost', 999);
+ $socket->setAcceptTimeout(1000);
+
+ $listener = tmpfile();
+
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_server')
+ ->expects($this->once())
+ ->with('tcp://somehost:999')
+ ->willReturn($listener);
+
+ $transportHandle = tmpfile();
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_accept')
+ ->expects($this->once())
+ ->with(
+ $this->equalTo($listener),
+ 1
+ )->willReturn($transportHandle);
+
+ $socket->listen();
+ $result = $socket->accept();
+ $this->assertInstanceOf(TSocket::class, $result);
+
+ $reflection = new \ReflectionClass($result);
+ $property = $reflection->getProperty('handle_');
+ $property->setAccessible(true);
+ $this->assertEquals($transportHandle, $property->getValue($result));
+ }
+
+ public function testAcceptFailed()
+ {
+ $socket = new TServerSocket('somehost', 999);
+ $socket->setAcceptTimeout(1000);
+
+ $listener = tmpfile();
+
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_server')
+ ->expects($this->once())
+ ->with('tcp://somehost:999')
+ ->willReturn($listener);
+
+ $transportHandle = tmpfile();
Review Comment:
++
##########
lib/php/test/Unit/Lib/Server/TSimpleServerTest.php:
##########
@@ -0,0 +1,166 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace Test\Thrift\Unit\Lib\Server;
+
+use PHPUnit\Framework\MockObject\MockObject;
+use PHPUnit\Framework\TestCase;
+use Test\Thrift\Unit\Lib\Server\Fixture\TestProcessor;
+use Thrift\Factory\TProtocolFactory;
+use Thrift\Factory\TTransportFactoryInterface;
+use Thrift\Server\TServerTransport;
+use Thrift\Server\TSimpleServer;
+use Thrift\Transport\TTransport;
+
+class TSimpleServerTest extends TestCase
+{
+ /**
+ * @var object
+ */
+ private $processor;
+ /**
+ * @var MockObject|TServerTransport
+ */
+ private $transport;
+ /**
+ * @var MockObject|TTransportFactoryInterface
+ */
+ private $inputTransportFactory;
+ /**
+ * @var MockObject|TTransportFactoryInterface
+ */
+ private $outputTransportFactory;
+ /**
+ * @var MockObject|TProtocolFactory
+ */
+ private $inputProtocolFactory;
+ /**
+ * @var MockObject|TProtocolFactory
+ */
+ private $outputProtocolFactory;
+ /**
+ * @var TSimpleServer
+ */
+ private $server;
+
+ protected function setUp(): void
+ {
+ $this->processor = $this->createMock(TestProcessor::class);
+ $this->transport = $this->createMock(TServerTransport::class);
+ $this->inputTransportFactory = $this->createMock(TTransportFactoryInterface::class);
+ $this->outputTransportFactory = $this->createMock(TTransportFactoryInterface::class);
+ $this->inputProtocolFactory = $this->createMock(TProtocolFactory::class);
+ $this->outputProtocolFactory = $this->createMock(TProtocolFactory::class);
+
+ $this->server = new TSimpleServer(
+ $this->processor,
+ $this->transport,
+ $this->inputTransportFactory,
+ $this->outputTransportFactory,
+ $this->inputProtocolFactory,
+ $this->outputProtocolFactory
+ );
+ }
+
+ protected function tearDown(): void
+ {
+ unset(
+ $this->processor,
+ $this->transport,
+ $this->inputTransportFactory,
+ $this->outputTransportFactory,
+ $this->inputProtocolFactory,
+ $this->outputProtocolFactory,
+ $this->server
+ );
+ }
+
+ /**
+ * @dataProvider serveDataProvider
+ */
+ public function testServe(
+ $serveLoopCount,
+ array $processLoopResult
+ ): void {
+ $transport = $this->createMock(TTransport::class);
+
+ $this->transport->expects($this->once())
+ ->method('listen');
+ $this->transport->expects($this->exactly($serveLoopCount))
+ ->method('accept')
+ ->willReturn($transport);
+
+ $this->inputTransportFactory->expects($this->exactly($serveLoopCount))
+ ->method('getTransport')
+ ->willReturn($this->createMock(TServerTransport::class));
+ $this->outputTransportFactory->expects($this->exactly($serveLoopCount))
+ ->method('getTransport')
+ ->willReturn($this->createMock(TServerTransport::class));
+
+ $inputProtocol = $this->createMock(TServerTransport::class);
+ $this->inputProtocolFactory->expects($this->exactly($serveLoopCount))
+ ->method('getProtocol')
+ ->willReturn($inputProtocol);
+
+ $outputProtocol = $this->createMock(TServerTransport::class);
+ $this->outputProtocolFactory->expects($this->exactly($serveLoopCount))
+ ->method('getProtocol')
+ ->willReturn($outputProtocol);
+
+ /**
+ * ATTENTION!
+ * it is a hack to stop the server loop in unit test
+ * last call of process can return any value, but should stop server for removing infinitive loop
Review Comment:
++
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] THRIFT-5757 Unit tests for php lib [thrift]
Posted by "Jens-G (via GitHub)" <gi...@apache.org>.
Jens-G merged PR #2949:
URL: https://github.com/apache/thrift/pull/2949
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [THRIFT-5757] Unit tests for php lib [thrift]
Posted by "sveneld (via GitHub)" <gi...@apache.org>.
sveneld commented on code in PR #2949:
URL: https://github.com/apache/thrift/pull/2949#discussion_r1529312735
##########
lib/php/lib/Factory/TFramedTransportFactory.php:
##########
@@ -1,13 +1,32 @@
<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
namespace Thrift\Factory;
use Thrift\Transport\TFramedTransport;
use Thrift\Transport\TTransport;
class TFramedTransportFactory implements TTransportFactoryInterface
{
- public static function getTransport(TTransport $transport)
Review Comment:
instances of TTransportFactoryInterface is always created through new object so there is no any requirement to use here static method.
Discovered this when writing test to TSimpleServer
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] THRIFT-5757 Unit tests for php lib [thrift]
Posted by "sveneld (via GitHub)" <gi...@apache.org>.
sveneld commented on PR #2949:
URL: https://github.com/apache/thrift/pull/2949#issuecomment-2024974807
@Jens-G what we are waiting for?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] THRIFT-5757 Unit tests for php lib [thrift]
Posted by "pkvach (via GitHub)" <gi...@apache.org>.
pkvach commented on code in PR #2949:
URL: https://github.com/apache/thrift/pull/2949#discussion_r1530974244
##########
lib/php/test/Unit/Lib/Server/TSimpleServerTest.php:
##########
@@ -0,0 +1,166 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace Test\Thrift\Unit\Lib\Server;
+
+use PHPUnit\Framework\MockObject\MockObject;
+use PHPUnit\Framework\TestCase;
+use Test\Thrift\Unit\Lib\Server\Fixture\TestProcessor;
+use Thrift\Factory\TProtocolFactory;
+use Thrift\Factory\TTransportFactoryInterface;
+use Thrift\Server\TServerTransport;
+use Thrift\Server\TSimpleServer;
+use Thrift\Transport\TTransport;
+
+class TSimpleServerTest extends TestCase
+{
+ /**
+ * @var object
+ */
+ private $processor;
+ /**
+ * @var MockObject|TServerTransport
+ */
+ private $transport;
+ /**
+ * @var MockObject|TTransportFactoryInterface
+ */
+ private $inputTransportFactory;
+ /**
+ * @var MockObject|TTransportFactoryInterface
+ */
+ private $outputTransportFactory;
+ /**
+ * @var MockObject|TProtocolFactory
+ */
+ private $inputProtocolFactory;
+ /**
+ * @var MockObject|TProtocolFactory
+ */
+ private $outputProtocolFactory;
+ /**
+ * @var TSimpleServer
+ */
+ private $server;
+
+ protected function setUp(): void
+ {
+ $this->processor = $this->createMock(TestProcessor::class);
+ $this->transport = $this->createMock(TServerTransport::class);
+ $this->inputTransportFactory = $this->createMock(TTransportFactoryInterface::class);
+ $this->outputTransportFactory = $this->createMock(TTransportFactoryInterface::class);
+ $this->inputProtocolFactory = $this->createMock(TProtocolFactory::class);
+ $this->outputProtocolFactory = $this->createMock(TProtocolFactory::class);
+
+ $this->server = new TSimpleServer(
+ $this->processor,
+ $this->transport,
+ $this->inputTransportFactory,
+ $this->outputTransportFactory,
+ $this->inputProtocolFactory,
+ $this->outputProtocolFactory
+ );
+ }
+
+ protected function tearDown(): void
+ {
+ unset(
+ $this->processor,
+ $this->transport,
+ $this->inputTransportFactory,
+ $this->outputTransportFactory,
+ $this->inputProtocolFactory,
+ $this->outputProtocolFactory,
+ $this->server
+ );
+ }
+
+ /**
+ * @dataProvider serveDataProvider
+ */
+ public function testServe(
+ $serveLoopCount,
+ array $processLoopResult
+ ): void {
+ $transport = $this->createMock(TTransport::class);
+
+ $this->transport->expects($this->once())
+ ->method('listen');
+ $this->transport->expects($this->exactly($serveLoopCount))
+ ->method('accept')
+ ->willReturn($transport);
+
+ $this->inputTransportFactory->expects($this->exactly($serveLoopCount))
+ ->method('getTransport')
+ ->willReturn($this->createMock(TServerTransport::class));
+ $this->outputTransportFactory->expects($this->exactly($serveLoopCount))
+ ->method('getTransport')
+ ->willReturn($this->createMock(TServerTransport::class));
+
+ $inputProtocol = $this->createMock(TServerTransport::class);
+ $this->inputProtocolFactory->expects($this->exactly($serveLoopCount))
+ ->method('getProtocol')
+ ->willReturn($inputProtocol);
+
+ $outputProtocol = $this->createMock(TServerTransport::class);
+ $this->outputProtocolFactory->expects($this->exactly($serveLoopCount))
+ ->method('getProtocol')
+ ->willReturn($outputProtocol);
+
+ /**
+ * ATTENTION!
+ * it is a hack to stop the server loop in unit test
+ * last call of process can return any value, but should stop server for removing infinitive loop
Review Comment:
```suggestion
* last call of process can return any value, but should stop server for removing infinite loop
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] THRIFT-5757 Unit tests for php lib [thrift]
Posted by "pkvach (via GitHub)" <gi...@apache.org>.
pkvach commented on code in PR #2949:
URL: https://github.com/apache/thrift/pull/2949#discussion_r1530987528
##########
lib/php/test/Unit/Lib/Server/TSSLServerSocketTest.php:
##########
@@ -0,0 +1,151 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace Test\Thrift\Unit\Lib\Server;
+
+use phpmock\phpunit\PHPMock;
+use PHPUnit\Framework\TestCase;
+use Thrift\Exception\TTransportException;
+use Thrift\Server\TSSLServerSocket;
+use Thrift\Transport\TSocket;
+
+class TSSLServerSocketTest extends TestCase
+{
+ use PHPMock;
+
+ public function testGetSSLHost()
+ {
+ $socket = new TSSLServerSocket();
+
+ $this->assertEquals('ssl://localhost', $socket->getSSLHost('localhost'));
+ $this->assertEquals('ssl://localhost', $socket->getSSLHost('ssl://localhost'));
+ $this->assertEquals('tcp://localhost', $socket->getSSLHost('tcp://localhost'));
+ }
+
+ public function testListenAndClose(): void
+ {
+ $options = [
+ 'ssl' => [
+ 'verify_peer' => true,
+ 'verify_peer_name' => true,
+ 'allow_self_signed' => true,
+ ],
+ ];
+ $context = stream_context_create($options);
+ $socket = new TSSLServerSocket('somehost', 999, $context);
+
+ $listener = tmpfile();
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_server')
+ ->expects($this->once())
+ ->with(
+ 'ssl://somehost:999', #$address
+ $this->anything(), #&$error_code
+ $this->anything(), #&$error_string
+ STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, #int $flags
+ $this->callback(function ($context) use ($options) {
+ $contextOptions = stream_context_get_options($context);
+
+ return is_resource($context) && $options === $contextOptions;
+ })#resource $context
+ )->willReturn($listener);
+
+ $socket->listen();
+
+ $reflection = new \ReflectionClass($socket);
+ $property = $reflection->getProperty('listener_');
+ $property->setAccessible(true);
+
+ $this->assertIsResource($property->getValue($socket));
+
+ $this->getFunctionMock('Thrift\Server', 'fclose')
+ ->expects($this->once())
+ ->with($this->equalTo($listener))
+ ->willReturn(true);
+
+ $socket->close();
+ $this->assertNull($property->getValue($socket));
+ }
+
+ public function testAccept()
+ {
+ $socket = new TSSLServerSocket('somehost', 999);
+ $socket->setAcceptTimeout(1000);
+
+ $listener = tmpfile();
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_server')
+ ->expects($this->once())
+ ->with(
+ 'ssl://somehost:999', #$address
+ $this->anything(), #&$error_code
+ $this->anything(), #&$error_string
+ STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, #int $flags
+ $this->callback(function ($context) {
+ $contextOptions = stream_context_get_options($context);
+
+ return is_resource($context) && $contextOptions === [];
+ }) #resource $context
+ )->willReturn($listener);
+
+ $transportHandle = tmpfile();
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_accept')
+ ->expects($this->once())
+ ->with(
+ $this->equalTo($listener),
+ 1
+ )->willReturn($transportHandle);
+
+ $socket->listen();
+ $result = $socket->accept();
+ $this->assertInstanceOf(TSocket::class, $result);
+
+ $reflection = new \ReflectionClass($result);
+ $property = $reflection->getProperty('handle_');
+ $property->setAccessible(true);
+ $this->assertEquals($transportHandle, $property->getValue($result));
+ }
+
+ public function testAcceptFailed()
+ {
+ $socket = new TSSLServerSocket('somehost', 999);
+ $socket->setAcceptTimeout(1000);
+
+ $listener = tmpfile();
+
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_server')
+ ->expects($this->once())
+ ->with('ssl://somehost:999')
+ ->willReturn($listener);
+
+ $transportHandle = tmpfile();
Review Comment:
Looks like it's not being used.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] THRIFT-5757 Unit tests for php lib [thrift]
Posted by "pkvach (via GitHub)" <gi...@apache.org>.
pkvach commented on code in PR #2949:
URL: https://github.com/apache/thrift/pull/2949#discussion_r1530985867
##########
lib/php/test/Unit/Lib/Server/TServerSocketTest.php:
##########
@@ -0,0 +1,129 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace Test\Thrift\Unit\Lib\Server;
+
+use phpmock\phpunit\PHPMock;
+use PHPUnit\Framework\TestCase;
+use Thrift\Exception\TTransportException;
+use Thrift\Server\TServerSocket;
+use Thrift\Transport\TSocket;
+
+class TServerSocketTest extends TestCase
+{
+ use PHPMock;
+
+ public function testSetAcceptTimeout(): void
+ {
+ $socket = new TServerSocket();
+ $socket->setAcceptTimeout(1000);
+
+ $reflection = new \ReflectionClass($socket);
+ $property = $reflection->getProperty('acceptTimeout_');
+ $property->setAccessible(true);
+
+ $this->assertEquals(1000, $property->getValue($socket));
+ }
+
+ public function testListenAndClose(): void
+ {
+ $socket = new TServerSocket('somehost', 999);
+
+ $listener = tmpfile();
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_server')
+ ->expects($this->once())
+ ->with('tcp://somehost:999')
+ ->willReturn($listener);
+
+ $socket->listen();
+
+ $reflection = new \ReflectionClass($socket);
+ $property = $reflection->getProperty('listener_');
+ $property->setAccessible(true);
+
+ $this->assertIsResource($property->getValue($socket));
+
+ $this->getFunctionMock('Thrift\Server', 'fclose')
+ ->expects($this->once())
+ ->with($this->equalTo($listener))
+ ->willReturn(true);
+
+ $socket->close();
+ $this->assertNull($property->getValue($socket));
+ }
+
+ public function testAccept()
+ {
+ $socket = new TServerSocket('somehost', 999);
+ $socket->setAcceptTimeout(1000);
+
+ $listener = tmpfile();
+
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_server')
+ ->expects($this->once())
+ ->with('tcp://somehost:999')
+ ->willReturn($listener);
+
+ $transportHandle = tmpfile();
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_accept')
+ ->expects($this->once())
+ ->with(
+ $this->equalTo($listener),
+ 1
+ )->willReturn($transportHandle);
+
+ $socket->listen();
+ $result = $socket->accept();
+ $this->assertInstanceOf(TSocket::class, $result);
+
+ $reflection = new \ReflectionClass($result);
+ $property = $reflection->getProperty('handle_');
+ $property->setAccessible(true);
+ $this->assertEquals($transportHandle, $property->getValue($result));
+ }
+
+ public function testAcceptFailed()
+ {
+ $socket = new TServerSocket('somehost', 999);
+ $socket->setAcceptTimeout(1000);
+
+ $listener = tmpfile();
+
+ $this->getFunctionMock('Thrift\Server', 'stream_socket_server')
+ ->expects($this->once())
+ ->with('tcp://somehost:999')
+ ->willReturn($listener);
+
+ $transportHandle = tmpfile();
Review Comment:
Looks like it's not being used.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [THRIFT-5757] Unit tests for php lib [thrift]
Posted by "sveneld (via GitHub)" <gi...@apache.org>.
sveneld commented on code in PR #2949:
URL: https://github.com/apache/thrift/pull/2949#discussion_r1529315517
##########
lib/php/lib/Server/TSSLServerSocket.php:
##########
@@ -49,6 +49,10 @@ public function __construct($host = 'localhost', $port = 9090, $context = null)
{
$ssl_host = $this->getSSLHost($host);
parent::__construct($ssl_host, $port);
+ // Initialize a stream context if not provided
+ if ($context === null) {
+ $context = stream_context_create();
Review Comment:
stream_socket_server expects to receive resource instead of null. Perhaps thats why warning is shutted down by @
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [THRIFT-5757] Unit tests for php lib [thrift]
Posted by "sveneld (via GitHub)" <gi...@apache.org>.
sveneld commented on PR #2949:
URL: https://github.com/apache/thrift/pull/2949#issuecomment-2005049716
@pkvach take a look
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] THRIFT-5757 Unit tests for php lib [thrift]
Posted by "sveneld (via GitHub)" <gi...@apache.org>.
sveneld commented on PR #2949:
URL: https://github.com/apache/thrift/pull/2949#issuecomment-2008732569
@Jens-G let's merge this pull request
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] THRIFT-5757 Unit tests for php lib [thrift]
Posted by "pkvach (via GitHub)" <gi...@apache.org>.
pkvach commented on PR #2949:
URL: https://github.com/apache/thrift/pull/2949#issuecomment-2008729002
LGTM
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org