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