Browse Source

Tests code finetune after code styles fix

tags/1.3.1
Paul Rock 6 years ago
parent
commit
a40a0b4251
  1. 2
      tests/APIConnectorTest.php
  2. 3
      tests/APILengthCoDecTest.php
  3. 10
      tests/ClientTest.php
  4. 9
      tests/ConfigTest.php
  5. 5
      tests/Helpers/BinaryStringHelperTest.php
  6. 30
      tests/Laravel/ServiceProviderTests.php
  7. 4
      tests/Laravel/TestCase.php
  8. 23
      tests/QueryTest.php
  9. 1
      tests/ResponseIteratorTest.php
  10. 13
      tests/Streams/ResourceStreamTest.php
  11. 14
      tests/Streams/StringStreamTest.php

2
tests/APIConnectorTest.php

@ -37,7 +37,7 @@ class APIConnectorTest extends TestCase
public function constructProvider(): array public function constructProvider(): array
{ {
return [ return [
[new ResourceStream(fopen(__FILE__, 'rb')),], // Myself, sure I exists
[new ResourceStream(fopen(__FILE__, 'rb'))], // Myself, sure I exists
[new ResourceStream(fsockopen('tcp://' . getenv('ROS_HOST'), getenv('ROS_PORT_MODERN')))], // Socket [new ResourceStream(fsockopen('tcp://' . getenv('ROS_HOST'), getenv('ROS_PORT_MODERN')))], // Socket
[new ResourceStream(STDIN), false], // Try it, but do not close STDIN please !!! [new ResourceStream(STDIN), false], // Try it, but do not close STDIN please !!!
[new StringStream('Hello World !!!')], // Try it, but do not close STDIN please !!! [new StringStream('Hello World !!!')], // Try it, but do not close STDIN please !!!

3
tests/APILengthCoDecTest.php

@ -7,6 +7,7 @@ use PHPUnit\Framework\TestCase;
use RouterOS\APILengthCoDec; use RouterOS\APILengthCoDec;
use RouterOS\Streams\StringStream; use RouterOS\Streams\StringStream;
use RouterOS\Helpers\BinaryStringHelper; use RouterOS\Helpers\BinaryStringHelper;
use UnexpectedValueException;
/** /**
* Limit code coverage to the class * Limit code coverage to the class
@ -99,7 +100,7 @@ class APILengthCoDecTest extends TestCase
*/ */
public function testDecodeLengthControlWord(string $encodedLength): void public function testDecodeLengthControlWord(string $encodedLength): void
{ {
$this->expectException(\UnexpectedValueException::class);
$this->expectException(UnexpectedValueException::class);
APILengthCoDec::decodeLength(new StringStream($encodedLength)); APILengthCoDec::decodeLength(new StringStream($encodedLength));
} }

10
tests/ClientTest.php

@ -122,7 +122,7 @@ class ClientTest extends TestCase
'pass' => $this->config['pass'], 'pass' => $this->config['pass'],
'host' => $this->config['host'], 'host' => $this->config['host'],
'port' => $this->port_legacy, 'port' => $this->port_legacy,
'legacy' => true
'legacy' => true,
]); ]);
$this->assertIsObject($obj); $this->assertIsObject($obj);
} catch (Exception $e) { } catch (Exception $e) {
@ -143,7 +143,7 @@ class ClientTest extends TestCase
'pass' => $this->config['pass'], 'pass' => $this->config['pass'],
'host' => $this->config['host'], 'host' => $this->config['host'],
'port' => $this->port_legacy, 'port' => $this->port_legacy,
'legacy' => false
'legacy' => false,
]); ]);
$this->assertIsObject($obj); $this->assertIsObject($obj);
} catch (Exception $e) { } catch (Exception $e) {
@ -159,7 +159,7 @@ class ClientTest extends TestCase
'user' => $this->config['user'], 'user' => $this->config['user'],
'pass' => 'admin2', 'pass' => 'admin2',
'host' => $this->config['host'], 'host' => $this->config['host'],
'attempts' => 2
'attempts' => 2,
]); ]);
} }
@ -172,7 +172,7 @@ class ClientTest extends TestCase
'pass' => $this->config['pass'], 'pass' => $this->config['pass'],
'host' => $this->config['host'], 'host' => $this->config['host'],
'port' => 11111, 'port' => 11111,
'attempts' => 2
'attempts' => 2,
]); ]);
} }
@ -206,7 +206,7 @@ class ClientTest extends TestCase
$read = $this->client->query('/interface/print', [ $read = $this->client->query('/interface/print', [
['type', 'ether'], ['type', 'ether'],
['type', 'vlan']
['type', 'vlan'],
], '|')->read(); ], '|')->read();
$this->assertCount(1, $read); $this->assertCount(1, $read);
$this->assertEquals('*1', $read[0]['.id']); $this->assertEquals('*1', $read[0]['.id']);

