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(); }