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. 1
      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
{
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(STDIN), false], // 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\Streams\StringStream;
use RouterOS\Helpers\BinaryStringHelper;
use UnexpectedValueException;
/**
* Limit code coverage to the class
@ -99,7 +100,7 @@ class APILengthCoDecTest extends TestCase
*/
public function testDecodeLengthControlWord(string $encodedLength): void
{
$this->expectException(\UnexpectedValueException::class);
$this->expectException(UnexpectedValueException::class);
APILengthCoDec::decodeLength(new StringStream($encodedLength));
}

10
tests/ClientTest.php

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

9
tests/ConfigTest.php

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

1
tests/Helpers/BinaryStringHelperTest.php

@ -3,7 +3,6 @@
namespace RouterOS\Tests\Helpers;
use PHPUnit\Framework\TestCase;
use RouterOS\Helpers\BinaryStringHelper;
/**

30
tests/Laravel/ServiceProviderTests.php

@ -8,19 +8,19 @@ use RouterOS\Laravel\Wrapper;
class ServiceProviderTests extends TestCase
{
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
@ -34,7 +34,7 @@ class ServiceProviderTests extends TestCase
$config = \RouterOS::config([
'host' => '192.168.1.3',
'user' => 'admin',
'pass' => 'admin'
'pass' => 'admin',
]);
$this->assertInstanceOf(Config::class, $config);
@ -54,7 +54,7 @@ class ServiceProviderTests extends TestCase
$client = \RouterOS::client([
'host' => '192.168.1.3',
'user' => 'admin',
'pass' => 'admin'
'pass' => 'admin',
], false);
$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
{
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function getPackageProviders($app): array
{
@ -24,7 +24,7 @@ abstract class TestCase extends Orchestra
}
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function getPackageAliases($app): array
{

23
tests/QueryTest.php

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

1
tests/ResponseIteratorTest.php

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

13
tests/Streams/ResourceStreamTest.php

@ -4,9 +4,9 @@ namespace RouterOS\Tests\Streams;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Constraint\IsType;
use RouterOS\Exceptions\StreamException;
use RouterOS\Streams\ResourceStream;
use stdClass;
/**
* Limit code coverage to the class RouterOS\APIStream
@ -23,7 +23,6 @@ class ResourceStreamTest extends TestCase
*
* @param $notResource
*/
public function testConstructNotResource($notResource): void
{
$this->expectException(InvalidArgumentException::class);
@ -42,9 +41,9 @@ class ResourceStreamTest extends TestCase
[3.14], // float
['a string'], // string
[
[0, 3.14] // Array
[0, 3.14], // Array
],
[new \stdClass()], // Object
[new stdClass()], // Object
// What else ?
];
}
@ -83,8 +82,8 @@ class ResourceStreamTest extends TestCase
public function constructProvider(): array
{
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 !!!
// What else ?
];
@ -167,6 +166,7 @@ class ResourceStreamTest extends TestCase
$resource = fopen(__FILE__, 'rb');
$me = new ResourceStream($resource);
fclose($resource);
return [
[$me, 1],
];
@ -269,5 +269,4 @@ class ResourceStreamTest extends TestCase
[new ResourceStream(fopen('/dev/null', 'wb')), 'sasasaas'], // Take that
];
}
}

14
tests/Streams/StringStreamTest.php

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

Loading…
Cancel
Save