fix php code style

pull/8045/head
thinkerou 8 years ago
parent 1b5f057995
commit 9392b04517
  1. 1
      src/php/lib/Grpc/BaseStub.php
  2. 64
      src/php/tests/interop/interop_client.php
  3. 3
      src/php/tests/unit_tests/CallCredentials2Test.php

@ -182,6 +182,7 @@ class BaseStub
} else {
$hostname = $this->hostname;
}
return 'https://'.$hostname.$service_name;
}

@ -70,7 +70,8 @@ function hardAssertIfStatusOk($status)
*/
function emptyUnary($stub)
{
list($result, $status) = $stub->EmptyCall(new grpc\testing\EmptyMessage())->wait();
list($result, $status) =
$stub->EmptyCall(new grpc\testing\EmptyMessage())->wait();
hardAssertIfStatusOk($status);
hardAssert($result !== null, 'Call completed with a null response');
}
@ -92,8 +93,8 @@ function largeUnary($stub)
* @param $fillUsername boolean whether to fill result with username
* @param $fillOauthScope boolean whether to fill result with oauth scope
*/
function performLargeUnary($stub, $fillUsername = false, $fillOauthScope = false,
$callback = false)
function performLargeUnary($stub, $fillUsername = false,
$fillOauthScope = false, $callback = false)
{
$request_len = 271828;
$response_len = 314159;
@ -141,8 +142,9 @@ function serviceAccountCreds($stub, $args)
$jsonKey = json_decode(
file_get_contents(getenv(CredentialsLoader::ENV_VAR)),
true);
$result = performLargeUnary($stub, $fillUsername = true, $fillOauthScope = true);
hardAssert($result->getUsername() == $jsonKey['client_email'],
$result = performLargeUnary($stub, $fillUsername = true,
$fillOauthScope = true);
hardAssert($result->getUsername() === $jsonKey['client_email'],
'invalid email returned');
hardAssert(strpos($args['oauth_scope'], $result->getOauthScope()) !== false,
'invalid oauth scope returned');
@ -163,8 +165,9 @@ function computeEngineCreds($stub, $args)
if (!array_key_exists('default_service_account', $args)) {
throw new Exception('Missing default_service_account');
}
$result = performLargeUnary($stub, $fillUsername = true, $fillOauthScope = true);
hardAssert($args['default_service_account'] == $result->getUsername(),
$result = performLargeUnary($stub, $fillUsername = true,
$fillOauthScope = true);
hardAssert($args['default_service_account'] === $result->getUsername(),
'invalid email returned');
}
@ -179,8 +182,9 @@ function jwtTokenCreds($stub, $args)
$jsonKey = json_decode(
file_get_contents(getenv(CredentialsLoader::ENV_VAR)),
true);
$result = performLargeUnary($stub, $fillUsername = true, $fillOauthScope = true);
hardAssert($result->getUsername() == $jsonKey['client_email'],
$result = performLargeUnary($stub, $fillUsername = true,
$fillOauthScope = true);
hardAssert($result->getUsername() === $jsonKey['client_email'],
'invalid email returned');
}
@ -195,8 +199,9 @@ function oauth2AuthToken($stub, $args)
$jsonKey = json_decode(
file_get_contents(getenv(CredentialsLoader::ENV_VAR)),
true);
$result = performLargeUnary($stub, $fillUsername = true, $fillOauthScope = true);
hardAssert($result->getUsername() == $jsonKey['client_email'],
$result = performLargeUnary($stub, $fillUsername = true,
$fillOauthScope = true);
hardAssert($result->getUsername() === $jsonKey['client_email'],
'invalid email returned');
}
@ -211,6 +216,7 @@ function updateAuthMetadataCallback($context)
foreach ($result as $key => $value) {
$metadata[strtolower($key)] = $value;
}
return $metadata;
}
@ -226,9 +232,10 @@ function perRpcCreds($stub, $args)
file_get_contents(getenv(CredentialsLoader::ENV_VAR)),
true);
$result = performLargeUnary($stub, $fillUsername = true, $fillOauthScope = true,
$result = performLargeUnary($stub, $fillUsername = true,
$fillOauthScope = true,
'updateAuthMetadataCallback');
hardAssert($result->getUsername() == $jsonKey['client_email'],
hardAssert($result->getUsername() === $jsonKey['client_email'],
'invalid email returned');
}
@ -283,7 +290,8 @@ function serverStreaming($stub)
foreach ($call->responses() as $value) {
hardAssert($i < 4, 'Too many responses');
$payload = $value->getPayload();
hardAssert($payload->getType() === grpc\testing\PayloadType::COMPRESSABLE,
hardAssert(
$payload->getType() === grpc\testing\PayloadType::COMPRESSABLE,
'Payload '.$i.' had the wrong type');
hardAssert(strlen($payload->getBody()) === $sizes[$i],
'Response '.$i.' had the wrong length');
@ -318,7 +326,8 @@ function pingPong($stub)
hardAssert($response !== null, 'Server returned too few responses');
$payload = $response->getPayload();
hardAssert($payload->getType() === grpc\testing\PayloadType::COMPRESSABLE,
hardAssert(
$payload->getType() === grpc\testing\PayloadType::COMPRESSABLE,
'Payload '.$i.' had the wrong type');
hardAssert(strlen($payload->getBody()) === $response_lengths[$i],
'Payload '.$i.' had the wrong length');
@ -425,8 +434,8 @@ function customMetadata($stub)
$initial_metadata = $call->getMetadata();
hardAssert(array_key_exists($ECHO_INITIAL_KEY, $initial_metadata),
'Initial metadata does not contain expected key');
hardAssert($initial_metadata[$ECHO_INITIAL_KEY][0] ==
$ECHO_INITIAL_VALUE,
hardAssert(
$initial_metadata[$ECHO_INITIAL_KEY][0] === $ECHO_INITIAL_VALUE,
'Incorrect initial metadata value');
list($result, $status) = $call->wait();
@ -435,8 +444,9 @@ function customMetadata($stub)
$trailing_metadata = $call->getTrailingMetadata();
hardAssert(array_key_exists($ECHO_TRAILING_KEY, $trailing_metadata),
'Trailing metadata does not contain expected key');
hardAssert($trailing_metadata[$ECHO_TRAILING_KEY][0] ==
$ECHO_TRAILING_VALUE, 'Incorrect trailing metadata value');
hardAssert(
$trailing_metadata[$ECHO_TRAILING_KEY][0] === $ECHO_TRAILING_VALUE,
'Incorrect trailing metadata value');
$streaming_call = $stub->FullDuplexCall($metadata);
@ -451,7 +461,7 @@ function customMetadata($stub)
hardAssert(array_key_exists($ECHO_TRAILING_KEY,
$streaming_trailing_metadata),
'Trailing metadata does not contain expected key');
hardAssert($streaming_trailing_metadata[$ECHO_TRAILING_KEY][0] ==
hardAssert($streaming_trailing_metadata[$ECHO_TRAILING_KEY][0] ===
$ECHO_TRAILING_VALUE, 'Incorrect trailing metadata value');
}
@ -506,7 +516,7 @@ function _makeStub($args)
throw new Exception('Missing argument: --test_case is required');
}
if ($args['server_port'] == 443) {
if ($args['server_port'] === 443) {
$server_address = $args['server_host'];
} else {
$server_address = $args['server_host'].':'.$args['server_port'];
@ -548,7 +558,7 @@ function _makeStub($args)
if (in_array($test_case, ['service_account_creds',
'compute_engine_creds', 'jwt_token_creds', ])) {
if ($test_case == 'jwt_token_creds') {
if ($test_case === 'jwt_token_creds') {
$auth_credentials = ApplicationDefaultCredentials::getCredentials();
} else {
$auth_credentials = ApplicationDefaultCredentials::getCredentials(
@ -558,7 +568,7 @@ function _makeStub($args)
$opts['update_metadata'] = $auth_credentials->getUpdateMetadataFunc();
}
if ($test_case == 'oauth2_auth_token') {
if ($test_case === 'oauth2_auth_token') {
$auth_credentials = ApplicationDefaultCredentials::getCredentials(
$args['oauth_scope']
);
@ -578,8 +588,9 @@ function _makeStub($args)
$opts['update_metadata'] = $update_metadata;
}
if ($test_case == 'unimplemented_method') {
$stub = new grpc\testing\UnimplementedServiceClient($server_address, $opts);
if ($test_case === 'unimplemented_method') {
$stub = new grpc\testing\UnimplementedServiceClient($server_address,
$opts);
} else {
$stub = new grpc\testing\TestServiceClient($server_address, $opts);
}
@ -656,7 +667,8 @@ function interop_main($args, $stub = false)
return $stub;
}
if (isset($_SERVER['PHP_SELF']) && preg_match('/interop_client/', $_SERVER['PHP_SELF'])) {
if (isset($_SERVER['PHP_SELF']) &&
preg_match('/interop_client/', $_SERVER['PHP_SELF'])) {
$args = getopt('', ['server_host:', 'server_port:', 'test_case:',
'use_tls::', 'use_test_ca::',
'server_host_override:', 'oauth_scope:',

@ -170,7 +170,7 @@ class CallCredentials2Test extends PHPUnit_Framework_TestCase
$this->assertTrue(is_string($context->service_url));
$this->assertTrue(is_string($context->method_name));
return "a string";
return 'a string';
}
public function testCallbackWithInvalidReturnValue()
@ -196,5 +196,4 @@ class CallCredentials2Test extends PHPUnit_Framework_TestCase
$this->assertTrue($event->send_close);
$this->assertTrue($event->status->code == Grpc\STATUS_UNAUTHENTICATED);
}
}

Loading…
Cancel
Save