| 1 |
<?php |
| 2 |
/* |
| 3 |
* |
| 4 |
* Copyright 2015 gRPC authors. |
| 5 |
* |
| 6 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 |
* you may not use this file except in compliance with the License. |
| 8 |
* You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, software |
| 13 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 |
* See the License for the specific language governing permissions and |
| 16 |
* limitations under the License. |
| 17 |
* |
| 18 |
*/ |
| 19 |
|
| 20 |
require_once(dirname(__FILE__) . '/../../lib/Grpc/Status.php'); |
| 21 |
|
| 22 |
class StatusTest extends \PHPUnit\Framework\TestCase |
| 23 |
{ |
| 24 |
public function testStatusOk() |
| 25 |
{ |
| 26 |
$status = [ |
| 27 |
'code' => \Grpc\STATUS_OK, |
| 28 |
'details' => 'OK', |
| 29 |
]; |
| 30 |
$return = \Grpc\Status::ok(); |
| 31 |
$this->assertEquals($status, $return); |
| 32 |
} |
| 33 |
|
| 34 |
public function testStatusOkWithMetadata() |
| 35 |
{ |
| 36 |
$status = [ |
| 37 |
'code' => \Grpc\STATUS_OK, |
| 38 |
'details' => 'OK', |
| 39 |
'metadata' => ['a' => 1], |
| 40 |
]; |
| 41 |
$return = \Grpc\Status::ok(['a' => 1]); |
| 42 |
$this->assertEquals($status, $return); |
| 43 |
} |
| 44 |
|
| 45 |
public function testStatusUnimplemented() |
| 46 |
{ |
| 47 |
$status = [ |
| 48 |
'code' => \Grpc\STATUS_UNIMPLEMENTED, |
| 49 |
'details' => 'UNIMPLEMENTED', |
| 50 |
]; |
| 51 |
$return = \Grpc\Status::unimplemented(); |
| 52 |
$this->assertEquals($status, $return); |
| 53 |
} |
| 54 |
|
| 55 |
public function testStatus() |
| 56 |
{ |
| 57 |
$status = [ |
| 58 |
'code' => \Grpc\STATUS_INVALID_ARGUMENT, |
| 59 |
'details' => 'invalid argument', |
| 60 |
]; |
| 61 |
$return = \Grpc\Status::status( |
| 62 |
\Grpc\STATUS_INVALID_ARGUMENT, |
| 63 |
"invalid argument" |
| 64 |
); |
| 65 |
$this->assertEquals($status, $return); |
| 66 |
} |
| 67 |
|
| 68 |
public function testStatusWithMetadata() |
| 69 |
{ |
| 70 |
$status = [ |
| 71 |
'code' => \Grpc\STATUS_INVALID_ARGUMENT, |
| 72 |
'details' => 'invalid argument', |
| 73 |
'metadata' => ['trailiingMeta' => 100] |
| 74 |
]; |
| 75 |
$return = \Grpc\Status::status( |
| 76 |
\Grpc\STATUS_INVALID_ARGUMENT, |
| 77 |
"invalid argument", |
| 78 |
['trailiingMeta' => 100] |
| 79 |
); |
| 80 |
$this->assertEquals($status, $return); |
| 81 |
} |
| 82 |
} |