9
tests/ConfigTest.php

@ -2,6 +2,7 @@
namespace RouterOS\Tests; namespace RouterOS\Tests;
use Exception;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use RouterOS\Config; use RouterOS\Config;
use RouterOS\Exceptions\ConfigException; use RouterOS\Exceptions\ConfigException;
@ -13,7 +14,7 @@ class ConfigTest extends TestCase
try { try {
$obj = new Config(); $obj = new Config();
$this->assertIsObject($obj); $this->assertIsObject($obj);
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertStringContainsString('Must be initialized ', $e->getMessage()); $this->assertStringContainsString('Must be initialized ', $e->getMessage());
} }
} }
@ -23,7 +24,7 @@ class ConfigTest extends TestCase
$obj = new Config(); $obj = new Config();
$params = $obj->getParameters(); $params = $obj->getParameters();
$this->assertCount(6, $params);
$this->assertCount(7, $params);
$this->assertEquals(false, $params['legacy']); $this->assertEquals(false, $params['legacy']);
$this->assertEquals(false, $params['ssl']); $this->assertEquals(false, $params['ssl']);
$this->assertEquals(10, $params['timeout']); $this->assertEquals(10, $params['timeout']);
@ -36,7 +37,7 @@ class ConfigTest extends TestCase
$obj = new Config(['timeout' => 100]); $obj = new Config(['timeout' => 100]);
$params = $obj->getParameters(); $params = $obj->getParameters();
$this->assertCount(6, $params);
$this->assertCount(7, $params);
$this->assertEquals(100, $params['timeout']); $this->assertEquals(100, $params['timeout']);
} }
@ -52,7 +53,7 @@ class ConfigTest extends TestCase
public function testSetArr(): void public function testSetArr(): void
{ {
$obj = new Config([ $obj = new Config([
'timeout' => 111
'timeout' => 111,
]); ]);
$params = $obj->getParameters(); $params = $obj->getParameters();

5
tests/Helpers/BinaryStringHelperTest.php

@ -3,7 +3,6 @@
namespace RouterOS\Tests\Helpers; namespace RouterOS\Tests\Helpers;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use RouterOS\Helpers\BinaryStringHelper; use RouterOS\Helpers\BinaryStringHelper;
/** /**
@ -33,8 +32,8 @@ class BinaryStringHelperTest extends TestCase
// strange behaviour : // strange behaviour :
// TypeError: Argument 1 passed to RouterOS\Tests\Helpers\BinaryStringHelperTest::test__IntegerToNBOBinaryString() must be of the type integer, float given // TypeError: Argument 1 passed to RouterOS\Tests\Helpers\BinaryStringHelperTest::test__IntegerToNBOBinaryString() must be of the type integer, float given
// Seems that php auto convert to float 0xFFF....
//
// Seems that php auto convert to float 0xFFF....
//
// [0xFFFFFFFFFFFFFFFF, chr(0xFF).chr(0xFF).chr(0xFF).chr(0xFF).chr(0xFF).chr(0xFF).chr(0xFF).chr(0xFF)], // [0xFFFFFFFFFFFFFFFF, chr(0xFF).chr(0xFF).chr(0xFF).chr(0xFF).chr(0xFF).chr(0xFF).chr(0xFF).chr(0xFF)],
// Let's try random value // Let's try random value

30
tests/Laravel/ServiceProviderTests.php

@ -8,19 +8,19 @@ use RouterOS\Laravel\Wrapper;
class ServiceProviderTests extends TestCase class ServiceProviderTests extends TestCase
{ {
private $client = [ private $client = [
"__construct",
"query",
"read",
"readAsIterator",
"parseResponse",
"connect",
"export",
"getSocket",
"q",
"r",
"ri",
"qr",
"qri",
'__construct',
'query',
'read',
'readAsIterator',
'parseResponse',
'connect',
'export',
'getSocket',
'q',
'r',
'ri',
'qr',
'qri',
]; ];
public function testAbstractsAreLoaded(): void public function testAbstractsAreLoaded(): void
@ -34,7 +34,7 @@ class ServiceProviderTests extends TestCase
$config = \RouterOS::config([ $config = \RouterOS::config([
'host' => '192.168.1.3', 'host' => '192.168.1.3',
'user' => 'admin', 'user' => 'admin',
'pass' => 'admin'
'pass' => 'admin',
]); ]);
$this->assertInstanceOf(Config::class, $config); $this->assertInstanceOf(Config::class, $config);
@ -54,7 +54,7 @@ class ServiceProviderTests extends TestCase
$client = \RouterOS::client([ $client = \RouterOS::client([
'host' => '192.168.1.3', 'host' => '192.168.1.3',
'user' => 'admin', 'user' => 'admin',
'pass' => 'admin'
'pass' => 'admin',
], false); ], false);
$this->assertEquals(get_class_methods($client), $this->client); $this->assertEquals(get_class_methods($client), $this->client);

4
tests/Laravel/TestCase.php

@ -14,7 +14,7 @@ use Orchestra\Testbench\TestCase as Orchestra;
abstract class TestCase extends Orchestra abstract class TestCase extends Orchestra
{ {
/** /**
* @inheritdoc
* {@inheritdoc}
*/ */
protected function getPackageProviders($app): array protected function getPackageProviders($app): array
{ {
@ -24,7 +24,7 @@ abstract class TestCase extends Orchestra
} }
/** /**
* @inheritdoc
* {@inheritdoc}
*/ */
protected function getPackageAliases($app): array protected function getPackageAliases($app): array
{ {

23
tests/QueryTest.php

@ -2,6 +2,7 @@
namespace RouterOS\Tests; namespace RouterOS\Tests;
use Exception;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use RouterOS\Exceptions\QueryException; use RouterOS\Exceptions\QueryException;
use RouterOS\Query; use RouterOS\Query;
@ -13,7 +14,7 @@ class QueryTest extends TestCase
try { try {
$obj = new Query('test'); $obj = new Query('test');
$this->assertIsObject($obj); $this->assertIsObject($obj);
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertStringContainsString('Must be initialized ', $e->getMessage()); $this->assertStringContainsString('Must be initialized ', $e->getMessage());
} }
} }
@ -23,7 +24,7 @@ class QueryTest extends TestCase
try { try {
$obj = new Query('test', ['line1', 'line2', 'line3']); $obj = new Query('test', ['line1', 'line2', 'line3']);
$this->assertIsObject($obj); $this->assertIsObject($obj);
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertStringContainsString('Must be initialized ', $e->getMessage()); $this->assertStringContainsString('Must be initialized ', $e->getMessage());
} }
} }
@ -33,7 +34,7 @@ class QueryTest extends TestCase
try { try {
$obj = new Query(['test', 'line1', 'line2', 'line3']); $obj = new Query(['test', 'line1', 'line2', 'line3']);
$this->assertIsObject($obj); $this->assertIsObject($obj);
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertStringContainsString('Must be initialized ', $e->getMessage()); $this->assertStringContainsString('Must be initialized ', $e->getMessage());
} }
} }
@ -57,7 +58,7 @@ class QueryTest extends TestCase
$this->expectException(QueryException::class); $this->expectException(QueryException::class);
$obj = new Query(null); $obj = new Query(null);
$test = $obj->getEndpoint();
$obj->getEndpoint();
} }
public function testSetEndpoint(): void public function testSetEndpoint(): void
@ -90,7 +91,7 @@ class QueryTest extends TestCase
$attrs = $obj->getAttributes(); $attrs = $obj->getAttributes();
$this->assertCount(1, $attrs); $this->assertCount(1, $attrs);
$this->assertEquals($attrs[0], 'line');
$this->assertEquals('line', $attrs[0]);
} }
public function testWhere(): void public function testWhere(): void
@ -101,7 +102,7 @@ class QueryTest extends TestCase
$attrs = $obj->getAttributes(); $attrs = $obj->getAttributes();
$this->assertCount(2, $attrs); $this->assertCount(2, $attrs);
$this->assertEquals($attrs[1], '?key2=value2');
$this->assertEquals('?key2=value2', $attrs[1]);
} }
@ -113,7 +114,7 @@ class QueryTest extends TestCase
$attrs = $obj->getAttributes(); $attrs = $obj->getAttributes();
$this->assertCount(2, $attrs); $this->assertCount(2, $attrs);
$this->assertEquals($attrs[1], '=key2=value2');
$this->assertEquals('=key2=value2', $attrs[1]);
} }
public function testTag(): void public function testTag(): void
@ -124,7 +125,7 @@ class QueryTest extends TestCase
$query = $obj->getQuery(); $query = $obj->getQuery();
$this->assertCount(3, $query); $this->assertCount(3, $query);
$this->assertEquals($query[2], '.tag=test');
$this->assertEquals('.tag=test', $query[2]);
} }
public function testOperator(): void public function testOperator(): void
@ -135,7 +136,7 @@ class QueryTest extends TestCase
$query = $obj->getQuery(); $query = $obj->getQuery();
$this->assertCount(3, $query); $this->assertCount(3, $query);
$this->assertEquals($query[2], '?#|');
$this->assertEquals('?#|', $query[2]);
} }
public function testWhereEx(): void public function testWhereEx(): void
@ -153,8 +154,8 @@ class QueryTest extends TestCase
$query = $obj->getQuery(); $query = $obj->getQuery();
$this->assertCount(2, $query); $this->assertCount(2, $query);
$this->assertEquals($query[0], 'test');
$this->assertEquals($query[1], 'line');
$this->assertEquals('test', $query[0]);
$this->assertEquals('line', $query[1]);
} }
public function testGetQueryEx(): void public function testGetQueryEx(): void

