| 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\Exception\TException; |
| 27 |
use Thrift\Protocol\TSimpleJSONProtocol; |
| 28 |
use Thrift\Transport\TTransport; |
| 29 |
use Thrift\Type\TType; |
| 30 |
|
| 31 |
class TSimpleJSONProtocolTest extends TestCase |
| 32 |
{ |
| 33 |
/** |
| 34 |
* Reading methods. |
| 35 |
* |
| 36 |
* simplejson is not meant to be read back into thrift |
| 37 |
* - see http://wiki.apache.org/thrift/ThriftUsageJava |
| 38 |
* - use JSON instead |
| 39 |
* |
| 40 |
* @dataProvider readDataProvider |
| 41 |
*/ |
| 42 |
public function testRead( |
| 43 |
$methodName, |
| 44 |
$methodArguments |
| 45 |
) { |
| 46 |
$this->expectException(TException::class); |
| 47 |
$this->expectExceptionMessage("Not implemented"); |
| 48 |
|
| 49 |
$transport = $this->createMock(TTransport::class); |
| 50 |
$protocol = new TSimpleJSONProtocol($transport); |
| 51 |
$protocol->$methodName(...$methodArguments); |
| 52 |
} |
| 53 |
|
| 54 |
public function readDataProvider() |
| 55 |
{ |
| 56 |
yield 'readMessageBegin' => [ |
| 57 |
'methodName' => 'readMessageBegin', |
| 58 |
'methodArguments' => ['name', 'type', 'seqId'], |
| 59 |
]; |
| 60 |
yield 'readMessageEnd' => [ |
| 61 |
'methodName' => 'readMessageEnd', |
| 62 |
'methodArguments' => [], |
| 63 |
]; |
| 64 |
yield 'readStructBegin' => [ |
| 65 |
'methodName' => 'readStructBegin', |
| 66 |
'methodArguments' => ['name'], |
| 67 |
]; |
| 68 |
yield 'readStructEnd' => [ |
| 69 |
'methodName' => 'readStructEnd', |
| 70 |
'methodArguments' => [], |
| 71 |
]; |
| 72 |
yield 'readFieldBegin' => [ |
| 73 |
'methodName' => 'readFieldBegin', |
| 74 |
'methodArguments' => ['name', TType::STRING, 1], |
| 75 |
]; |
| 76 |
yield 'readFieldEnd' => [ |
| 77 |
'methodName' => 'readFieldEnd', |
| 78 |
'methodArguments' => [], |
| 79 |
]; |
| 80 |
yield 'readMapBegin' => [ |
| 81 |
'methodName' => 'readMapBegin', |
| 82 |
'methodArguments' => [TType::STRING, TType::STRING, 1], |
| 83 |
]; |
| 84 |
yield 'readMapEnd' => [ |
| 85 |
'methodName' => 'readMapEnd', |
| 86 |
'methodArguments' => [], |
| 87 |
]; |
| 88 |
yield 'readListBegin' => [ |
| 89 |
'methodName' => 'readListBegin', |
| 90 |
'methodArguments' => [TType::STRING, 1], |
| 91 |
]; |
| 92 |
yield 'readListEnd' => [ |
| 93 |
'methodName' => 'readListEnd', |
| 94 |
'methodArguments' => [], |
| 95 |
]; |
| 96 |
yield 'readSetBegin' => [ |
| 97 |
'methodName' => 'readSetBegin', |
| 98 |
'methodArguments' => [TType::STRING, 1], |
| 99 |
]; |
| 100 |
yield 'readSetEnd' => [ |
| 101 |
'methodName' => 'readSetEnd', |
| 102 |
'methodArguments' => [], |
| 103 |
]; |
| 104 |
yield 'readBool' => [ |
| 105 |
'methodName' => 'readBool', |
| 106 |
'methodArguments' => [true], |
| 107 |
]; |
| 108 |
yield 'readByte' => [ |
| 109 |
'methodName' => 'readByte', |
| 110 |
'methodArguments' => [0x01], |
| 111 |
]; |
| 112 |
yield 'readI16' => [ |
| 113 |
'methodName' => 'readI16', |
| 114 |
'methodArguments' => [1], |
| 115 |
]; |
| 116 |
yield 'readI32' => [ |
| 117 |
'methodName' => 'readI32', |
| 118 |
'methodArguments' => [1], |
| 119 |
]; |
| 120 |
yield 'readI64' => [ |
| 121 |
'methodName' => 'readI64', |
| 122 |
'methodArguments' => [1], |
| 123 |
]; |
| 124 |
yield 'readDouble' => [ |
| 125 |
'methodName' => 'readDouble', |
| 126 |
'methodArguments' => [0.1], |
| 127 |
]; |
| 128 |
yield 'readString' => [ |
| 129 |
'methodName' => 'readString', |
| 130 |
'methodArguments' => ['string'], |
| 131 |
]; |
| 132 |
} |
| 133 |
} |