Added testing.

This commit is contained in:
李铭昕 2019-08-24 11:15:25 +08:00
parent d641683bce
commit 3483eef500
3 changed files with 70 additions and 4 deletions

View File

@ -17,6 +17,10 @@
- [#401](https://github.com/hyperf-cloud/hyperf/pull/401) Deleted class `Hyperf\JsonRpc\HttpServerFactory`, `Hyperf\HttpServer\ServerFactory`, `Hyperf\GrpcServer\ServerFactory`.
- [#402](https://github.com/hyperf-cloud/hyperf/pull/402) Deleted deprecated method `AsyncQueue::delay`.
## Fixed
- [#448](https://github.com/hyperf-cloud/hyperf/pull/448) Fixed TcpServer does not works, when has http or ws servers.
# v1.0.13 - TBD
# v1.0.12 - 2019-08-21

View File

@ -51,8 +51,9 @@ class Port
public static function build(array $config)
{
$config = self::filter($config);
$port = new static();
self::filter($config);
isset($config['name']) && $port->setName($config['name']);
isset($config['type']) && $port->setType($config['type']);
isset($config['host']) && $port->setHost($config['host']);
@ -140,13 +141,17 @@ class Port
return $this;
}
private static function filter(array &$config)
private static function filter(array $config): array
{
if ($config['type'] == ServerInterface::SERVER_TCP) {
$config['settings'] = array_replace($config['settings'] ?? [], [
$default = [
'open_http2_protocol' => false,
'open_http_protocol' => false,
]);
];
$config['settings'] = array_merge($default, $config['settings'] ?? []);
}
return $config;
}
}

View File

@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Server;
use Hyperf\Server\Port;
use Hyperf\Server\Server;
use PHPUnit\Framework\TestCase;
/**
* @internal
* @coversNothing
*/
class PortTest extends TestCase
{
public function testSetting()
{
$port = Port::build([
'name' => 'http',
'type' => Server::SERVER_HTTP,
]);
$this->assertSame([], $port->getSettings());
$port = Port::build([
'name' => 'tcp',
'type' => Server::SERVER_TCP,
]);
$this->assertSame([
'open_http2_protocol' => false,
'open_http_protocol' => false,
], $port->getSettings());
$port = Port::build([
'name' => 'tcp',
'type' => Server::SERVER_TCP,
'settings' => [
'open_http2_protocol' => true,
],
]);
$this->assertSame([
'open_http2_protocol' => true,
'open_http_protocol' => false,
], $port->getSettings());
}
}