From 84bcfaea8ed3c748d98ec05c9e02cbb57c7f34fc Mon Sep 17 00:00:00 2001 From: overtrue Date: Tue, 21 Mar 2017 07:29:47 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/OpenPlatform/Authorization.php | 25 ++++++++------- src/OpenPlatform/AuthorizerToken.php | 6 ++-- .../Components/AbstractComponent.php | 6 ++-- src/OpenPlatform/Components/Authorizer.php | 1 - src/OpenPlatform/Components/PreAuthCode.php | 1 - src/OpenPlatform/EventHandlers/Authorized.php | 1 + .../EventHandlers/Unauthorized.php | 2 +- src/OpenPlatform/Guard.php | 18 +++++------ src/OpenPlatform/ServiceProvider.php | 11 +++---- src/OpenPlatform/Traits/Caches.php | 9 +++--- src/OpenPlatform/VerifyTicket.php | 4 +-- tests/Core/CoreAbstractAPITest.php | 2 +- .../OpenPlatform/AuthorizationHandlerTest.php | 30 +++++++++--------- tests/OpenPlatform/AuthorizationTest.php | 22 ++++++------- tests/OpenPlatform/AuthorizerTest.php | 31 +++++++++---------- tests/OpenPlatform/AuthorizerTokenTest.php | 7 ++--- tests/OpenPlatform/GuardTest.php | 18 +++++------ tests/OpenPlatform/OpenPlatformTest.php | 14 ++++----- tests/OpenPlatform/PreAuthCodeTest.php | 15 +++++---- tests/OpenPlatform/VerifyTicketTest.php | 10 +++--- tests/Payment/PaymentNotifyTest.php | 2 +- 21 files changed, 108 insertions(+), 127 deletions(-) diff --git a/src/OpenPlatform/Authorization.php b/src/OpenPlatform/Authorization.php index 18e47a648..74c859812 100644 --- a/src/OpenPlatform/Authorization.php +++ b/src/OpenPlatform/Authorization.php @@ -26,7 +26,7 @@ class Authorization { use Caches; - const CACHE_KEY_ACCESS_TOKEN = 'easywechat.open_platform.authorizer_access_token'; + const CACHE_KEY_ACCESS_TOKEN = 'easywechat.open_platform.authorizer_access_token'; const CACHE_KEY_REFRESH_TOKEN = 'easywechat.open_platform.authorizer_refresh_token'; /** @@ -79,11 +79,12 @@ public function setAuthorizerAppId($authorizerAppId) * Gets the authorizer app id, or throws if not found. * * @return string + * * @throws Exception */ public function getAuthorizerAppId() { - if (! $this->authorizerAppId) { + if (!$this->authorizerAppId) { throw new Exception( 'Authorizer App Id is not present, you may not make the authorization yet.' ); @@ -153,7 +154,7 @@ public function handleAuthorization() /** * Handles the authorizer access token: calls the API, saves the token. * - * @return string The authorizer access token. + * @return string the authorizer access token */ public function handleAuthorizerAccessToken() { @@ -202,7 +203,7 @@ public function getAuthorizerInfo() /** * Saves the authorizer access token in cache. * - * @param Collection|array $data Array structure from WeChat API result. + * @param Collection|array $data array structure from WeChat API result */ public function saveAuthorizerAccessToken($data) { @@ -226,7 +227,7 @@ public function getAuthorizerAccessToken() /** * Saves the authorizer refresh token in cache. * - * @param Collection|array $data Array structure from WeChat API result. + * @param Collection|array $data array structure from WeChat API result */ public function saveAuthorizerRefreshToken($data) { @@ -239,7 +240,8 @@ public function saveAuthorizerRefreshToken($data) * Gets the authorizer refresh token. * * @return string - * @throws Exception When refresh token is not present. + * + * @throws Exception when refresh token is not present */ public function getAuthorizerRefreshToken() { @@ -276,8 +278,8 @@ public function removeAuthorizerRefreshToken() public function getAuthorizerAccessTokenKey() { return self::CACHE_KEY_ACCESS_TOKEN - . '.' . $this->appId - . '.' . $this->getAuthorizerAppId(); + .'.'.$this->appId + .'.'.$this->getAuthorizerAppId(); } /** @@ -288,8 +290,7 @@ public function getAuthorizerAccessTokenKey() public function getAuthorizerRefreshTokenKey() { return self::CACHE_KEY_REFRESH_TOKEN - . '.' . $this->appId - . '.' . $this->getAuthorizerAppId(); + .'.'.$this->appId + .'.'.$this->getAuthorizerAppId(); } - -} \ No newline at end of file +} diff --git a/src/OpenPlatform/AuthorizerToken.php b/src/OpenPlatform/AuthorizerToken.php index 9828cf107..36d8e5c2a 100644 --- a/src/OpenPlatform/AuthorizerToken.php +++ b/src/OpenPlatform/AuthorizerToken.php @@ -32,7 +32,7 @@ use EasyWeChat\Core\AccessToken as BaseAccessToken; /** - * Class AuthorizerToken + * Class AuthorizerToken. * * AuthorizerToken is responsible for the access token of the authorizer, * the complexity is that this access token also requires the refresh token @@ -40,8 +40,6 @@ * process. * * This completely overrides the original AccessToken. - * - * @package EasyWeChat\OpenPlatform */ class AuthorizerToken extends BaseAccessToken { @@ -55,7 +53,7 @@ class AuthorizerToken extends BaseAccessToken /** * AuthorizerAccessToken constructor. * - * @param string $appId + * @param string $appId * @param Authorization $authorization */ public function __construct($appId, Authorization $authorization) diff --git a/src/OpenPlatform/Components/AbstractComponent.php b/src/OpenPlatform/Components/AbstractComponent.php index 2c3f8ad82..7d6ec4d86 100644 --- a/src/OpenPlatform/Components/AbstractComponent.php +++ b/src/OpenPlatform/Components/AbstractComponent.php @@ -59,7 +59,7 @@ abstract class AbstractComponent extends AbstractAPI * AbstractComponent constructor. * * @param AccessToken $accessToken - * @param array $config + * @param array $config * @param $request */ public function __construct($accessToken, array $config, $request = null) @@ -73,7 +73,8 @@ public function __construct($accessToken, array $config, $request = null) * Get AppId. * * @return string - * @throws Exception When app id is not present. + * + * @throws Exception when app id is not present */ public function getAppId() { @@ -107,5 +108,4 @@ public function setAppId($appId) return $this; } - } diff --git a/src/OpenPlatform/Components/Authorizer.php b/src/OpenPlatform/Components/Authorizer.php index 0522027fd..c29b6503e 100644 --- a/src/OpenPlatform/Components/Authorizer.php +++ b/src/OpenPlatform/Components/Authorizer.php @@ -146,5 +146,4 @@ public function setAuthorizerOption($authorizerAppId, $optionName, $optionValue) return $this->parseJSON('json', [self::SET_AUTHORIZER_OPTION, $data]); } - } diff --git a/src/OpenPlatform/Components/PreAuthCode.php b/src/OpenPlatform/Components/PreAuthCode.php index b2f60adce..75dc2f269 100644 --- a/src/OpenPlatform/Components/PreAuthCode.php +++ b/src/OpenPlatform/Components/PreAuthCode.php @@ -50,7 +50,6 @@ class PreAuthCode extends AbstractComponent */ protected $redirectUri; - /** * Get pre auth code. * diff --git a/src/OpenPlatform/EventHandlers/Authorized.php b/src/OpenPlatform/EventHandlers/Authorized.php index 73e8eeeee..0bc84e509 100644 --- a/src/OpenPlatform/EventHandlers/Authorized.php +++ b/src/OpenPlatform/EventHandlers/Authorized.php @@ -48,6 +48,7 @@ public function __construct(Authorization $authorization) public function handle(Collection $message) { $this->authorization->setFromAuthMessage($message); + return $this->authorization->handleAuthorization(); } } diff --git a/src/OpenPlatform/EventHandlers/Unauthorized.php b/src/OpenPlatform/EventHandlers/Unauthorized.php index addf6a656..eaab78177 100644 --- a/src/OpenPlatform/EventHandlers/Unauthorized.php +++ b/src/OpenPlatform/EventHandlers/Unauthorized.php @@ -32,7 +32,7 @@ class Unauthorized extends Authorized { /** - * @inheritdoc + * {@inheritdoc} */ public function handle(Collection $message) { diff --git a/src/OpenPlatform/Guard.php b/src/OpenPlatform/Guard.php index 4ea68544d..cd55af68c 100644 --- a/src/OpenPlatform/Guard.php +++ b/src/OpenPlatform/Guard.php @@ -36,9 +36,9 @@ class Guard extends ServerGuard { - const EVENT_AUTHORIZED = 'authorized'; - const EVENT_UNAUTHORIZED = 'unauthorized'; - const EVENT_UPDATE_AUTHORIZED = 'updateauthorized'; + const EVENT_AUTHORIZED = 'authorized'; + const EVENT_UNAUTHORIZED = 'unauthorized'; + const EVENT_UPDATE_AUTHORIZED = 'updateauthorized'; const EVENT_COMPONENT_VERIFY_TICKET = 'component_verify_ticket'; /** @@ -51,7 +51,7 @@ class Guard extends ServerGuard /** * Guard constructor. * - * @param string $token + * @param string $token * @param Request $request */ public function __construct($token, Request $request = null) @@ -72,11 +72,10 @@ public function setContainer(Container $container) } /** - * @inheritdoc + * {@inheritdoc} */ public function serve() { - // If sees the `auth_code` query parameter in the url, that is, // authorization is successful and it calls back, meanwhile, an // ` authorized` event, which also includes the auth code, is sent @@ -140,7 +139,7 @@ public function listen($callback = null) } /** - * @inheritdoc + * {@inheritdoc} */ protected function handleMessage($message) { @@ -156,7 +155,7 @@ protected function handleMessage($message) if (is_array($result) || $result instanceof Collection) { $message->merge($result); } else { - if (! empty($result)) { + if (!empty($result)) { $message->set('result', $result); } } @@ -174,12 +173,13 @@ protected function handleMessage($message) * @param $type * * @return EventHandlers\EventHandler + * * @throws InvalidArgumentException */ protected function getDefaultHandler($type) { $handler = $this->container->offsetGet("open_platform.handlers.{$type}"); - if (! $handler) { + if (!$handler) { throw new InvalidArgumentException("EventHandler \"$type\" does not exists."); } diff --git a/src/OpenPlatform/ServiceProvider.php b/src/OpenPlatform/ServiceProvider.php index 0cb1242e3..f59413fa0 100644 --- a/src/OpenPlatform/ServiceProvider.php +++ b/src/OpenPlatform/ServiceProvider.php @@ -98,7 +98,7 @@ public function register(Container $pimple) ); }; - $pimple['open_platform.authorization'] = function($pimple) { + $pimple['open_platform.authorization'] = function ($pimple) { return new Authorization( $pimple['open_platform.authorizer'], $pimple['config']['open_platform']['app_id'], @@ -114,18 +114,17 @@ public function register(Container $pimple) }; // Authorization events handlers. - $pimple['open_platform.handlers.component_verify_ticket'] = function($pimple) { + $pimple['open_platform.handlers.component_verify_ticket'] = function ($pimple) { return new ComponentVerifyTicket($pimple['open_platform.verify_ticket']); }; - $pimple['open_platform.handlers.authorized'] = function($pimple) { + $pimple['open_platform.handlers.authorized'] = function ($pimple) { return new Authorized($pimple['open_platform.authorization']); }; - $pimple['open_platform.handlers.updateauthorized'] = function($pimple) { + $pimple['open_platform.handlers.updateauthorized'] = function ($pimple) { return new UpdateAuthorized($pimple['open_platform.authorization']); }; - $pimple['open_platform.handlers.unauthorized'] = function($pimple) { + $pimple['open_platform.handlers.unauthorized'] = function ($pimple) { return new Unauthorized($pimple['open_platform.authorization']); }; } - } diff --git a/src/OpenPlatform/Traits/Caches.php b/src/OpenPlatform/Traits/Caches.php index 3aa470cf5..bf9ab86bc 100644 --- a/src/OpenPlatform/Traits/Caches.php +++ b/src/OpenPlatform/Traits/Caches.php @@ -54,7 +54,7 @@ public function getCache() * Gets the cached data. * * @param string $key - * @param mixed $default A default value or a callable to return the value. + * @param mixed $default a default value or a callable to return the value * * @return mixed */ @@ -75,8 +75,8 @@ public function get($key, $default = null) * Sets the cached data. * * @param string $key - * @param mixed $value - * @param int $life Cache life time in seconds. + * @param mixed $value + * @param int $life cache life time in seconds * * @return bool */ @@ -96,5 +96,4 @@ public function remove($key) { return $this->getCache()->delete($key); } - -} \ No newline at end of file +} diff --git a/src/OpenPlatform/VerifyTicket.php b/src/OpenPlatform/VerifyTicket.php index 0e049e4ab..54dd3f2a9 100644 --- a/src/OpenPlatform/VerifyTicket.php +++ b/src/OpenPlatform/VerifyTicket.php @@ -68,7 +68,7 @@ class VerifyTicket * VerifyTicket constructor. * * @param string $appId - * @param Cache $cache + * @param Cache $cache */ public function __construct($appId, Cache $cache = null) { @@ -129,7 +129,7 @@ public function setCacheKey($cacheKey) public function getCacheKey() { if (is_null($this->cacheKey)) { - return $this->prefix . $this->appId; + return $this->prefix.$this->appId; } return $this->cacheKey; diff --git a/tests/Core/CoreAbstractAPITest.php b/tests/Core/CoreAbstractAPITest.php index a195e8240..b1abf7f7f 100644 --- a/tests/Core/CoreAbstractAPITest.php +++ b/tests/Core/CoreAbstractAPITest.php @@ -92,7 +92,7 @@ public function testParseJSON() $this->expectException(\EasyWeChat\Core\Exceptions\HttpException::class); $this->expectExceptionMessage('Unknown'); $this->expectExceptionCode(24000); - + $collection = $api->parseJSON('get', ['foo', ['bar']]); $this->fail(); } diff --git a/tests/OpenPlatform/AuthorizationHandlerTest.php b/tests/OpenPlatform/AuthorizationHandlerTest.php index 1c749121e..f70095477 100644 --- a/tests/OpenPlatform/AuthorizationHandlerTest.php +++ b/tests/OpenPlatform/AuthorizationHandlerTest.php @@ -5,14 +5,12 @@ * * @author lixiao */ - use EasyWeChat\OpenPlatform\EventHandlers\Authorized; use EasyWeChat\OpenPlatform\EventHandlers\Unauthorized; use EasyWeChat\Support\Collection; class AuthorizationHandlerTest extends AuthorizationTest { - public function testAuthorized() { $appId = 'appid@123'; @@ -25,11 +23,11 @@ public function testAuthorized() ); $message = [ - 'AppId' => 'open-platform-app-id', - 'CreateTIme' => '1413192760', - 'InfoType' => 'authorized', - 'AuthorizerAppid' => 'authorizer-app-id', - 'AuthorizationCode' => 'auth-code', + 'AppId' => 'open-platform-app-id', + 'CreateTIme' => '1413192760', + 'InfoType' => 'authorized', + 'AuthorizerAppid' => 'authorizer-app-id', + 'AuthorizationCode' => 'auth-code', 'AuthorizationCodeExpiredTime' => '600', ]; $authorized = new Authorized($authorization); @@ -58,11 +56,11 @@ public function testUnauthorized() // Authorized => saves the tokens. $message = [ - 'AppId' => 'open-platform-app-id', - 'CreateTIme' => '1413192760', - 'InfoType' => 'authorized', - 'AuthorizerAppid' => 'authorizer-app-id', - 'AuthorizationCode' => 'auth-code', + 'AppId' => 'open-platform-app-id', + 'CreateTIme' => '1413192760', + 'InfoType' => 'authorized', + 'AuthorizerAppid' => 'authorizer-app-id', + 'AuthorizationCode' => 'auth-code', 'AuthorizationCodeExpiredTime' => '600', ]; $authorized = new Authorized($authorization); @@ -70,9 +68,9 @@ public function testUnauthorized() // Unauthorized => removes the tokens. $message = [ - 'AppId' => 'open-platform-app-id', - 'CreateTIme' => '1413192760', - 'InfoType' => 'authorized', + 'AppId' => 'open-platform-app-id', + 'CreateTIme' => '1413192760', + 'InfoType' => 'authorized', 'AuthorizerAppid' => 'authorizer-app-id', ]; $authorized = new Unauthorized($authorization); @@ -82,4 +80,4 @@ public function testUnauthorized() $this->setExpectedException(\EasyWeChat\Core\Exception::class); $this->assertNull($authorization->getAuthorizerRefreshToken()); } -} \ No newline at end of file +} diff --git a/tests/OpenPlatform/AuthorizationTest.php b/tests/OpenPlatform/AuthorizationTest.php index 8d28ee92d..0c7ce523d 100644 --- a/tests/OpenPlatform/AuthorizationTest.php +++ b/tests/OpenPlatform/AuthorizationTest.php @@ -5,14 +5,12 @@ * * @author lixiao */ - use Doctrine\Common\Cache\ArrayCache; use EasyWeChat\OpenPlatform\Authorization; use EasyWeChat\OpenPlatform\Components\Authorizer; class AuthorizationTest extends TestCase { - public function testGetAuthorizationInfo() { $appId = 'appid@123'; @@ -141,12 +139,11 @@ protected function make($appId, $authorizerAppId, $stub = $this->stubAuthorizerToken( $authorizerAccessToken, $authorizerRefreshToken ); - /** @noinspection PhpUnusedParameterInspection */ + /* @noinspection PhpUnusedParameterInspection */ $mockAuthorizer ->shouldReceive('getAuthorizationToken') ->andReturnUsing( - function ($appId, $authorizerRefreshToken) - use ($stub) { + function ($appId, $authorizerRefreshToken) use ($stub) { return $stub; } ); @@ -196,8 +193,8 @@ protected function stubAuthorizationAll($authorizerAppId, { $overrides = [ 'authorization_info' => [ - 'authorizer_appid' => $authorizerAppId, - 'authorizer_access_token' => $authorizerAccessToken, + 'authorizer_appid' => $authorizerAppId, + 'authorizer_access_token' => $authorizerAccessToken, 'authorizer_refresh_token' => $authorizerRefreshToken, ], ]; @@ -209,7 +206,7 @@ protected function stubAuthorizerToken($authorizerAccessToken, $authorizerRefreshToken) { $overrides = [ - 'authorizer_access_token' => $authorizerAccessToken, + 'authorizer_access_token' => $authorizerAccessToken, 'authorizer_refresh_token' => $authorizerRefreshToken, ]; @@ -233,14 +230,13 @@ protected function overrides(array &$array1, array &$array2) $merged = $array1; foreach ($array2 as $key => &$value) { - if (is_array($value) && isset($merged [$key]) && is_array($merged [$key])) { - $merged [$key] = $this->overrides($merged [$key], $value); + if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) { + $merged[$key] = $this->overrides($merged[$key], $value); } else { - $merged [$key] = $value; + $merged[$key] = $value; } } return $merged; } - -} \ No newline at end of file +} diff --git a/tests/OpenPlatform/AuthorizerTest.php b/tests/OpenPlatform/AuthorizerTest.php index d2507caa4..7f975fd5e 100644 --- a/tests/OpenPlatform/AuthorizerTest.php +++ b/tests/OpenPlatform/AuthorizerTest.php @@ -5,12 +5,11 @@ * * @author lixiao */ - use EasyWeChat\OpenPlatform\AccessToken; use EasyWeChat\OpenPlatform\Components\Authorizer; -class AuthorizerTest extends TestCase { - +class AuthorizerTest extends TestCase +{ /** * Authorizer mock. * @@ -21,19 +20,19 @@ class AuthorizerTest extends TestCase { public function mockAuthorizer($appId) { $authorizer = Mockery::mock( - Authorizer::class . '[parseJSON]', + Authorizer::class.'[parseJSON]', [ Mockery::mock(AccessToken::class), ['open_platform' => ['app_id' => $appId]], ] ); - /** @noinspection PhpUnusedParameterInspection */ + /* @noinspection PhpUnusedParameterInspection */ $authorizer ->shouldReceive('parseJSON') ->andReturnUsing(function ($method, $params) { return [ - 'api' => $params[0], + 'api' => $params[0], 'params' => empty($params[1]) ? null : $params[1], ]; }); @@ -50,7 +49,7 @@ public function testGetAuthorizationInfo() $result = $authorizer->getAuthorizationInfo($code); $params = [ - 'component_appid' => $appId, + 'component_appid' => $appId, 'authorization_code' => $code, ]; $this->assertStringStartsWith(Authorizer::GET_AUTH_INFO, $result['api']); @@ -67,8 +66,8 @@ public function testGetAuthorizationToken() $result = $authorizer->getAuthorizationToken($authorizerAppId, $refreshToken); $params = [ - 'component_appid' => $appId, - 'authorizer_appid' => $authorizerAppId, + 'component_appid' => $appId, + 'authorizer_appid' => $authorizerAppId, 'authorizer_refresh_token' => $refreshToken, ]; $this->assertStringStartsWith(Authorizer::GET_AUTHORIZER_TOKEN, $result['api']); @@ -84,7 +83,7 @@ public function testGetAuthorizerInfo() $result = $authorizer->getAuthorizerInfo($authorizerAppId); $params = [ - 'component_appid' => $appId, + 'component_appid' => $appId, 'authorizer_appid' => $authorizerAppId, ]; $this->assertStringStartsWith(Authorizer::GET_AUTHORIZER_INFO, $result['api']); @@ -101,15 +100,16 @@ public function testGetAuthorizerOption() $result = $authorizer->getAuthorizerOption($authorizerAppId, $optionName); $params = [ - 'component_appid' => $appId, + 'component_appid' => $appId, 'authorizer_appid' => $authorizerAppId, - 'option_name' => $optionName, + 'option_name' => $optionName, ]; $this->assertStringStartsWith(Authorizer::GET_AUTHORIZER_OPTION, $result['api']); $this->assertEquals($params, $result['params']); } - public function testSetAuthorizerOption() { + public function testSetAuthorizerOption() + { $appId = 'appid@123'; $authorizer = $this->mockAuthorizer($appId); @@ -120,7 +120,7 @@ public function testSetAuthorizerOption() { $authorizerAppId, $optionName, $optionValue); $params = [ - 'component_appid' => $appId, + 'component_appid' => $appId, 'authorizer_appid' => $authorizerAppId, 'option_name' => $optionName, 'option_value' => $optionValue, @@ -128,5 +128,4 @@ public function testSetAuthorizerOption() { $this->assertStringStartsWith(Authorizer::SET_AUTHORIZER_OPTION, $result['api']); $this->assertEquals($params, $result['params']); } - -} \ No newline at end of file +} diff --git a/tests/OpenPlatform/AuthorizerTokenTest.php b/tests/OpenPlatform/AuthorizerTokenTest.php index d409bbcf0..906f95808 100644 --- a/tests/OpenPlatform/AuthorizerTokenTest.php +++ b/tests/OpenPlatform/AuthorizerTokenTest.php @@ -5,13 +5,11 @@ * * @author lixiao */ - use EasyWeChat\OpenPlatform\Authorization; use EasyWeChat\OpenPlatform\AuthorizerToken; class AuthorizerTokenTest extends TestCase { - public function testGetToken() { $appId = 'appid@123'; @@ -32,7 +30,8 @@ public function testGetTokenExpired() $this->assertEquals($newToken, $token); } - public function testGetTokenForced() { + public function testGetTokenForced() + { $appId = 'appid@123'; $cachedToken = 'token@123'; $newToken = 'token@456'; @@ -53,4 +52,4 @@ private function make($appId, $cachedToken, $newToken) return new AuthorizerToken($appId, $mock); } -} \ No newline at end of file +} diff --git a/tests/OpenPlatform/GuardTest.php b/tests/OpenPlatform/GuardTest.php index 8d7fcb4bb..98c71df78 100644 --- a/tests/OpenPlatform/GuardTest.php +++ b/tests/OpenPlatform/GuardTest.php @@ -5,7 +5,6 @@ * * @author lixiao */ - use EasyWeChat\Foundation\Application; use EasyWeChat\OpenPlatform\EventHandlers\Authorized; use EasyWeChat\OpenPlatform\EventHandlers\ComponentVerifyTicket; @@ -17,15 +16,14 @@ class GuardTest extends TestCase { - public function testGetHandler() { $server = $this->make(); $handlers = [ - Guard::EVENT_AUTHORIZED => Authorized::class, - Guard::EVENT_UNAUTHORIZED => Unauthorized::class, - Guard::EVENT_UPDATE_AUTHORIZED => UpdateAuthorized::class, + Guard::EVENT_AUTHORIZED => Authorized::class, + Guard::EVENT_UNAUTHORIZED => Unauthorized::class, + Guard::EVENT_UPDATE_AUTHORIZED => UpdateAuthorized::class, Guard::EVENT_COMPONENT_VERIFY_TICKET => ComponentVerifyTicket::class, ]; @@ -46,9 +44,9 @@ private function make() { $config = [ 'open_platform' => [ - 'app_id' => 'your-app-id', - 'secret' => 'your-app-secret', - 'token' => 'your-token', + 'app_id' => 'your-app-id', + 'secret' => 'your-app-secret', + 'token' => 'your-token', 'aes_key' => 'your-ase-key', ], ]; @@ -74,7 +72,6 @@ function (Collection $message) { class OpenPlatformGuardStub extends Guard { - public static $message = ['InfoType' => 'test']; public function getHandlerForTest($type) @@ -86,5 +83,4 @@ public function handleMessageForTest() { return $this->handleMessage(self::$message); } - -} \ No newline at end of file +} diff --git a/tests/OpenPlatform/OpenPlatformTest.php b/tests/OpenPlatform/OpenPlatformTest.php index c07a1c6b9..9d90dd740 100644 --- a/tests/OpenPlatform/OpenPlatformTest.php +++ b/tests/OpenPlatform/OpenPlatformTest.php @@ -5,14 +5,13 @@ * * @author lixiao */ - use EasyWeChat\Foundation\Application; use EasyWeChat\OpenPlatform\Components\Authorizer; use EasyWeChat\OpenPlatform\Components\PreAuthCode; use EasyWeChat\OpenPlatform\Guard; -class OpenPlatformTest extends TestCase { - +class OpenPlatformTest extends TestCase +{ public function testOpenPlatform() { $app = $this->make(); @@ -31,14 +30,13 @@ private function make() { $config = [ 'open_platform' => [ - 'app_id' => 'your-app-id', - 'secret' => 'your-app-secret', - 'token' => 'your-token', + 'app_id' => 'your-app-id', + 'secret' => 'your-app-secret', + 'token' => 'your-token', 'aes_key' => 'your-ase-key', ], ]; return new Application($config); } - -} \ No newline at end of file +} diff --git a/tests/OpenPlatform/PreAuthCodeTest.php b/tests/OpenPlatform/PreAuthCodeTest.php index 6c52e6842..f7a0cd312 100644 --- a/tests/OpenPlatform/PreAuthCodeTest.php +++ b/tests/OpenPlatform/PreAuthCodeTest.php @@ -5,12 +5,11 @@ * * @author lixiao */ - use EasyWeChat\OpenPlatform\AccessToken; use EasyWeChat\OpenPlatform\Components\PreAuthCode; -class PreAuthCodeTest extends TestCase { - +class PreAuthCodeTest extends TestCase +{ /** * PreAuthCode mock. * @@ -22,20 +21,20 @@ class PreAuthCodeTest extends TestCase { public function mockPreAuth($appId, $code = null) { $preAuth = Mockery::mock( - PreAuthCode::class . '[parseJSON]', + PreAuthCode::class.'[parseJSON]', [ Mockery::mock(AccessToken::class), ['open_platform' => ['app_id' => $appId]], ] ); - /** @noinspection PhpUnusedParameterInspection */ + /* @noinspection PhpUnusedParameterInspection */ $preAuth ->shouldReceive('parseJSON') ->andReturnUsing(function ($method, $params) use ($code) { return [ - 'api' => $params[0], - 'params' => empty($params[1]) ? null : $params[1], + 'api' => $params[0], + 'params' => empty($params[1]) ? null : $params[1], 'pre_auth_code' => $code, ]; }); @@ -76,4 +75,4 @@ public function testGetAuthLink() $this->assertEquals($link, strtolower($preAuth->getAuthLink())); } -} \ No newline at end of file +} diff --git a/tests/OpenPlatform/VerifyTicketTest.php b/tests/OpenPlatform/VerifyTicketTest.php index 5715e2c88..fdb7658b8 100644 --- a/tests/OpenPlatform/VerifyTicketTest.php +++ b/tests/OpenPlatform/VerifyTicketTest.php @@ -5,17 +5,17 @@ * * @author lixiao */ - use Doctrine\Common\Cache\ArrayCache; use EasyWeChat\OpenPlatform\VerifyTicket; use EasyWeChat\Support\Collection; -class VerifyTicketTest extends TestCase { - +class VerifyTicketTest extends TestCase +{ /** * Tests that the verify ticket is properly cached. */ - public function testCache() { + public function testCache() + { $appId = 'foobar'; $cache = new ArrayCache(); $verifyTicket = new VerifyTicket($appId, $cache); @@ -29,4 +29,4 @@ public function testCache() { $cached = $verifyTicket->getTicket(); $this->assertEquals($ticket, $cached); } -} \ No newline at end of file +} diff --git a/tests/Payment/PaymentNotifyTest.php b/tests/Payment/PaymentNotifyTest.php index 7daa1bd7c..e7322dd31 100644 --- a/tests/Payment/PaymentNotifyTest.php +++ b/tests/Payment/PaymentNotifyTest.php @@ -55,7 +55,7 @@ public function testGetNotifyWithInvalidXMLContent() $this->expectException(FaultException::class); $this->expectExceptionMessageRegExp('/Invalid request XML: .*/'); - + $notify->getNotify(); } }