Skip to content

Commit

Permalink
Update SubmailGatewayTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue authored Aug 10, 2018
1 parent 8328dbd commit febe6ef
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/Gateways/SubmailGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,46 @@ public function testSend()

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

public function testProject() {
$config = [
'app_id' => 'mock-app-id',
'app_key' => 'mock-app-key',
// no project id
];
$gateway = \Mockery::mock(SubmailGateway::class.'[post]', [$config])->shouldAllowMockingProtectedMethods();

$gateway->shouldReceive('post')->with('https://api.mysubmail.com/message/xsend.json', [
'appid' => 'mock-app-id',
'signature' => 'mock-app-key',
'project' => 'mock-project',
'to' => new PhoneNumber(18188888888),
'vars' => json_encode(['code' => '123456', 'time' => '15']),
])->andReturn([
'status' => 'success',
'send_id' => '093c0a7df143c087d6cba9cdf0cf3738',
'fee' => 1,
'sms_credits' => 14197,
], [
'status' => 'error',
'code' => 100,
'msg' => 'mock-err-msg',
])->times(2);

$message = new Message(['data' => ['code' => '123456', 'time' => '15', 'project' => 'mock-project']]);
$config = new Config($config);

$this->assertSame([
'status' => 'success',
'send_id' => '093c0a7df143c087d6cba9cdf0cf3738',
'fee' => 1,
'sms_credits' => 14197,
], $gateway->send(new PhoneNumber(18188888888), $message, $config));

$this->expectException(GatewayErrorException::class);
$this->expectExceptionCode(100);
$this->expectExceptionMessage('mock-err-msg');

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

0 comments on commit febe6ef

Please sign in to comment.