blob: 71b0bb5066aded32a21c8e15c73f425e70df347f [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;
Robert Lu12f124c2018-01-25 23:19:41 +080027use Thrift\Serializer\TBinarySerializer;
28
Robert Lu68707d92018-01-17 19:40:39 +080029require __DIR__ . '/../../../../vendor/autoload.php';
Robert Lu12f124c2018-01-25 23:19:41 +080030
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 */
40class BinarySerializerTest extends TestCase
41{
42 public function setUp()
43 {
Robert Lu68707d92018-01-17 19:40:39 +080044 /** @var \Composer\Autoload\ClassLoader $loader */
45 $loader = require __DIR__ . '/../../../../vendor/autoload.php';
46 $loader->addPsr4('', __DIR__ . '/../packages/php');
Robert Lu12f124c2018-01-25 23:19:41 +080047 }
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}