Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Apr 18, 2024
1 parent 44034b8 commit 73e1f27
Showing 1 changed file with 17 additions and 30 deletions.
47 changes: 17 additions & 30 deletions tests/Gateways/YidongmasblackGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,54 +29,41 @@ public function testSend()
'sign' => 'mock-sign',
'addSerial' => 'mock-add-serial',
];
$gateway = \Mockery::mock(YidongmasblackGateway::class.'[get]', [$config])->shouldAllowMockingProtectedMethods();
$gateway = \Mockery::mock(YidongmasblackGateway::class . '[postJson]', [$config])->shouldAllowMockingProtectedMethods();

$expected = [
'RegionId' => 'cn-hangzhou',
'AccessKeyId' => 'mock-api-key',
'Format' => 'JSON',
'SignatureMethod' => 'HMAC-SHA1',
'SignatureVersion' => '1.0',
// 'SignatureNonce' => uniqid(),
// 'Timestamp' => date('Y-m-d\TH:i:s\Z'),
'Action' => 'SendSms',
'Version' => '2017-05-25',
'PhoneNumbers' => strval(new PhoneNumber(18888888888)),
'SignName' => 'mock-api-sign-name',
'TemplateCode' => 'mock-template-code',
'TemplateParam' => json_encode(['code' => '123456']),
'ecName' => "mock-ec-name",
'apId' => "mock-ap-id",
'sign' => "mock-sign",
'addSerial' => "mock-add-serial",
'mobiles' => 18888888888,
'content' => "123456",
'mac' => "316769171b5b29b13e1fa0a5250ff5e2",
];
$gateway->shouldReceive('post')
$gateway->shouldReceive('postJson')
->with(YidongmasblackGateway::ENDPOINT_URL, \Mockery::on(function ($params) use ($expected) {
if (empty($params['Signature'])) {
return false;
}

unset($params['SignatureNonce'], $params['Timestamp'], $params['Signature']);

ksort($params);
ksort($expected);
$params = json_decode(base64_decode($params), true);

return $params == $expected;
}))
->andReturn([
'Code' => 'OK',
'Message' => 'mock-result',
'success' => 'true',
'rspcod' => '1234',
], [
'Code' => 1234,
'Message' => 'mock-err-msg',
'success' => 'mock-err-msg',
'rspcod' => '1234',
])
->twice();

$message = new Message([
'content' => '123456',
'content' => '123456',
]);

$config = new Config($config);

$this->assertSame([
'Code' => 'OK',
'Message' => 'mock-result',
'success' => 'true',
'rspcod' => '1234',
], $gateway->send(new PhoneNumber(18888888888), $message, $config));

$this->expectException(GatewayErrorException::class);
Expand Down

0 comments on commit 73e1f27

Please sign in to comment.