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; |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 27 | use Thrift\Serializer\TBinarySerializer; |
| 28 | |
Robert Lu | 68707d9 | 2018-01-17 19:40:39 +0800 | [diff] [blame] | 29 | require __DIR__ . '/../../../../vendor/autoload.php'; |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 30 | |
| 31 | /*** |
| 32 | * This test suite depends on running the compiler against the |
| 33 | * standard ThriftTest.thrift file: |
| 34 | * |
| 35 | * lib/php/test$ ../../../compiler/cpp/thrift --gen php -r \ |
| 36 | * --out ./packages ../../../test/ThriftTest.thrift |
| 37 | * |
| 38 | * @runTestsInSeparateProcesses |
| 39 | */ |
| 40 | class BinarySerializerTest extends TestCase |
| 41 | { |
| 42 | public function setUp() |
| 43 | { |
Robert Lu | 68707d9 | 2018-01-17 19:40:39 +0800 | [diff] [blame] | 44 | /** @var \Composer\Autoload\ClassLoader $loader */ |
| 45 | $loader = require __DIR__ . '/../../../../vendor/autoload.php'; |
| 46 | $loader->addPsr4('', __DIR__ . '/../packages/php'); |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /** |
| 50 | * We try to serialize and deserialize a random object to make sure no exceptions are thrown. |
| 51 | * @see THRIFT-1579 |
| 52 | */ |
| 53 | public function testBinarySerializer() |
| 54 | { |
| 55 | $struct = new \ThriftTest\Xtruct(array('string_thing' => 'abc')); |
| 56 | $serialized = TBinarySerializer::serialize($struct, 'ThriftTest\\Xtruct'); |
| 57 | $deserialized = TBinarySerializer::deserialize($serialized, 'ThriftTest\\Xtruct'); |
| 58 | $this->assertEquals($struct, $deserialized); |
| 59 | } |
| 60 | } |