|
|
|
@ -8,51 +8,51 @@ use RouterOS\Query; |
|
|
|
|
|
|
|
class QueryTest extends TestCase |
|
|
|
{ |
|
|
|
public function test__construct() |
|
|
|
public function test__construct(): void |
|
|
|
{ |
|
|
|
try { |
|
|
|
$obj = new Query('test'); |
|
|
|
$this->assertInternalType('object', $obj); |
|
|
|
$this->assertIsObject($obj); |
|
|
|
} catch (\Exception $e) { |
|
|
|
$this->assertContains('Must be initialized ', $e->getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function test__construct_arr() |
|
|
|
public function test__construct_arr(): void |
|
|
|
{ |
|
|
|
try { |
|
|
|
$obj = new Query('test', ['line1', 'line2', 'line3']); |
|
|
|
$this->assertInternalType('object', $obj); |
|
|
|
$this->assertIsObject($obj); |
|
|
|
} catch (\Exception $e) { |
|
|
|
$this->assertContains('Must be initialized ', $e->getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function test__construct_arr2() |
|
|
|
public function test__construct_arr2(): void |
|
|
|
{ |
|
|
|
try { |
|
|
|
$obj = new Query(['test', 'line1', 'line2', 'line3']); |
|
|
|
$this->assertInternalType('object', $obj); |
|
|
|
$this->assertIsObject($obj); |
|
|
|
} catch (\Exception $e) { |
|
|
|
$this->assertContains('Must be initialized ', $e->getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function testGetEndpoint() |
|
|
|
public function testGetEndpoint(): void |
|
|
|
{ |
|
|
|
$obj = new Query('test'); |
|
|
|
$test = $obj->getEndpoint(); |
|
|
|
$this->assertEquals($test, 'test'); |
|
|
|
} |
|
|
|
|
|
|
|
public function testGetEndpoint2() |
|
|
|
public function testGetEndpoint2(): void |
|
|
|
{ |
|
|
|
$obj = new Query(['zzz', 'line1', 'line2', 'line3']); |
|
|
|
$test = $obj->getEndpoint(); |
|
|
|
$this->assertEquals($test, 'zzz'); |
|
|
|
} |
|
|
|
|
|
|
|
public function testGetEndpointEx() |
|
|
|
public function testGetEndpointEx(): void |
|
|
|
{ |
|
|
|
$this->expectException(QueryException::class); |
|
|
|
|
|
|
|
@ -60,7 +60,7 @@ class QueryTest extends TestCase |
|
|
|
$test = $obj->getEndpoint(); |
|
|
|
} |
|
|
|
|
|
|
|
public function testSetEndpoint() |
|
|
|
public function testSetEndpoint(): void |
|
|
|
{ |
|
|
|
$obj = new Query('test'); |
|
|
|
$obj->setEndpoint('zzz'); |
|
|
|
@ -68,14 +68,14 @@ class QueryTest extends TestCase |
|
|
|
$this->assertEquals($test, 'zzz'); |
|
|
|
} |
|
|
|
|
|
|
|
public function testGetAttributes() |
|
|
|
public function testGetAttributes(): void |
|
|
|
{ |
|
|
|
$obj = new Query('test'); |
|
|
|
$test = $obj->getAttributes(); |
|
|
|
$this->assertCount(0, $test); |
|
|
|
} |
|
|
|
|
|
|
|
public function testSetAttributes() |
|
|
|
public function testSetAttributes(): void |
|
|
|
{ |
|
|
|
$obj = new Query('test'); |
|
|
|
$obj->setAttributes(['line1', 'line2', 'line3']); |
|
|
|
@ -83,7 +83,7 @@ class QueryTest extends TestCase |
|
|
|
$this->assertCount(3, $test); |
|
|
|
} |
|
|
|
|
|
|
|
public function testAdd() |
|
|
|
public function testAdd(): void |
|
|
|
{ |
|
|
|
$obj = new Query('test'); |
|
|
|
$obj->add('line'); |
|
|
|
@ -93,7 +93,48 @@ class QueryTest extends TestCase |
|
|
|
$this->assertEquals($attrs[0], 'line'); |
|
|
|
} |
|
|
|
|
|
|
|
public function testGetQuery() |
|
|
|
public function testWhere(): void |
|
|
|
{ |
|
|
|
$obj = new Query('test'); |
|
|
|
$obj->where('key1', 'value1'); |
|
|
|
$obj->where('key2', 'value2'); |
|
|
|
|
|
|
|
$attrs = $obj->getAttributes(); |
|
|
|
$this->assertCount(2, $attrs); |
|
|
|
$this->assertEquals($attrs[1], '?=key2=value2'); |
|
|
|
} |
|
|
|
|
|
|
|
public function testTag(): void |
|
|
|
{ |
|
|
|
$obj = new Query('/test/test'); |
|
|
|
$obj->where('key1', 'value1'); |
|
|
|
$obj->tag('test'); |
|
|
|
|
|
|
|
$query = $obj->getQuery(); |
|
|
|
$this->assertCount(3, $query); |
|
|
|
$this->assertEquals($query[2], '.tag=test'); |
|
|
|
} |
|
|
|
|
|
|
|
public function testOperator(): void |
|
|
|
{ |
|
|
|
$obj = new Query('/test/test'); |
|
|
|
$obj->where('key1', 'value1'); |
|
|
|
$obj->operations('|'); |
|
|
|
|
|
|
|
$query = $obj->getQuery(); |
|
|
|
$this->assertCount(3, $query); |
|
|
|
$this->assertEquals($query[2], '?#|'); |
|
|
|
} |
|
|
|
|
|
|
|
public function testWhereEx(): void |
|
|
|
{ |
|
|
|
$this->expectException(QueryException::class); |
|
|
|
|
|
|
|
$obj = new Query('/richard/cheese'); |
|
|
|
$obj->where('people', 'equals', 'shit'); |
|
|
|
} |
|
|
|
|
|
|
|
public function testGetQuery(): void |
|
|
|
{ |
|
|
|
$obj = new Query('test'); |
|
|
|
$obj->add('line'); |
|
|
|
@ -104,7 +145,7 @@ class QueryTest extends TestCase |
|
|
|
$this->assertEquals($query[1], 'line'); |
|
|
|
} |
|
|
|
|
|
|
|
public function testGetQueryEx() |
|
|
|
public function testGetQueryEx(): void |
|
|
|
{ |
|
|
|
$this->expectException(QueryException::class); |
|
|
|
|
|
|
|
|