Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added letter time notation support to Util::parseValue();
Added a preliminary changelog; Altered the Packer template to support newer RouterOS versions; Moved some Communicator tests into a new test folder.
- Loading branch information
Showing
22 changed files
with
636 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Bug fixes, mostly. | ||
|
||
* New Util methods: | ||
- newRequest() | ||
- comment() | ||
* Util::parseValue() now supports letter notation for time (1h2m3s), not just double colon notation (01:02:03), modeled after RouterOS. Related to that is also that leading zeroes, and zero minutes and seconds are now optional (e.g. "1:" is a valid way of saying 1 hour). Sub-second information is rounded up to the nearest second on current PHP versions (future versions are expected to support sub-second information in DateInterval by allowing seconds to be a double; The code currently attempts to give DateInterval a double, falling back to rounding to a second). | ||
* Client::login() consumes the !done or !fatal response even when called on an already logged in connection. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace PEAR2\Net\RouterOS\Test\Communicator; | ||
|
||
use PEAR2\Net\RouterOS\Communicator; | ||
use PEAR2\Net\RouterOS\Request; | ||
use PEAR2\Net\RouterOS\Response; | ||
use PEAR2\Net\RouterOS\Query; | ||
use PEAR2\Net\RouterOS\InvalidArgumentException; | ||
use PEAR2\Net\RouterOS\SocketException; | ||
use PHPUnit_Framework_TestCase; | ||
|
||
abstract class Safe extends PHPUnit_Framework_TestCase | ||
{ | ||
|
||
/** | ||
* @var Communicator | ||
*/ | ||
protected $object; | ||
|
||
public function testNonSeekableCommunicatorWord() | ||
{ | ||
$value = fopen('php://output', 'a'); | ||
try { | ||
$this->object->sendWordFromStream('', $value); | ||
$this->fail('Call had to fail.'); | ||
} catch (InvalidArgumentException $e) { | ||
$this->assertEquals( | ||
InvalidArgumentException::CODE_SEEKABLE_REQUIRED, | ||
$e->getCode(), | ||
'Improper exception code.' | ||
); | ||
} | ||
} | ||
|
||
public function testInvokability() | ||
{ | ||
$com = $this->object; | ||
$request = new Request('/ping'); | ||
$request('address', HOSTNAME)->setTag('p'); | ||
$this->assertEquals(HOSTNAME, $request('address')); | ||
$this->assertEquals('p', $request->getTag()); | ||
$this->assertEquals('p', $request()); | ||
$request($com); | ||
$response = new Response( | ||
$com, | ||
false, | ||
ini_get('default_socket_timeout') | ||
); | ||
$this->assertInternalType('string', $response()); | ||
$this->assertEquals(HOSTNAME, $response('host')); | ||
|
||
$request = new Request('/queue/simple/print'); | ||
$query = Query::where('target', HOSTNAME_INVALID . '/32'); | ||
$request($query); | ||
$this->assertSame($query, $request->getQuery()); | ||
$com('/log/print'); | ||
$com(''); | ||
} | ||
|
||
public function testInvalidSocketOnReceive() | ||
{ | ||
try { | ||
new Response($this->object); | ||
$this->fail('Receiving had to fail.'); | ||
} catch (SocketException $e) { | ||
$this->assertEquals( | ||
SocketException::CODE_NO_DATA, | ||
$e->getCode(), | ||
'Improper exception code.' | ||
); | ||
} | ||
} | ||
|
||
public function testInvalidSocketOnStreamReceive() | ||
{ | ||
try { | ||
$response = new Response($this->object, true); | ||
$this->fail('Receiving had to fail.'); | ||
} catch (SocketException $e) { | ||
$this->assertEquals( | ||
SocketException::CODE_NO_DATA, | ||
$e->getCode(), | ||
'Improper exception code.' | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace PEAR2\Net\RouterOS\Test\Communicator\Safe; | ||
|
||
use PEAR2\Net\RouterOS\Test\Communicator\Safe; | ||
|
||
require_once __DIR__ . '/../Safe.php'; | ||
|
||
abstract class NonPersistent extends Safe | ||
{ | ||
protected function tearDown() | ||
{ | ||
unset($this->object); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace PEAR2\Net\RouterOS\Test\Communicator\Safe\NonPersistent; | ||
|
||
use PEAR2\Net\RouterOS\Client; | ||
use PEAR2\Net\RouterOS\Communicator; | ||
use PEAR2\Net\RouterOS\Test\Communicator\Safe\NonPersistent; | ||
use PEAR2\Net\Transmitter\NetworkStream; | ||
|
||
require_once __DIR__ . '/../NonPersistent.php'; | ||
|
||
/** | ||
* ~ | ||
* | ||
* @group Communicator | ||
* @group Safe | ||
* @group NonPersistent | ||
* @group Encrypted | ||
* | ||
* @requires extension openssl | ||
* | ||
* @category Net | ||
* @package PEAR2_Net_RouterOS | ||
* @author Vasil Rangelov <boen.robot@gmail.com> | ||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 | ||
* @link http://pear2.php.net/PEAR2_Net_RouterOS | ||
*/ | ||
class EncryptedTest extends NonPersistent | ||
{ | ||
protected function setUp() | ||
{ | ||
$this->object = new Communicator( | ||
\HOSTNAME, | ||
ENC_PORT, | ||
false, | ||
null, | ||
NetworkStream::CRYPTO_TLS | ||
); | ||
Client::login($this->object, USERNAME, PASSWORD); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace PEAR2\Net\RouterOS\Test\Communicator\Safe\NonPersistent; | ||
|
||
use PEAR2\Net\RouterOS\Client; | ||
use PEAR2\Net\RouterOS\Communicator; | ||
use PEAR2\Net\RouterOS\Test\Communicator\Safe\NonPersistent; | ||
|
||
require_once __DIR__ . '/../NonPersistent.php'; | ||
|
||
/** | ||
* ~ | ||
* | ||
* @group Communicator | ||
* @group Safe | ||
* @group NonPersistent | ||
* @group Unencrypted | ||
* | ||
* @category Net | ||
* @package PEAR2_Net_RouterOS | ||
* @author Vasil Rangelov <boen.robot@gmail.com> | ||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 | ||
* @link http://pear2.php.net/PEAR2_Net_RouterOS | ||
*/ | ||
class UnencryptedTest extends NonPersistent | ||
{ | ||
protected function setUp() | ||
{ | ||
$this->object = new Communicator(\HOSTNAME, PORT); | ||
Client::login($this->object, USERNAME, PASSWORD); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace PEAR2\Net\RouterOS\Test\Communicator\Safe; | ||
|
||
use PEAR2\Net\RouterOS\Test\Communicator\Safe; | ||
|
||
require_once __DIR__ . '/../Safe.php'; | ||
|
||
abstract class Persistent extends Safe | ||
{ | ||
|
||
protected function tearDown() | ||
{ | ||
$this->object->close(); | ||
unset($this->object); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace PEAR2\Net\RouterOS\Test\Communicator\Safe\Persistent; | ||
|
||
use PEAR2\Net\RouterOS\Client; | ||
use PEAR2\Net\RouterOS\Communicator; | ||
use PEAR2\Net\RouterOS\Test\Communicator\Safe\Persistent; | ||
use PEAR2\Net\Transmitter\NetworkStream; | ||
|
||
require_once __DIR__ . '/../Persistent.php'; | ||
|
||
/** | ||
* ~ | ||
* | ||
* @group Communicator | ||
* @group Safe | ||
* @group Persistent | ||
* @group Encrypted | ||
* | ||
* @requires extension openssl | ||
* @requires PHP 5.3.9 | ||
* | ||
* @category Net | ||
* @package PEAR2_Net_RouterOS | ||
* @author Vasil Rangelov <boen.robot@gmail.com> | ||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 | ||
* @link http://pear2.php.net/PEAR2_Net_RouterOS | ||
*/ | ||
class EncryptedTest extends Persistent | ||
{ | ||
protected function setUp() | ||
{ | ||
$this->object = new Communicator( | ||
\HOSTNAME, | ||
ENC_PORT, | ||
true, | ||
null, | ||
NetworkStream::CRYPTO_TLS | ||
); | ||
Client::login($this->object, USERNAME, PASSWORD); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace PEAR2\Net\RouterOS\Test\Communicator\Safe\Persistent; | ||
|
||
use PEAR2\Net\RouterOS\Client; | ||
use PEAR2\Net\RouterOS\Communicator; | ||
use PEAR2\Net\RouterOS\Test\Communicator\Safe\Persistent; | ||
|
||
require_once __DIR__ . '/../Persistent.php'; | ||
|
||
/** | ||
* ~ | ||
* | ||
* @group Communicator | ||
* @group Safe | ||
* @group Persistent | ||
* @group Unencrypted | ||
* | ||
* @requires PHP 5.3.9 | ||
* | ||
* @category Net | ||
* @package PEAR2_Net_RouterOS | ||
* @author Vasil Rangelov <boen.robot@gmail.com> | ||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 | ||
* @link http://pear2.php.net/PEAR2_Net_RouterOS | ||
*/ | ||
class UnencryptedTest extends Persistent | ||
{ | ||
protected function setUp() | ||
{ | ||
$this->object = new Communicator(\HOSTNAME, PORT, true); | ||
Client::login($this->object, USERNAME, PASSWORD); | ||
} | ||
} |
Oops, something went wrong.