-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
HttpServerCommandTest.phpt
98 lines (79 loc) · 2.39 KB
/
HttpServerCommandTest.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php declare(strict_types = 1);
namespace Tests\Cases;
use FastyBird\SocketServerFactory;
use FastyBird\WebServer\Commands;
use FastyBird\WebServer\Middleware;
use Mockery;
use Ninjify\Nunjuck\TestCase\BaseMockeryTestCase;
use Psr\EventDispatcher;
use Psr\Log;
use React\EventLoop;
use React\Promise;
use React\Socket;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Tester\Assert;
require_once __DIR__ . '/../../../bootstrap.php';
/**
* @testCase
*/
final class HttpServerCommandTest extends BaseMockeryTestCase
{
public function testExecute(): void
{
$promise = Mockery::mock(Promise\PromiseInterface::class);
$promise
->shouldReceive('then')
->andReturn($promise);
$logger = Mockery::mock(Log\LoggerInterface::class);
$logger
->shouldReceive('info')
->withArgs(['[FB:WEB_SERVER] Starting HTTP server'])
->times(1)
->getMock()
->shouldReceive('info')
->withArgs(['[FB:WEB_SERVER] Listening on "http://127.0.0.1:8001"'])
->times(1);
$eventLoop = Mockery::mock(EventLoop\LoopInterface::class);
$eventLoop
->shouldReceive('addReadStream')
->getMock()
->shouldReceive('run')
->withNoArgs();
$eventDispatcher = Mockery::mock(EventDispatcher\EventDispatcherInterface::class);
$eventDispatcher
->shouldReceive('dispatch')
->times(1);
$socketServer = Mockery::mock(Socket\ServerInterface::class);
$socketServer
->shouldReceive('getAddress')
->andReturn('http://127.0.0.1:8001')
->times(2)
->getMock()
->shouldReceive('on');
$socketServerFactory = Mockery::mock(SocketServerFactory\SocketServerFactory::class);
$socketServerFactory
->shouldReceive('create')
->andReturn($socketServer)
->times(1);
$corsFilesMiddleware = Mockery::mock(Middleware\CorsMiddleware::class);
$staticFilesMiddleware = Mockery::mock(Middleware\StaticFilesMiddleware::class);
$routerMiddleware = Mockery::mock(Middleware\RouterMiddleware::class);
$application = new Application();
$application->add(new Commands\HttpServerCommand(
$corsFilesMiddleware,
$staticFilesMiddleware,
$routerMiddleware,
$socketServerFactory,
$eventLoop,
$eventDispatcher,
$logger
));
$command = $application->get('fb:web-server:start');
$commandTester = new CommandTester($command);
$commandTester->execute([]);
Assert::true(true);
}
}
$test_case = new HttpServerCommandTest();
$test_case->run();