コード例 #1
0
ファイル: ServerTest.php プロジェクト: phpixie/illusion
 public function testServer()
 {
     $pid = pcntl_fork();
     if ($pid == 0) {
         socket_close($this->input[0]);
         socket_close($this->output[0]);
         $input = new \PHPixie\Illusion\Socket($this->input[1]);
         $output = new \PHPixie\Illusion\Socket($this->output[1]);
         $server = new \PHPixie\Illusion\Server(4747, 'localhost', $input, $output);
         $server->run();
     } else {
         socket_close($this->input[1]);
         socket_close($this->output[1]);
         $input = new \PHPixie\Illusion\Socket($this->input[0]);
         $output = new \PHPixie\Illusion\Socket($this->output[0]);
         $message = array('action' => 'route', 'method' => 'GET', 'headers' => array('Content-Type: text/plain'), 'path' => '/hello', 'response' => 'world');
         $input->write($message);
         $url = 'http://localhost:4747/hello';
         $response = $output->read(true);
         $this->assertEquals(array(array('url' => $url)), $response);
         $contents = file_get_contents($url);
         $this->assertEquals('world', $contents);
         $input->write(array('action' => 'stop'));
         sleep(2);
     }
 }
コード例 #2
0
ファイル: SocketTest.php プロジェクト: phpixie/illusion
 public function testMessages()
 {
     $data = array('test' => 5);
     $pid = pcntl_fork();
     if ($pid === 0) {
         socket_close($this->sockets[0]);
         $socket = new \PHPixie\Illusion\Socket($this->sockets[1]);
         $socket->write($data);
         die;
     } else {
         socket_close($this->sockets[1]);
         $socket = new \PHPixie\Illusion\Socket($this->sockets[0]);
         $this->assertEquals(array($data), $socket->read());
     }
 }