| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 5 |
* or more contributor license agreements. See the NOTICE file |
| 6 |
* distributed with this work for additional information |
| 7 |
* regarding copyright ownership. The ASF licenses this file |
| 8 |
* to you under the Apache License, Version 2.0 (the |
| 9 |
* "License"); you may not use this file except in compliance |
| 10 |
* with the License. You may obtain a copy of the License at |
| 11 |
* |
| 12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
* |
| 14 |
* Unless required by applicable law or agreed to in writing, |
| 15 |
* software distributed under the License is distributed on an |
| 16 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 |
* KIND, either express or implied. See the License for the |
| 18 |
* specific language governing permissions and limitations |
| 19 |
* under the License. |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
namespace Test\Thrift\Unit\Lib\Protocol; |
| 24 |
|
| 25 |
use PHPUnit\Framework\TestCase; |
| 26 |
use Thrift\Protocol\TBinaryProtocolAccelerated; |
| 27 |
use Thrift\Transport\TBufferedTransport; |
| 28 |
use Thrift\Transport\TMemoryBuffer; |
| 29 |
use Thrift\Transport\TSocket; |
| 30 |
|
| 31 |
class TBinaryProtocolAcceleratedTest extends TestCase |
| 32 |
{ |
| 33 |
/** |
| 34 |
* @dataProvider constructDataProvider |
| 35 |
*/ |
| 36 |
public function testConstruct( |
| 37 |
$transport, |
| 38 |
$expectedTransport |
| 39 |
) { |
| 40 |
$protocol = new TBinaryProtocolAccelerated($transport); |
| 41 |
$this->assertInstanceOf($expectedTransport, $protocol->getTransport()); |
| 42 |
} |
| 43 |
|
| 44 |
public function constructDataProvider() |
| 45 |
{ |
| 46 |
yield 'not buffered transport' => [ |
| 47 |
'transport' => new TMemoryBuffer(), |
| 48 |
'expectedTransport' => TMemoryBuffer::class, |
| 49 |
]; |
| 50 |
yield 'buffered transport' => [ |
| 51 |
'transport' => new TSocket(), |
| 52 |
'expectedTransport' => TBufferedTransport::class, |
| 53 |
]; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* @dataProvider strictParamsDataProvider |
| 58 |
*/ |
| 59 |
public function testStrictParams($strictRead, $strictWrite) |
| 60 |
{ |
| 61 |
$protocol = new TBinaryProtocolAccelerated(new TMemoryBuffer(), $strictRead, $strictWrite); |
| 62 |
$this->assertEquals($strictRead, $protocol->isStrictRead()); |
| 63 |
$this->assertEquals($strictWrite, $protocol->isStrictWrite()); |
| 64 |
} |
| 65 |
|
| 66 |
public function strictParamsDataProvider() |
| 67 |
{ |
| 68 |
yield 'strict read and write' => [true, true]; |
| 69 |
yield 'not strict read and write' => [false, false]; |
| 70 |
yield 'strict read and not strict write' => [true, false]; |
| 71 |
yield 'not strict read and strict write' => [false, true]; |
| 72 |
} |
| 73 |
} |