Skip to content

Commit

Permalink
新增单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
larvacent committed Mar 18, 2022
1 parent 497ba34 commit daea764
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/Gateways/MaapGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class MaapGateway extends Gateway

const ENDPOINT_URL = 'http://rcsapi.wo.cn:8000/umcinterface/sendtempletmsg';

const ENDPOINT_FORMAT = 'json';

/**
* Send message.
* @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to
Expand Down Expand Up @@ -60,7 +58,6 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config
return $result;
}


/**
* Generate Sign.
*
Expand Down
71 changes: 71 additions & 0 deletions tests/Gateways/MaapGatewayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* This file is part of the overtrue/easy-sms.
*
* (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 Overtrue\EasySms\Tests\Gateways;

use Overtrue\EasySms\Exceptions\GatewayErrorException;
use Overtrue\EasySms\Gateways\MaapGateway;
use Overtrue\EasySms\Message;
use Overtrue\EasySms\PhoneNumber;
use Overtrue\EasySms\Support\Config;
use Overtrue\EasySms\Tests\TestCase;

class MaapGatewayTest extends TestCase
{
public function testSend()
{
$config = [
'cpcode' => 'mock-cpcode',
'key' => 'mock-key',
'excode' => 'mock-excode',
];

$gateway = \Mockery::mock(MaapGateway::class . '[postJson]', [$config])->shouldAllowMockingProtectedMethods();

$params = [
'cpcode' => 'mock-cpcode',
'msg' => '1234',
'mobiles' => '18888888888',
'excode' => 'mock-excode',
'templetid' => '123456',
];
$params['sign'] = md5($params['cpcode'] . $params['msg'] . $params['mobiles'] . $params['excode'] . $params['templetid'] . $config['key']);

$gateway->shouldReceive('postJson')
->with(MaapGateway::ENDPOINT_URL, $params)
->andReturn([
'resultcode' => 0,
'resultmsg' => '成功',
'taskid' => 'C20511170688217',
], [
'resultcode' => 301,
'resultmsg' => 'Error Message',
'taskid' => '',
])->twice();

$message = new Message(['data' => ['1234'], 'template' => '123456']);
$config = new Config($config);
$this->assertSame(
[
'resultcode' => 0,
'resultmsg' => '成功',
'taskid' => 'C20511170688217',
],
$gateway->send(new PhoneNumber(18888888888), $message, $config)
);

$this->expectException(GatewayErrorException::class);
$this->expectExceptionCode(301);
$this->expectExceptionMessage('Error Message');

$gateway->send(new PhoneNumber(18888888888), $message, $config);
}
}

0 comments on commit daea764

Please sign in to comment.