Skip to content

Commit

Permalink
修复 GuzzleHttp\Client 超时时间设置问题 (overtrue#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
her-cat authored and overtrue committed Aug 1, 2019
1 parent 25140e0 commit b2e7d5b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/EasySms.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Overtrue\EasySms\Contracts\PhoneNumberInterface;
use Overtrue\EasySms\Contracts\StrategyInterface;
use Overtrue\EasySms\Exceptions\InvalidArgumentException;
use Overtrue\EasySms\Gateways\Gateway;
use Overtrue\EasySms\Strategies\OrderStrategy;
use Overtrue\EasySms\Support\Config;
use RuntimeException;
Expand Down Expand Up @@ -223,7 +224,13 @@ protected function createGateway($name)
$gateway = $this->callCustomCreator($name);
} else {
$className = $this->formatGatewayClassName($name);
$gateway = $this->makeGateway($className, $this->config->get("gateways.{$name}", []));
$config = $this->config->get("gateways.{$name}", []);

if (!isset($config['timeout'])) {
$config['timeout'] = $this->config->get('timeout', Gateway::DEFAULT_TIMEOUT);
}

$gateway = $this->makeGateway($className, $config);
}

if (!($gateway instanceof GatewayInterface)) {
Expand Down
15 changes: 15 additions & 0 deletions tests/EasySmsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,21 @@ public function testFormatGateways()
$this->assertSame('g', $gateways['foo']->get('f'));
$this->assertSame('e', $gateways['bar']->get('c'));
}

public function testCreateGatewayWithDefaultTimeout()
{
$easySms = new EasySms([
'timeout' => 10.0,
]);

$gateway = $easySms->gateway('aliyun');

$this->assertSame(10.0, $gateway->getTimeout());

$gateway->setTimeout(9.0);

$this->assertSame(9.0, $gateway->getTimeout());
}
}

class DummyGatewayNotImplementsGatewayInterface
Expand Down

0 comments on commit b2e7d5b

Please sign in to comment.