OLD | NEW |
(Empty) | |
| 1 <?php |
| 2 /* |
| 3 * |
| 4 * Copyright 2015-2016, Google Inc. |
| 5 * All rights reserved. |
| 6 * |
| 7 * Redistribution and use in source and binary forms, with or without |
| 8 * modification, are permitted provided that the following conditions are |
| 9 * met: |
| 10 * |
| 11 * * Redistributions of source code must retain the above copyright |
| 12 * notice, this list of conditions and the following disclaimer. |
| 13 * * Redistributions in binary form must reproduce the above |
| 14 * copyright notice, this list of conditions and the following disclaimer |
| 15 * in the documentation and/or other materials provided with the |
| 16 * distribution. |
| 17 * * Neither the name of Google Inc. nor the names of its |
| 18 * contributors may be used to endorse or promote products derived from |
| 19 * this software without specific prior written permission. |
| 20 * |
| 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 * |
| 33 */ |
| 34 class CallTest extends PHPUnit_Framework_TestCase |
| 35 { |
| 36 public static $server; |
| 37 public static $port; |
| 38 |
| 39 public static function setUpBeforeClass() |
| 40 { |
| 41 self::$server = new Grpc\Server([]); |
| 42 self::$port = self::$server->addHttp2Port('0.0.0.0:0'); |
| 43 } |
| 44 |
| 45 public function setUp() |
| 46 { |
| 47 $this->channel = new Grpc\Channel('localhost:'.self::$port, []); |
| 48 $this->call = new Grpc\Call($this->channel, |
| 49 '/foo', |
| 50 Grpc\Timeval::infFuture()); |
| 51 } |
| 52 |
| 53 public function testAddEmptyMetadata() |
| 54 { |
| 55 $batch = [ |
| 56 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 57 ]; |
| 58 $result = $this->call->startBatch($batch); |
| 59 $this->assertTrue($result->send_metadata); |
| 60 } |
| 61 |
| 62 public function testAddSingleMetadata() |
| 63 { |
| 64 $batch = [ |
| 65 Grpc\OP_SEND_INITIAL_METADATA => ['key' => ['value']], |
| 66 ]; |
| 67 $result = $this->call->startBatch($batch); |
| 68 $this->assertTrue($result->send_metadata); |
| 69 } |
| 70 |
| 71 public function testAddMultiValueMetadata() |
| 72 { |
| 73 $batch = [ |
| 74 Grpc\OP_SEND_INITIAL_METADATA => ['key' => ['value1', 'value2']], |
| 75 ]; |
| 76 $result = $this->call->startBatch($batch); |
| 77 $this->assertTrue($result->send_metadata); |
| 78 } |
| 79 |
| 80 public function testAddSingleAndMultiValueMetadata() |
| 81 { |
| 82 $batch = [ |
| 83 Grpc\OP_SEND_INITIAL_METADATA => ['key1' => ['value1'], |
| 84 'key2' => ['value2', 'value3'], ], |
| 85 ]; |
| 86 $result = $this->call->startBatch($batch); |
| 87 $this->assertTrue($result->send_metadata); |
| 88 } |
| 89 |
| 90 public function testGetPeer() |
| 91 { |
| 92 $this->assertTrue(is_string($this->call->getPeer())); |
| 93 } |
| 94 |
| 95 public function testCancel() |
| 96 { |
| 97 $this->assertNull($this->call->cancel()); |
| 98 } |
| 99 |
| 100 /** |
| 101 * @expectedException InvalidArgumentException |
| 102 */ |
| 103 public function testInvalidMetadataKey() |
| 104 { |
| 105 $batch = [ |
| 106 'invalid' => ['key1' => 'value1'], |
| 107 ]; |
| 108 $result = $this->call->startBatch($batch); |
| 109 } |
| 110 |
| 111 /** |
| 112 * @expectedException InvalidArgumentException |
| 113 */ |
| 114 public function testInvalidMetadataInnerValue() |
| 115 { |
| 116 $batch = [ |
| 117 Grpc\OP_SEND_INITIAL_METADATA => ['key1' => 'value1'], |
| 118 ]; |
| 119 $result = $this->call->startBatch($batch); |
| 120 } |
| 121 |
| 122 } |
OLD | NEW |