forked from w7corp/easywechat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 增加企业微信开放平台部分测试用例 * remove doc * fix styleCi
- Loading branch information
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/wechat. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* 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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/wechat. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* 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()); | ||
} | ||
} |