sveneld commented on code in PR #2942:
URL: https://github.com/apache/thrift/pull/2942#discussion_r1511758040


##########
lib/php/test/Unit/Lib/Transport/TFramedTransportTest.php:
##########
@@ -0,0 +1,244 @@
+<?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.
+ *
+ * @package thrift.transport
+ */
+
+namespace Test\Thrift\Unit\Lib\Transport;
+
+namespace Unit\Lib\Transport;
+
+use PHPUnit\Framework\TestCase;
+use Thrift\Transport\TFramedTransport;
+use Thrift\Transport\TTransport;
+
+class TFramedTransportTest extends TestCase
+{
+    public function testIsOpen()
+    {
+        $transport = $this->createMock(TTransport::class);
+        $framedTransport = new TFramedTransport($transport);
+
+        $transport
+            ->expects($this->once())
+            ->method('isOpen')
+            ->willReturn(true);
+
+        $this->assertTrue($framedTransport->isOpen());
+    }
+
+    public function testOpen()
+    {
+        $transport = $this->createMock(TTransport::class);
+        $framedTransport = new TFramedTransport($transport);
+
+        $transport
+            ->expects($this->once())
+            ->method('open')
+            ->willReturn(null);
+
+        $this->assertNull($framedTransport->open());
+    }
+
+    public function testClose()
+    {
+        $transport = $this->createMock(TTransport::class);
+        $framedTransport = new TFramedTransport($transport);
+
+        $transport
+            ->expects($this->once())
+            ->method('close')
+            ->willReturn(null);
+
+        $this->assertNull($framedTransport->close());
+    }
+
+    public function testPutBack()
+    {
+        $transport = $this->createMock(TTransport::class);
+        $framedTransport = new TFramedTransport($transport);
+        $framedTransport->putBack('test');
+
+        $ref = new \ReflectionClass($framedTransport);
+        $property = $ref->getProperty('rBuf_');
+        $property->setAccessible(true);
+        $this->assertEquals('test', $property->getValue($framedTransport));
+
+        $framedTransport->putBack('abcde');
+        $this->assertEquals('abcdetest', 
$property->getValue($framedTransport));
+    }
+
+    /**
+     * @dataProvider readDataProvider
+     */
+    public function testRead(
+        $readAllowed,
+        $readBuffer,
+        $lowLevelTransportReadResult,
+        $lowLevelTransportReadAllParams,
+        $lowLevelTransportReadAllResult,
+        $readLength,
+        $expectedReadResult
+    ) {
+        $transport = $this->createMock(TTransport::class);
+        $framedTransport = new TFramedTransport($transport, $readAllowed);
+        $framedTransport->putBack($readBuffer);
+
+        $transport
+            ->expects($readAllowed ? $this->never() : $this->once())
+            ->method('read')
+            ->with($readLength)
+            ->willReturn($lowLevelTransportReadResult);
+
+        $transport
+            ->expects($this->exactly(count($lowLevelTransportReadAllParams)))
+            ->method('readAll')
+            ->withConsecutive(...$lowLevelTransportReadAllParams)

Review Comment:
   https://github.com/sebastianbergmann/phpunit/issues/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



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to