mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-30 02:37:58 +08:00
Added testing.
This commit is contained in:
parent
d641683bce
commit
3483eef500
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
57
src/server/tests/PortTest.php
Normal file
57
src/server/tests/PortTest.php
Normal 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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user