1
tests/ResponseIteratorTest.php

@ -4,7 +4,6 @@ namespace RouterOS\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use RouterOS\Client; use RouterOS\Client;
use RouterOS\ResponseIterator;
class ResponseIteratorTest extends TestCase class ResponseIteratorTest extends TestCase
{ {

13
tests/Streams/ResourceStreamTest.php

@ -4,9 +4,9 @@ namespace RouterOS\Tests\Streams;
use InvalidArgumentException; use InvalidArgumentException;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Constraint\IsType;
use RouterOS\Exceptions\StreamException; use RouterOS\Exceptions\StreamException;
use RouterOS\Streams\ResourceStream; use RouterOS\Streams\ResourceStream;
use stdClass;
/** /**
* Limit code coverage to the class RouterOS\APIStream * Limit code coverage to the class RouterOS\APIStream
@ -23,7 +23,6 @@ class ResourceStreamTest extends TestCase
* *
* @param $notResource * @param $notResource
*/ */
public function testConstructNotResource($notResource): void public function testConstructNotResource($notResource): void
{ {
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
@ -42,9 +41,9 @@ class ResourceStreamTest extends TestCase
[3.14], // float [3.14], // float
['a string'], // string ['a string'], // string
[ [
[0, 3.14] // Array
[0, 3.14], // Array
], ],
[new \stdClass()], // Object
[new stdClass()], // Object
// What else ? // What else ?
]; ];
} }
@ -83,8 +82,8 @@ class ResourceStreamTest extends TestCase
public function constructProvider(): array public function constructProvider(): array
{ {
return [ return [
[fopen(__FILE__, 'rb'),], // Myself, sure I exists
[fsockopen('tcp://' . getenv('ROS_HOST'), getenv('ROS_PORT_MODERN')),], // Socket
[fopen(__FILE__, 'rb')], // Myself, sure I exists
[fsockopen('tcp://' . getenv('ROS_HOST'), getenv('ROS_PORT_MODERN'))], // Socket
[STDIN, false], // Try it, but do not close STDIN please !!! [STDIN, false], // Try it, but do not close STDIN please !!!
// What else ? // What else ?
]; ];
@ -167,6 +166,7 @@ class ResourceStreamTest extends TestCase
$resource = fopen(__FILE__, 'rb'); $resource = fopen(__FILE__, 'rb');
$me = new ResourceStream($resource); $me = new ResourceStream($resource);
fclose($resource); fclose($resource);
return [ return [
[$me, 1], [$me, 1],
]; ];
@ -269,5 +269,4 @@ class ResourceStreamTest extends TestCase
[new ResourceStream(fopen('/dev/null', 'wb')), 'sasasaas'], // Take that [new ResourceStream(fopen('/dev/null', 'wb')), 'sasasaas'], // Take that
]; ];
} }
} }

