|
5 | 5 | use DateInterval;
|
6 | 6 | use DateTime;
|
7 | 7 | use DateTimeZone;
|
| 8 | +use PEAR2\Net\RouterOS\Client; |
8 | 9 | use PEAR2\Net\RouterOS\Communicator;
|
9 | 10 | use PEAR2\Net\RouterOS\InvalidArgumentException;
|
10 | 11 | use PEAR2\Net\RouterOS\LengthException;
|
11 | 12 | use PEAR2\Net\RouterOS\NotSupportedException;
|
12 | 13 | use PEAR2\Net\RouterOS\Query;
|
13 | 14 | use PEAR2\Net\RouterOS\Request;
|
| 15 | +use PEAR2\Net\RouterOS\Response; |
14 | 16 | use PEAR2\Net\RouterOS\Script;
|
15 | 17 | use PEAR2\Net\RouterOS\UnexpectedValueException;
|
16 | 18 | use PEAR2\Net\Transmitter as T;
|
@@ -946,6 +948,66 @@ public function providerControlByte()
|
946 | 948 | );
|
947 | 949 | }
|
948 | 950 |
|
| 951 | + public function testInvalidResponseType() |
| 952 | + { |
| 953 | + $transMock = $this->createMock('PEAR2\Net\Transmitter\TcpClient'); |
| 954 | + $transMock->method('isPersistent')->will( |
| 955 | + $this->onConsecutiveCalls(false, true) |
| 956 | + ); |
| 957 | + $transMock->method('isAvailable')->willReturn(true); |
| 958 | + $transMock->method('isDataAwaiting')->willReturn(true); |
| 959 | + |
| 960 | + $comMock = $this->createMock(ROS_NAMESPACE . '\Communicator'); |
| 961 | + $comMock->method('getTransmitter')->willReturn($transMock); |
| 962 | + $comMock->method('getNextWord')->willReturn('TEST'); |
| 963 | + |
| 964 | + //Non persistent connection |
| 965 | + try { |
| 966 | + new Response($comMock); |
| 967 | + $this->fail('Getting unknown types should throw an exception.'); |
| 968 | + } catch (UnexpectedValueException $e) { |
| 969 | + $this->assertSame( |
| 970 | + UnexpectedValueException::CODE_RESPONSE_TYPE_UNKNOWN, |
| 971 | + $e->getCode() |
| 972 | + ); |
| 973 | + } |
| 974 | + |
| 975 | + //Persistent connection |
| 976 | + try { |
| 977 | + new Response($comMock); |
| 978 | + $this->fail('Getting unknown types should throw an exception.'); |
| 979 | + } catch (UnexpectedValueException $e) { |
| 980 | + $this->assertSame( |
| 981 | + UnexpectedValueException::CODE_RESPONSE_TYPE_UNKNOWN, |
| 982 | + $e->getCode() |
| 983 | + ); |
| 984 | + } |
| 985 | + } |
| 986 | + |
| 987 | + public function testUnexpectedLoginException() |
| 988 | + { |
| 989 | + $newLockException = new T\LockException('TEST'); |
| 990 | + $transMock = $this->createMock('PEAR2\Net\Transmitter\TcpClient'); |
| 991 | + $transMock->method('isPersistent')->willReturn(true); |
| 992 | + $transMock->method('isAvailable')->willReturn(true); |
| 993 | + $transMock->method('isDataAwaiting')->willReturn(true); |
| 994 | + $transMock->method('lock')->will( |
| 995 | + $this->throwException($newLockException) |
| 996 | + ); |
| 997 | + |
| 998 | + $comMock = $this->createMock(ROS_NAMESPACE . '\Communicator'); |
| 999 | + $comMock->method('getTransmitter')->willReturn($transMock); |
| 1000 | + |
| 1001 | + try { |
| 1002 | + Client::login($comMock, 'TEST', 'TEST'); |
| 1003 | + $this->fail( |
| 1004 | + 'Unexpected exceptions during login should be re-thrown' |
| 1005 | + ); |
| 1006 | + } catch (T\LockException $e) { |
| 1007 | + $this->assertSame($e, $newLockException); |
| 1008 | + } |
| 1009 | + } |
| 1010 | + |
949 | 1011 | public function testPrepareScript()
|
950 | 1012 | {
|
951 | 1013 | $msg = 'testing';
|
|
0 commit comments