Ejemplo n.º 1
0
 /**
  * Test the connect, send, receive method
  */
 public function testConnect()
 {
     try {
         $helper = new ServerTestHelper();
         $helper->setUp();
         $instance = $this->getInstance($helper->getConnectionString());
         $success = $instance->connect();
         $this->assertTrue($success, 'Client socket can connect to test server');
         $sent = $instance->send("GET /echo HTTP/1.1\r\nHost: localhost\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://localhost\r\nSec-WebSocket-Version: 13\r\n\r\n");
         $this->assertNotEquals(false, $sent, 'Client socket can send to test server');
         $response = $instance->receive();
         $this->assertStringStartsWith('HTTP', $response, 'Response looks like HTTP handshake response');
     } catch (\Exception $e) {
         $helper->tearDown();
         throw $e;
     }
     $helper->tearDown();
 }
Ejemplo n.º 2
0
 public function testSend()
 {
     try {
         $helper = new ServerTestHelper();
         $helper->setUp();
         /* @var $instance Wrench\Client */
         $instance = $this->getInstance($helper->getEchoConnectionString(), 'http://www.example.com/send');
         $instance->addRequestHeader('X-Test', 'Custom Request Header');
         $this->assertFalse($instance->receive(), 'Receive before connect');
         $success = $instance->connect();
         $this->assertTrue($success, 'Client can connect to test server');
         $this->assertTrue($instance->isConnected());
         $this->assertFalse($instance->connect(), 'Double connect');
         $this->assertFalse((bool) $instance->receive(), 'No data');
         $bytes = $instance->sendData('foobar', 'text');
         $this->assertTrue($bytes >= 6, 'sent text frame');
         sleep(1);
         $bytes = $instance->sendData('baz', Protocol::TYPE_TEXT);
         $this->assertTrue($bytes >= 3, 'sent text frame');
         sleep(1);
         $responses = $instance->receive();
         $this->assertTrue(is_array($responses));
         $this->assertCount(2, $responses);
         $this->assertInstanceOf('Wrench\\Payload\\Payload', $responses[0]);
         $this->assertInstanceOf('Wrench\\Payload\\Payload', $responses[1]);
         $bytes = $instance->sendData('baz', Protocol::TYPE_TEXT);
         $this->assertTrue($bytes >= 3, 'sent text frame');
         sleep(1);
         # test fix for issue #43
         $responses = $instance->receive();
         $this->assertTrue(is_array($responses));
         $this->assertCount(1, $responses);
         $this->assertInstanceOf('Wrench\\Payload\\Payload', $responses[2]);
         $instance->disconnect();
         $this->assertFalse($instance->isConnected());
     } catch (\Exception $e) {
         $helper->tearDown();
         throw $e;
     }
     $helper->tearDown();
 }