Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 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 | * @package thrift.test |
| 22 | */ |
| 23 | |
| 24 | namespace Test\Thrift\Protocol; |
| 25 | |
| 26 | use PHPUnit\Framework\TestCase; |
| 27 | use Test\Thrift\Fixtures; |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 28 | use Thrift\Protocol\TSimpleJSONProtocol; |
| 29 | use Thrift\Transport\TMemoryBuffer; |
| 30 | |
Robert Lu | 68707d9 | 2018-01-17 19:40:39 +0800 | [diff] [blame^] | 31 | require __DIR__ . '/../../../../vendor/autoload.php'; |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 32 | |
| 33 | /*** |
| 34 | * This test suite depends on running the compiler against the |
| 35 | * standard ThriftTest.thrift file: |
| 36 | * |
| 37 | * lib/php/test$ ../../../compiler/cpp/thrift --gen php -r \ |
| 38 | * --out ./packages ../../../test/ThriftTest.thrift |
| 39 | * |
| 40 | * @runTestsInSeparateProcesses |
| 41 | */ |
| 42 | class TSimpleJSONProtocolTest extends TestCase |
| 43 | { |
| 44 | private $transport; |
| 45 | private $protocol; |
| 46 | |
| 47 | public static function setUpBeforeClass() |
| 48 | { |
Robert Lu | 68707d9 | 2018-01-17 19:40:39 +0800 | [diff] [blame^] | 49 | |
| 50 | /** @var \Composer\Autoload\ClassLoader $loader */ |
| 51 | $loader = require __DIR__ . '/../../../../vendor/autoload.php'; |
| 52 | $loader->addPsr4('', __DIR__ . '/../packages/php'); |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 53 | |
| 54 | Fixtures::populateTestArgs(); |
| 55 | TSimpleJSONProtocolFixtures::populateTestArgsSimpleJSON(); |
| 56 | } |
| 57 | |
| 58 | public function setUp() |
| 59 | { |
| 60 | $this->transport = new TMemoryBuffer(); |
| 61 | $this->protocol = new TSimpleJSONProtocol($this->transport); |
| 62 | $this->transport->open(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * WRITE TESTS |
| 67 | */ |
| 68 | public function testVoidWrite() |
| 69 | { |
| 70 | $args = new \ThriftTest\ThriftTest_testVoid_args(); |
| 71 | $args->write($this->protocol); |
| 72 | |
| 73 | $actual = $this->transport->read(Fixtures::$bufsize); |
| 74 | $expected = TSimpleJSONProtocolFixtures::$testArgsJSON['testVoid']; |
| 75 | |
| 76 | $this->assertEquals($expected, $actual); |
| 77 | } |
| 78 | |
| 79 | public function testString1Write() |
| 80 | { |
| 81 | $args = new \ThriftTest\ThriftTest_testString_args(); |
| 82 | $args->thing = Fixtures::$testArgs['testString1']; |
| 83 | $args->write($this->protocol); |
| 84 | |
| 85 | $actual = $this->transport->read(Fixtures::$bufsize); |
| 86 | $expected = TSimpleJSONProtocolFixtures::$testArgsJSON['testString1']; |
| 87 | |
| 88 | $this->assertEquals($expected, $actual); |
| 89 | } |
| 90 | |
| 91 | public function testString2Write() |
| 92 | { |
| 93 | $args = new \ThriftTest\ThriftTest_testString_args(); |
| 94 | $args->thing = Fixtures::$testArgs['testString2']; |
| 95 | $args->write($this->protocol); |
| 96 | |
| 97 | $actual = $this->transport->read(Fixtures::$bufsize); |
| 98 | $expected = TSimpleJSONProtocolFixtures::$testArgsJSON['testString2']; |
| 99 | |
| 100 | $this->assertEquals($expected, $actual); |
| 101 | } |
| 102 | |
| 103 | public function testDoubleWrite() |
| 104 | { |
| 105 | $args = new \ThriftTest\ThriftTest_testDouble_args(); |
| 106 | $args->thing = Fixtures::$testArgs['testDouble']; |
| 107 | $args->write($this->protocol); |
| 108 | |
| 109 | $actual = $this->transport->read(Fixtures::$bufsize); |
| 110 | $expected = TSimpleJSONProtocolFixtures::$testArgsJSON['testDouble']; |
| 111 | |
| 112 | $this->assertEquals($expected, $actual); |
| 113 | } |
| 114 | |
| 115 | public function testByteWrite() |
| 116 | { |
| 117 | $args = new \ThriftTest\ThriftTest_testByte_args(); |
| 118 | $args->thing = Fixtures::$testArgs['testByte']; |
| 119 | $args->write($this->protocol); |
| 120 | |
| 121 | $actual = $this->transport->read(Fixtures::$bufsize); |
| 122 | $expected = TSimpleJSONProtocolFixtures::$testArgsJSON['testByte']; |
| 123 | |
| 124 | $this->assertEquals($expected, $actual); |
| 125 | } |
| 126 | |
| 127 | public function testI32Write() |
| 128 | { |
| 129 | $args = new \ThriftTest\ThriftTest_testI32_args(); |
| 130 | $args->thing = Fixtures::$testArgs['testI32']; |
| 131 | $args->write($this->protocol); |
| 132 | |
| 133 | $actual = $this->transport->read(Fixtures::$bufsize); |
| 134 | $expected = TSimpleJSONProtocolFixtures::$testArgsJSON['testI32']; |
| 135 | |
| 136 | $this->assertEquals($expected, $actual); |
| 137 | } |
| 138 | |
| 139 | public function testI64Write() |
| 140 | { |
| 141 | $args = new \ThriftTest\ThriftTest_testI64_args(); |
| 142 | $args->thing = Fixtures::$testArgs['testI64']; |
| 143 | $args->write($this->protocol); |
| 144 | |
| 145 | $actual = $this->transport->read(Fixtures::$bufsize); |
| 146 | $expected = TSimpleJSONProtocolFixtures::$testArgsJSON['testI64']; |
| 147 | |
| 148 | $this->assertEquals($expected, $actual); |
| 149 | } |
| 150 | |
| 151 | public function testStructWrite() |
| 152 | { |
| 153 | $args = new \ThriftTest\ThriftTest_testStruct_args(); |
| 154 | $args->thing = Fixtures::$testArgs['testStruct']; |
| 155 | |
| 156 | $args->write($this->protocol); |
| 157 | |
| 158 | $actual = $this->transport->read(Fixtures::$bufsize); |
| 159 | $expected = TSimpleJSONProtocolFixtures::$testArgsJSON['testStruct']; |
| 160 | |
| 161 | $this->assertEquals($expected, $actual); |
| 162 | } |
| 163 | |
| 164 | public function testNestWrite() |
| 165 | { |
| 166 | $args = new \ThriftTest\ThriftTest_testNest_args(); |
| 167 | $args->thing = Fixtures::$testArgs['testNest']; |
| 168 | |
| 169 | $args->write($this->protocol); |
| 170 | |
| 171 | $actual = $this->transport->read(Fixtures::$bufsize); |
| 172 | $expected = TSimpleJSONProtocolFixtures::$testArgsJSON['testNest']; |
| 173 | |
| 174 | $this->assertEquals($expected, $actual); |
| 175 | } |
| 176 | |
| 177 | public function testMapWrite() |
| 178 | { |
| 179 | $args = new \ThriftTest\ThriftTest_testMap_args(); |
| 180 | $args->thing = Fixtures::$testArgs['testMap']; |
| 181 | |
| 182 | $args->write($this->protocol); |
| 183 | |
| 184 | $actual = $this->transport->read(Fixtures::$bufsize); |
| 185 | $expected = TSimpleJSONProtocolFixtures::$testArgsJSON['testMap']; |
| 186 | |
| 187 | $this->assertEquals($expected, $actual); |
| 188 | } |
| 189 | |
| 190 | public function testStringMapWrite() |
| 191 | { |
| 192 | $args = new \ThriftTest\ThriftTest_testStringMap_args(); |
| 193 | $args->thing = Fixtures::$testArgs['testStringMap']; |
| 194 | |
| 195 | $args->write($this->protocol); |
| 196 | |
| 197 | $actual = $this->transport->read(Fixtures::$bufsize); |
| 198 | $expected = TSimpleJSONProtocolFixtures::$testArgsJSON['testStringMap']; |
| 199 | |
| 200 | $this->assertEquals($expected, $actual); |
| 201 | } |
| 202 | |
| 203 | public function testSetWrite() |
| 204 | { |
| 205 | $args = new \ThriftTest\ThriftTest_testSet_args(); |
| 206 | $args->thing = Fixtures::$testArgs['testSet']; |
| 207 | |
| 208 | $args->write($this->protocol); |
| 209 | |
| 210 | $actual = $this->transport->read(Fixtures::$bufsize); |
| 211 | $expected = TSimpleJSONProtocolFixtures::$testArgsJSON['testSet']; |
| 212 | |
| 213 | $this->assertEquals($expected, $actual); |
| 214 | } |
| 215 | |
| 216 | public function testListWrite() |
| 217 | { |
| 218 | $args = new \ThriftTest\ThriftTest_testList_args(); |
| 219 | $args->thing = Fixtures::$testArgs['testList']; |
| 220 | |
| 221 | $args->write($this->protocol); |
| 222 | |
| 223 | $actual = $this->transport->read(Fixtures::$bufsize); |
| 224 | $expected = TSimpleJSONProtocolFixtures::$testArgsJSON['testList']; |
| 225 | |
| 226 | $this->assertEquals($expected, $actual); |
| 227 | } |
| 228 | |
| 229 | public function testEnumWrite() |
| 230 | { |
| 231 | $args = new \ThriftTest\ThriftTest_testEnum_args(); |
| 232 | $args->thing = Fixtures::$testArgs['testEnum']; |
| 233 | |
| 234 | $args->write($this->protocol); |
| 235 | |
| 236 | $actual = $this->transport->read(Fixtures::$bufsize); |
| 237 | $expected = TSimpleJSONProtocolFixtures::$testArgsJSON['testEnum']; |
| 238 | |
| 239 | $this->assertEquals($expected, $actual); |
| 240 | } |
| 241 | |
| 242 | public function testTypedefWrite() |
| 243 | { |
| 244 | $args = new \ThriftTest\ThriftTest_testTypedef_args(); |
| 245 | $args->thing = Fixtures::$testArgs['testTypedef']; |
| 246 | |
| 247 | $args->write($this->protocol); |
| 248 | |
| 249 | $actual = $this->transport->read(Fixtures::$bufsize); |
| 250 | $expected = TSimpleJSONProtocolFixtures::$testArgsJSON['testTypedef']; |
| 251 | |
| 252 | $this->assertEquals($expected, $actual); |
| 253 | } |
| 254 | } |