Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mini-program tester's binding/unbinding feature #1011

Merged
merged 6 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/OpenPlatform/Authorizer/MiniProgram/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @property \EasyWeChat\OpenPlatform\Authorizer\Aggregate\Account\Client $account
* @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code\Client $code
* @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Domain\Client $domain
* @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Tester\Client $tester
*/
class Application extends MiniProgram
{
Expand All @@ -39,6 +40,7 @@ public function __construct(array $config = [], array $prepends = [])
AggregateServiceProvider::class,
Code\ServiceProvider::class,
Domain\ServiceProvider::class,
Tester\ServiceProvider::class,
];

foreach ($providers as $provider) {
Expand Down
48 changes: 48 additions & 0 deletions src/OpenPlatform/Authorizer/MiniProgram/Tester/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Created by PhpStorm.
* User: keal
* Date: 2017/11/6
* Time: 下午2:11
*/

namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Tester;


use EasyWeChat\Kernel\BaseClient;

/**
* Class Client
*
* @author caikeal <[email protected]>
*/
class Client extends BaseClient
{
/**
* 绑定小程序体验者
*
* @param string $wechatId
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*/
public function bind(string $wechatId)
{
return $this->httpPostJson('wxa/bind_tester', [
'wechatid' => $wechatId
]);
}

/**
* 解绑小程序体验者
*
* @param string $wechatId
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*/
public function unbind(string $wechatId)
{
return $this->httpPostJson('wxa/unbind_tester', [
'wechatid' => $wechatId
]);
}
}
25 changes: 25 additions & 0 deletions src/OpenPlatform/Authorizer/MiniProgram/Tester/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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\OpenPlatform\Authorizer\MiniProgram\Tester;

use Pimple\Container;
use Pimple\ServiceProviderInterface;

class ServiceProvider implements ServiceProviderInterface
{
public function register(Container $app)
{
$app['tester'] = function ($app) {
return new Client($app);
};
}
}
31 changes: 31 additions & 0 deletions tests/OpenPlatform/Authorizer/MiniProgram/Tester/ClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Created by PhpStorm.
* User: keal
* Date: 2017/11/6
* Time: 下午2:39
*/

namespace EasyWeChat\Tests\OpenPlatform\Authorizer\MiniProgram\Tester;


use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Tester\Client;
use EasyWeChat\Kernel\ServiceContainer;
use EasyWeChat\Tests\TestCase;

class ClientTest extends TestCase
{
public function testBind()
{
$client = $this->mockApiClient(Client::class, [], new ServiceContainer(['app_id' => 'app-id']));
$client->expects()->httpPostJson('wxa/bind_tester', ['wechatid' => 'bar'])->andReturn('mock-result')->once();
$this->assertSame('mock-result', $client->bind('bar'));
}

public function testUnbind()
{
$client = $this->mockApiClient(Client::class, [], new ServiceContainer(['app_id' => 'app-id']));
$client->expects()->httpPostJson('wxa/unbind_tester', ['wechatid' => 'bar'])->andReturn('mock-result')->once();
$this->assertSame('mock-result', $client->unbind('bar'));
}
}