14
tests/Streams/StringStreamTest.php

@ -2,9 +2,9 @@
namespace RouterOS\Tests\Streams; namespace RouterOS\Tests\Streams;
use Generator;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Constraint\IsType;
use RouterOS\Streams\StringStream; use RouterOS\Streams\StringStream;
use RouterOS\Exceptions\StreamException; use RouterOS\Exceptions\StreamException;
@ -81,7 +81,7 @@ class StringStreamTest extends TestCase
*/ */
public function testWriteWithNegativeLength(): void public function testWriteWithNegativeLength(): void
{ {
$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$stream = new StringStream('Does not matters'); $stream = new StringStream('Does not matters');
$stream->write('PLOP', -1); $stream->write('PLOP', -1);
} }
@ -108,7 +108,7 @@ class StringStreamTest extends TestCase
*/ */
public function testReadBadLength(): void public function testReadBadLength(): void
{ {
$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$stream = new StringStream('123456789'); $stream = new StringStream('123456789');
$stream->read(-1); $stream->read(-1);
} }
@ -124,7 +124,7 @@ class StringStreamTest extends TestCase
*/ */
public function testReadWhileEmpty(StringStream $stream, int $length): void public function testReadWhileEmpty(StringStream $stream, int $length): void
{ {
$this->expectException(\RouterOS\Exceptions\StreamException::class);
$this->expectException(StreamException::class);
$stream->read($length); $stream->read($length);
} }
@ -132,7 +132,7 @@ class StringStreamTest extends TestCase
* @return \Generator * @return \Generator
* @throws StreamException * @throws StreamException
*/ */
public function readWhileEmptyProvider(): ?\Generator
public function readWhileEmptyProvider(): ?Generator
{ {
$stream = new StringStream('123456789'); $stream = new StringStream('123456789');
$stream->read(9); $stream->read(9);
@ -149,7 +149,7 @@ class StringStreamTest extends TestCase
public function testReadClosed(): void public function testReadClosed(): void
{ {
$this->expectException(\RouterOS\Exceptions\StreamException::class);
$this->expectException(StreamException::class);
$stream = new StringStream('123456789'); $stream = new StringStream('123456789');
$stream->close(); $stream->close();
$stream->read(1); $stream->read(1);

Loading…
Cancel
Save