forked from overtrue/easy-sms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHuaxinGatewayTest.php
76 lines (68 loc) · 2.39 KB
/
HuaxinGatewayTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?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\HuaxinGateway;
use Overtrue\EasySms\Message;
use Overtrue\EasySms\PhoneNumber;
use Overtrue\EasySms\Support\Config;
use Overtrue\EasySms\Tests\TestCase;
class HuaxinGatewayTest extends TestCase
{
public function testSend()
{
$config = [
'user_id' => 'mock-user-id',
'password' => 'mock-password',
'account' => 'mock-account',
'ip' => '127.0.0.1',
'ext_no' => '',
];
$gateway = \Mockery::mock(HuaxinGateway::class.'[post]', [$config])->shouldAllowMockingProtectedMethods();
$gateway->shouldReceive('post')->with('http://127.0.0.1/smsJson.aspx', [
'userid' => 'mock-user-id',
'password' => 'mock-password',
'account' => 'mock-account',
'mobile' => 18188888888,
'content' => 'This is a test message.',
'sendTime' => '',
'action' => 'send',
'extno' => '',
])->andReturn([
'returnstatus' => 'Success',
'message' => '操作成功',
'remainpoint' => '100',
'taskID' => '1504080852350206',
'successCounts' => '1',
], [
'returnstatus' => 'Faild',
'message' => '操作失败',
'remainpoint' => '0',
'taskID' => '0',
'successCounts' => '0',
])->times(2);
$message = new Message(['content' => 'This is a test message.']);
$config = new Config($config);
$this->assertSame(
[
'returnstatus' => 'Success',
'message' => '操作成功',
'remainpoint' => '100',
'taskID' => '1504080852350206',
'successCounts' => '1',
],
$gateway->send(new PhoneNumber(18188888888), $message, $config)
);
$this->expectException(GatewayErrorException::class);
$this->expectExceptionCode(400);
$this->expectExceptionMessage('操作失败');
$gateway->send(new PhoneNumber(18188888888), $message, $config);
}
}