|
2 | 2 |
|
3 | 3 | namespace Wrench\Tests;
|
4 | 4 |
|
| 5 | +use Wrench\Protocol\Protocol; |
| 6 | + |
5 | 7 | use Wrench\Client;
|
6 | 8 | use Wrench\Tests\Test;
|
7 | 9 | use Wrench\Socket;
|
@@ -105,4 +107,67 @@ public function testConstructorOriginInvalid()
|
105 | 107 | {
|
106 | 108 | $w = new Client('ws://localhost:8000', 'NOTAVALIDURI');
|
107 | 109 | }
|
| 110 | + |
| 111 | + /** |
| 112 | + * @expectedException InvalidArgumentException |
| 113 | + */ |
| 114 | + public function testSendInvalidType() |
| 115 | + { |
| 116 | + $client = new Client('ws://localhost/test', 'http://example.org/'); |
| 117 | + $client->sendData('blah', 9999); |
| 118 | + } |
| 119 | + |
| 120 | + /** |
| 121 | + * @expectedException InvalidArgumentException |
| 122 | + */ |
| 123 | + public function testSendInvalidTypeString() |
| 124 | + { |
| 125 | + $client = new Client('ws://localhost/test', 'http://example.org/'); |
| 126 | + $client->sendData('blah', 'fooey'); |
| 127 | + } |
| 128 | + |
| 129 | + public function testSend() |
| 130 | + { |
| 131 | + try { |
| 132 | + $helper = new ServerTestHelper(); |
| 133 | + $helper->setUp(); |
| 134 | + |
| 135 | + /* @var $instance Wrench\Client */ |
| 136 | + $instance = $this->getInstance($helper->getEchoConnectionString(), 'http://www.example.com/send'); |
| 137 | + $instance->addRequestHeader('X-Test', 'Custom Request Header'); |
| 138 | + |
| 139 | + $this->assertFalse($instance->receive(), 'Receive before connect'); |
| 140 | + |
| 141 | + $success = $instance->connect(); |
| 142 | + $this->assertTrue($success, 'Client can connect to test server'); |
| 143 | + $this->assertTrue($instance->isConnected()); |
| 144 | + |
| 145 | + $this->assertFalse($instance->connect(), 'Double connect'); |
| 146 | + |
| 147 | + $this->assertFalse((boolean)$instance->receive(), 'No data'); |
| 148 | + |
| 149 | + $bytes = $instance->sendData('foobar', 'text'); |
| 150 | + $this->assertTrue($bytes >= 6, 'sent text frame'); |
| 151 | + sleep(1); |
| 152 | + |
| 153 | + $bytes = $instance->sendData('baz', Protocol::TYPE_TEXT); |
| 154 | + $this->assertTrue($bytes >= 3, 'sent text frame'); |
| 155 | + sleep(1); |
| 156 | + |
| 157 | + $responses = $instance->receive(); |
| 158 | + $this->assertTrue(is_array($responses)); |
| 159 | + $this->assertCount(2, $responses); |
| 160 | + $this->assertInstanceOf('Wrench\\Payload\\Payload', $responses[0]); |
| 161 | + $this->assertInstanceOf('Wrench\\Payload\\Payload', $responses[1]); |
| 162 | + |
| 163 | + $instance->disconnect(); |
| 164 | + |
| 165 | + $this->assertFalse($instance->isConnected()); |
| 166 | + } catch (\Exception $e) { |
| 167 | + $helper->tearDown(); |
| 168 | + throw $e; |
| 169 | + } |
| 170 | + |
| 171 | + $helper->tearDown(); |
| 172 | + } |
108 | 173 | }
|
0 commit comments