File tree Expand file tree Collapse file tree 2 files changed +90
-0
lines changed
Expand file tree Collapse file tree 2 files changed +90
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace PHPFastCGI \Test \FastCGIDaemon \ConnectionHandler ;
4+
5+ use PHPFastCGI \FastCGIDaemon \ConnectionHandler \ConnectionHandlerFactory ;
6+
7+ /**
8+ * Tests the daemon.
9+ */
10+ class ConnectionHandlerFactoryTest extends \PHPUnit_Framework_TestCase
11+ {
12+ /**
13+ * Tests that the factory creates a connection handler from a kernel
14+ */
15+ public function testCreatesConnectionHandlerFromKernel ()
16+ {
17+ $ kernel = $ this
18+ ->getMockBuilder ('PHPFastCGI \\FastCGIDaemon \\KernelInterface ' )
19+ ->getMock ();
20+
21+ $ connectionHandlerFactory = new ConnectionHandlerFactory ($ kernel );
22+
23+ $ connection = $ this
24+ ->getMockBuilder ('PHPFastCGI \\FastCGIDaemon \\Connection \\StreamSocketConnection ' )
25+ ->disableOriginalConstructor ()
26+ ->getMock ();
27+
28+ $ connectionHandler = $ connectionHandlerFactory ->createConnectionHandler ($ connection );
29+
30+ $ this ->assertInstanceOf ('PHPFastCGI \\FastCGIDaemon \\ConnectionHandler \\ConnectionHandler ' , $ connectionHandler );
31+ }
32+
33+ /**
34+ * Tests that the factory creates a connection handler from a closure
35+ */
36+ public function testCreatesConnectionHandlerFromClosure ()
37+ {
38+ $ connectionHandlerFactory = new ConnectionHandlerFactory (function () { });
39+
40+ $ connection = $ this
41+ ->getMockBuilder ('PHPFastCGI \\FastCGIDaemon \\Connection \\StreamSocketConnection ' )
42+ ->disableOriginalConstructor ()
43+ ->getMock ();
44+
45+ $ connectionHandler = $ connectionHandlerFactory ->createConnectionHandler ($ connection );
46+
47+ $ this ->assertInstanceOf ('PHPFastCGI \\FastCGIDaemon \\ConnectionHandler \\ConnectionHandler ' , $ connectionHandler );
48+ }
49+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace PHPFastCGI \Test \FastCGIDaemon ;
4+
5+ use PHPFastCGI \FastCGIDaemon \Daemon ;
6+
7+ /**
8+ * Tests the daemon.
9+ */
10+ class DaemonTest extends \PHPUnit_Framework_TestCase
11+ {
12+ /**
13+ * Tests that the daemon runs a connection pool with a handler factory.
14+ */
15+ public function testRun ()
16+ {
17+ $ mockConnectionHandlerFactory = $ this
18+ ->getMockBuilder ('PHPFastCGI \\FastCGIDaemon \\ConnectionHandler \\ConnectionHandlerFactory ' )
19+ ->disableOriginalConstructor ()
20+ ->setMethods (['setLogger ' ])
21+ ->getMock ();
22+
23+ $ mockConnectionHandlerFactory
24+ ->expects ($ this ->once ())
25+ ->method ('setLogger ' );
26+
27+ $ mockConnectionPool = $ this
28+ ->getMockBuilder ('PHPFastCGI \\FastCGIDaemon \\Connection \\StreamSocketConnectionPool ' )
29+ ->disableOriginalConstructor ()
30+ ->setMethods (['operate ' ])
31+ ->getMock ();
32+
33+ $ mockConnectionPool
34+ ->expects ($ this ->once ())
35+ ->method ('operate ' )
36+ ->with ($ this ->equalTo ($ mockConnectionHandlerFactory ), $ this ->equalTo (5 ));
37+
38+ $ daemon = new Daemon ($ mockConnectionPool , $ mockConnectionHandlerFactory );
39+ $ daemon ->run ();
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments