|
| 1 | +<?php |
| 2 | + |
| 3 | +use Socks\Server; |
| 4 | + |
| 5 | +class ServerApiTest extends TestCase |
| 6 | +{ |
| 7 | + /** @var Server */ |
| 8 | + private $server; |
| 9 | + |
| 10 | + public function setUp() |
| 11 | + { |
| 12 | + $socket = $this->getMockBuilder('React\Socket\Server') |
| 13 | + ->disableOriginalConstructor() |
| 14 | + ->getMock(); |
| 15 | + |
| 16 | + $loop = $this->getMockBuilder('React\EventLoop\StreamSelectLoop') |
| 17 | + ->disableOriginalConstructor() |
| 18 | + ->getMock(); |
| 19 | + |
| 20 | + $connector = $this->getMockBuilder('React\SocketClient\Connector') |
| 21 | + ->disableOriginalConstructor() |
| 22 | + ->getMock(); |
| 23 | + |
| 24 | + $this->server = new Server($socket, $loop, $connector); |
| 25 | + } |
| 26 | + |
| 27 | + public function testSetProtocolVersion() |
| 28 | + { |
| 29 | + $this->server->setProtocolVersion(4); |
| 30 | + $this->server->setProtocolVersion('4a'); |
| 31 | + $this->server->setProtocolVersion(5); |
| 32 | + $this->server->setProtocolVersion(null); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @expectedException InvalidArgumentException |
| 37 | + */ |
| 38 | + public function testSetInvalidProtocolVersion() |
| 39 | + { |
| 40 | + $this->server->setProtocolVersion(6); |
| 41 | + } |
| 42 | + |
| 43 | + public function testSetAuthArray() |
| 44 | + { |
| 45 | + $this->server->setAuthArray(array()); |
| 46 | + |
| 47 | + $this->server->setAuthArray(array( |
| 48 | + 'name1' => 'password1', |
| 49 | + 'name2' => 'password2' |
| 50 | + )); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @expectedException InvalidArgumentException |
| 55 | + */ |
| 56 | + public function testSetAuthInvalid() |
| 57 | + { |
| 58 | + $this->server->setAuth(true); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @expectedException UnexpectedValueException |
| 63 | + */ |
| 64 | + public function testUnableToSetAuthIfProtocolDoesNotSupportAuth() |
| 65 | + { |
| 66 | + $this->server->setProtocolVersion(4); |
| 67 | + |
| 68 | + $this->server->setAuthArray(array()); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @expectedException UnexpectedValueException |
| 73 | + */ |
| 74 | + public function testUnableToSetProtocolWhichDoesNotSupportAuth() |
| 75 | + { |
| 76 | + $this->server->setAuthArray(array()); |
| 77 | + |
| 78 | + // this is okay |
| 79 | + $this->server->setProtocolVersion(5); |
| 80 | + |
| 81 | + $this->server->setProtocolVersion(4); |
| 82 | + } |
| 83 | + |
| 84 | + public function testUnsetAuth() |
| 85 | + { |
| 86 | + $this->server->unsetAuth(); |
| 87 | + $this->server->unsetAuth(); |
| 88 | + } |
| 89 | +} |
0 commit comments