Skip to content

Commit 65d53ea

Browse files
committed
Reorganized tests:
- Everything is within a "Test" namespace, eliminating pollution of auto-complete suggestions in IDEs - Persistent tests now require PHP >= 5.3.9 (in accordance with PEAR2_Cache_SHM) and are otherwise skipped - Connection tests are done for all connection types; Added Util::comment(); Adjusted Client::login() to consume the !done or !fatal response even when called on an already logged in connection; Adjusted the RouterOS settings file to add a 1 second delay after the DHCP client call, to ensure proper DNS resolutions down the script; Using ADH implicitly (without a context) will also explicitly set verify_peer to false, for compatibility with PHP 5.6+;
1 parent e16038b commit 65d53ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+702
-346
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
vendor/
1+
composer.phar
2+
vendor/

src/PEAR2/Net/RouterOS/Client.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,18 @@ private static function _login(
281281
)
282282
);
283283
$request->send($com);
284+
284285
$response = new Response($com, false, $timeout);
285-
return $response->getType() === Response::TYPE_FINAL
286-
&& null === $response->getProperty('ret');
286+
if ($response->getType() === Response::TYPE_FINAL) {
287+
return null === $response->getProperty('ret');
288+
} else {
289+
while ($response->getType() !== Response::TYPE_FINAL
290+
&& $response->getType() !== Response::TYPE_FATAL
291+
) {
292+
$response = new Response($com, false, $timeout);
293+
}
294+
return false;
295+
}
287296
}
288297

289298
/**

src/PEAR2/Net/RouterOS/Communicator.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,15 @@ public function __construct(
126126
if (!isset($opts['ssl']['ciphers'])
127127
|| 'DEFAULT' === $opts['ssl']['ciphers']
128128
) {
129-
stream_context_set_option($context, 'ssl', 'ciphers', 'ADH');
129+
stream_context_set_option(
130+
$context,
131+
array(
132+
'ssl' => array(
133+
'ciphers' => 'ADH',
134+
'verify_peer' => false
135+
)
136+
)
137+
);
130138
}
131139
}
132140
// @codeCoverageIgnoreStart

src/PEAR2/Net/RouterOS/Util.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,10 @@ public function find()
559559
$ret = $this->client->sendSync(
560560
new Request($this->menu . '/find')
561561
)->getProperty('ret');
562-
if (!is_string($ret)) {
562+
if (null === $ret) {
563+
$this->idCache = array();
564+
return '';
565+
} elseif (!is_string($ret)) {
563566
$ret = stream_get_contents($ret);
564567
}
565568

tests/Client/Safe.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace PEAR2\Net\RouterOS\Client\Test;
3+
namespace PEAR2\Net\RouterOS\Test\Client;
44

55
use PEAR2\Net\RouterOS\Client;
66
use PEAR2\Net\RouterOS\Communicator;

tests/Client/Safe/NonPersistent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace PEAR2\Net\RouterOS\Client\Test\Safe;
3+
namespace PEAR2\Net\RouterOS\Test\Client\Safe;
44

5-
use PEAR2\Net\RouterOS\Client\Test\Safe;
5+
use PEAR2\Net\RouterOS\Test\Client\Safe;
66

77
require_once __DIR__ . '/../Safe.php';
88

tests/Client/Safe/NonPersistent/EncryptedTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace PEAR2\Net\RouterOS\Client\Test\Safe\NonPersistent;
3+
namespace PEAR2\Net\RouterOS\Test\Client\Safe\NonPersistent;
44

55
use PEAR2\Net\RouterOS\Client;
6-
use PEAR2\Net\RouterOS\Client\Test\Safe\NonPersistent;
6+
use PEAR2\Net\RouterOS\Test\Client\Safe\NonPersistent;
77
use PEAR2\Net\Transmitter\NetworkStream;
88

99
require_once __DIR__ . '/../NonPersistent.php';
@@ -15,6 +15,8 @@
1515
* @group Safe
1616
* @group NonPersistent
1717
* @group Encrypted
18+
*
19+
* @requires extension openssl
1820
*
1921
* @category Net
2022
* @package PEAR2_Net_RouterOS

tests/Client/Safe/NonPersistent/UnencryptedTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace PEAR2\Net\RouterOS\Client\Test\Safe\NonPersistent;
3+
namespace PEAR2\Net\RouterOS\Test\Client\Safe\NonPersistent;
44

55
use PEAR2\Net\RouterOS\Client;
6-
use PEAR2\Net\RouterOS\Client\Test\Safe\NonPersistent;
6+
use PEAR2\Net\RouterOS\Test\Client\Safe\NonPersistent;
77

88
require_once __DIR__ . '/../NonPersistent.php';
99

tests/Client/Safe/Persistent.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace PEAR2\Net\RouterOS\Client\Test\Safe;
3+
namespace PEAR2\Net\RouterOS\Test\Client\Safe;
44

55
use PEAR2\Net\RouterOS\Client;
6-
use PEAR2\Net\RouterOS\Client\Test;
7-
use PEAR2\Net\RouterOS\Client\Test\Safe;
6+
use PEAR2\Net\RouterOS\Test\Client as Test;
7+
use PEAR2\Net\RouterOS\Test\Client\Safe;
88
use PEAR2\Net\RouterOS\Request;
99

1010
require_once __DIR__ . '/../Safe.php';

tests/Client/Safe/Persistent/EncryptedTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace PEAR2\Net\RouterOS\Client\Test\Safe\Persistent;
3+
namespace PEAR2\Net\RouterOS\Test\Client\Safe\Persistent;
44

55
use PEAR2\Net\RouterOS\Client;
6-
use PEAR2\Net\RouterOS\Client\Test\Safe\Persistent;
6+
use PEAR2\Net\RouterOS\Test\Client\Safe\Persistent;
77
use PEAR2\Net\Transmitter\NetworkStream;
88

99
require_once __DIR__ . '/../Persistent.php';
@@ -15,6 +15,9 @@
1515
* @group Safe
1616
* @group Persistent
1717
* @group Encrypted
18+
*
19+
* @requires extension openssl
20+
* @requires PHP 5.3.9
1821
*
1922
* @category Net
2023
* @package PEAR2_Net_RouterOS

0 commit comments

Comments
 (0)