Skip to content

Commit 0a8b20b

Browse files
caikealmingyoung
authored andcommitted
Add Mini-program tester's binding/unbinding feature (#1011)
* Added open-platform's mini-program code management about template and draft change template_code to code_template * Fix styles. * Fix styles. * Simplify code_template's function name * Add Mini-program tester's binding/unbinding feature
1 parent 535ca7b commit 0a8b20b

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

src/OpenPlatform/Authorizer/MiniProgram/Application.php

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* @property \EasyWeChat\OpenPlatform\Authorizer\Aggregate\Account\Client $account
2323
* @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code\Client $code
2424
* @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Domain\Client $domain
25+
* @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Tester\Client $tester
2526
*/
2627
class Application extends MiniProgram
2728
{
@@ -39,6 +40,7 @@ public function __construct(array $config = [], array $prepends = [])
3940
AggregateServiceProvider::class,
4041
Code\ServiceProvider::class,
4142
Domain\ServiceProvider::class,
43+
Tester\ServiceProvider::class,
4244
];
4345

4446
foreach ($providers as $provider) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: keal
5+
* Date: 2017/11/6
6+
* Time: 下午2:11
7+
*/
8+
9+
namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Tester;
10+
11+
12+
use EasyWeChat\Kernel\BaseClient;
13+
14+
/**
15+
* Class Client
16+
*
17+
* @author caikeal <[email protected]>
18+
*/
19+
class Client extends BaseClient
20+
{
21+
/**
22+
* 绑定小程序体验者
23+
*
24+
* @param string $wechatId
25+
*
26+
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
27+
*/
28+
public function bind(string $wechatId)
29+
{
30+
return $this->httpPostJson('wxa/bind_tester', [
31+
'wechatid' => $wechatId
32+
]);
33+
}
34+
35+
/**
36+
* 解绑小程序体验者
37+
*
38+
* @param string $wechatId
39+
*
40+
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
41+
*/
42+
public function unbind(string $wechatId)
43+
{
44+
return $this->httpPostJson('wxa/unbind_tester', [
45+
'wechatid' => $wechatId
46+
]);
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the overtrue/wechat.
5+
*
6+
* (c) overtrue <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Tester;
13+
14+
use Pimple\Container;
15+
use Pimple\ServiceProviderInterface;
16+
17+
class ServiceProvider implements ServiceProviderInterface
18+
{
19+
public function register(Container $app)
20+
{
21+
$app['tester'] = function ($app) {
22+
return new Client($app);
23+
};
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: keal
5+
* Date: 2017/11/6
6+
* Time: 下午2:39
7+
*/
8+
9+
namespace EasyWeChat\Tests\OpenPlatform\Authorizer\MiniProgram\Tester;
10+
11+
12+
use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Tester\Client;
13+
use EasyWeChat\Kernel\ServiceContainer;
14+
use EasyWeChat\Tests\TestCase;
15+
16+
class ClientTest extends TestCase
17+
{
18+
public function testBind()
19+
{
20+
$client = $this->mockApiClient(Client::class, [], new ServiceContainer(['app_id' => 'app-id']));
21+
$client->expects()->httpPostJson('wxa/bind_tester', ['wechatid' => 'bar'])->andReturn('mock-result')->once();
22+
$this->assertSame('mock-result', $client->bind('bar'));
23+
}
24+
25+
public function testUnbind()
26+
{
27+
$client = $this->mockApiClient(Client::class, [], new ServiceContainer(['app_id' => 'app-id']));
28+
$client->expects()->httpPostJson('wxa/unbind_tester', ['wechatid' => 'bar'])->andReturn('mock-result')->once();
29+
$this->assertSame('mock-result', $client->unbind('bar'));
30+
}
31+
}

0 commit comments

Comments
 (0)