Skip to content

Commit

Permalink
增加企业微信开放平台部分测试用例 (w7corp#1414)
Browse files Browse the repository at this point in the history
* 增加企业微信开放平台部分测试用例

* remove doc

* fix styleCi
  • Loading branch information
milkmeowo authored and overtrue committed Dec 6, 2018
1 parent 370ef23 commit 40ce19c
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/OpenWork/ApplicationTest.php
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());
}
}
51 changes: 51 additions & 0 deletions tests/OpenWork/Work/Auth/AccessTokenTest.php
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());
}
}

0 comments on commit 40ce19c

Please sign in to comment.