From 40ce19cc7276f5dc3143855c1c4ccca4345974bb Mon Sep 17 00:00:00 2001 From: milkmeowo Date: Thu, 6 Dec 2018 23:07:58 +0800 Subject: [PATCH] =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=BC=80=E6=94=BE=E5=B9=B3=E5=8F=B0=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=20(#1414)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加企业微信开放平台部分测试用例 * remove doc * fix styleCi --- tests/OpenWork/ApplicationTest.php | 62 ++++++++++++++++++++ tests/OpenWork/Work/Auth/AccessTokenTest.php | 51 ++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 tests/OpenWork/ApplicationTest.php create mode 100644 tests/OpenWork/Work/Auth/AccessTokenTest.php diff --git a/tests/OpenWork/ApplicationTest.php b/tests/OpenWork/ApplicationTest.php new file mode 100644 index 000000000..49b4a2add --- /dev/null +++ b/tests/OpenWork/ApplicationTest.php @@ -0,0 +1,62 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace EasyWeChat\Tests\OpenWork; + +use EasyWeChat\OpenWork\Application; +use EasyWeChat\Tests\TestCase; + +class ApplicationTest extends TestCase +{ + public function testProperties() + { + $app = new Application(['corp_id' => 'mock-corp-id']); + + $this->assertInstanceOf(\EasyWeChat\OpenWork\Server\Guard::class, $app->server); + $this->assertInstanceOf(\EasyWeChat\OpenWork\Corp\Client::class, $app->corp); + $this->assertInstanceOf(\EasyWeChat\OpenWork\Provider\Client::class, $app->provider); + } + + public function testWork() + { + $app = new Application(['corp_id' => 'mock-corp-id']); + $work = $app->work('mock-auth-corp-id', 'mock-permanent-code'); + + $this->assertInstanceOf('\EasyWeChat\OpenWork\Work\Application', $work); + $this->assertInstanceOf('EasyWeChat\OpenWork\Work\Auth\AccessToken', $work->access_token); + + $this->assertInstanceOf('EasyWeChat\Work\Application', $work); + $this->assertInstanceOf(\EasyWeChat\Work\OA\Client::class, $work->oa); + $this->assertInstanceOf(\EasyWeChat\Work\Agent\Client::class, $work->agent); + $this->assertInstanceOf(\EasyWeChat\Work\Chat\Client::class, $work->chat); + $this->assertInstanceOf(\EasyWeChat\Work\Department\Client::class, $work->department); + $this->assertInstanceOf(\EasyWeChat\Work\Media\Client::class, $work->media); + $this->assertInstanceOf(\EasyWeChat\Work\Menu\Client::class, $work->menu); + $this->assertInstanceOf(\EasyWeChat\Work\Message\Client::class, $work->message); + $this->assertInstanceOf(\EasyWeChat\Work\Message\Messenger::class, $work->messenger); + $this->assertInstanceOf(\EasyWeChat\Work\Server\Guard::class, $work->server); + $this->assertInstanceOf(\EasyWeChat\BasicService\Jssdk\Client::class, $work->jssdk); + $this->assertInstanceOf(\Overtrue\Socialite\Providers\WeWorkProvider::class, $work->oauth); + } + + public function testDynamicCalls() + { + $app = new Application(['corp_id' => 'mock-corp-id']); + $app['base'] = new class() { + public function dummyMethod() + { + return 'mock-result'; + } + }; + + $this->assertSame('mock-result', $app->dummyMethod()); + } +} diff --git a/tests/OpenWork/Work/Auth/AccessTokenTest.php b/tests/OpenWork/Work/Auth/AccessTokenTest.php new file mode 100644 index 000000000..8c2ba31b1 --- /dev/null +++ b/tests/OpenWork/Work/Auth/AccessTokenTest.php @@ -0,0 +1,51 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace EasyWeChat\Tests\OpenWork\Work\Auth; + +use EasyWeChat\Kernel\ServiceContainer; +use EasyWeChat\OpenWork\Application; +use EasyWeChat\OpenWork\Work\Auth\AccessToken; +use EasyWeChat\Tests\TestCase; + +class AccessTokenTest extends TestCase +{ + public function testGetCredentials() + { + $app = new ServiceContainer([ + 'corp_id' => '1234', + 'secret' => 'secret', + ]); + $accessToken = \Mockery::mock(AccessToken::class, [$app, 'mock-auth-corp-id', 'mock-permanent-code', new Application()])->makePartial()->shouldAllowMockingProtectedMethods(); + + $this->assertSame([ + 'auth_corpid' => 'mock-auth-corp-id', + 'permanent_code' => 'mock-permanent-code', + ], $accessToken->getCredentials()); + } + + public function testEndpoint() + { + $app = \Mockery::mock(new ServiceContainer()); + + $openWork = new Application(); + + $openWork['suite_access_token'] = \Mockery::mock(\EasyWeChat\OpenWork\SuiteAuth\AccessToken::class, function ($mock) { + $mock->shouldReceive('getToken')->andReturn([ + 'suite_access_token' => 'mock-suit-access-token', + ]); + }); + + $accessToken = \Mockery::mock(AccessToken::class, [$app, 'mock-auth-corp-id', 'mock-permanent-code', $openWork])->makePartial()->shouldAllowMockingProtectedMethods(); + + $this->assertSame('cgi-bin/service/get_corp_token?suite_access_token=mock-suit-access-token', $accessToken->getEndpoint()); + } +}