From d491e397c717693abf11804b0e67c6429dbf35ce Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Thu, 25 Jul 2019 02:01:11 +0300 Subject: [PATCH] tests updated --- tests/ClientTest.php | 86 ++++++++++++++++++++++++++++++++-------------------- tests/QueryTest.php | 2 +- 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 0895f8b..0f77cf5 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -135,41 +135,62 @@ class ClientTest extends TestCase ]); } - public function testWriteRead(): void + public function testQueryRead(): void { $config = new Config(); $config->set('user', getenv('ROS_USER'))->set('pass', getenv('ROS_PASS'))->set('host', getenv('ROS_HOST')); $obj = new Client($config); - $query = new Query('/ip/address/print'); - $readRaw = $obj->write($query)->read(false); - $this->assertCount(10, $readRaw); - $this->assertEquals('=.id=*1', $readRaw[1]); + /* + * Build query with where + */ - $query = new Query('/system/package/print'); - $read = $obj->write($query)->read(); + $read = $obj->query('/system/package/print')->read(); $this->assertCount(13, $read); $this->assertEquals('advanced-tools', $read[12]['name']); - $query = new Query('/ip/address/print'); - $readRaw = $obj->w($query)->read(false); - $this->assertCount(10, $readRaw); - $this->assertEquals('=.id=*1', $readRaw[1]); + $read = $obj->query('/system/package/print', ['name'])->read(); + $this->assertCount(13, $read); + $this->assertEquals('dude', $read[0]['name']); + + $read = $obj->query('/system/package/print', ['.id', '*1'])->read(); + $this->assertCount(1, $read); + $this->assertEquals('dude', $read[0]['name']); + + $read = $obj->query('/system/package/print', ['.id', '=', '*1'])->read(); + $this->assertCount(1, $read); + $this->assertEquals('dude', $read[0]['name']); + + $read = $obj->query('/system/package/print', [['name']])->read(); + $this->assertCount(13, $read); + $this->assertEquals('dude', $read[0]['name']); - $query = new Query('/interface/getall'); - $read = $obj->write($query)->r(); + $read = $obj->query('/system/package/print', [['.id', '*1']])->read(); + $this->assertCount(1, $read); + $this->assertEquals('dude', $read[0]['name']); + + $read = $obj->query('/system/package/print', [['.id', '=', '*1']])->read(); + $this->assertCount(1, $read); + $this->assertEquals('dude', $read[0]['name']); + + /* + * Build query with operations + */ + + $read = $obj->query('/interface/print', [ + ['type', 'ether'], + ['type', 'vlan'] + ], '|')->read(); $this->assertCount(1, $read); $this->assertEquals('*1', $read[0]['.id']); - $query = new Query('/interface'); - $readTrap = $obj->w($query)->r(false); - $this->assertCount(3, $readTrap); - $this->assertEquals('!trap', $readTrap[0]); + /* + * Build query with tag + */ - $query = new Query('/interface'); - $readTrap = $obj->wr($query, false); - $this->assertCount(3, $readTrap); - $this->assertEquals('!trap', $readTrap[0]); + $read = $obj->query('/system/package/print', null, null, 'zzzz')->read(); + $this->assertCount(13, $read); + $this->assertEquals('zzzz', $read[0]['tag']); } public function testReadAsIterator(): void @@ -197,7 +218,7 @@ class ClientTest extends TestCase $this->assertEquals('!trap', $readTrap[0]); } - public function testWriteReadArray(): void + public function testFatal(): void { $obj = new Client([ 'user' => getenv('ROS_USER'), @@ -205,27 +226,27 @@ class ClientTest extends TestCase 'host' => getenv('ROS_HOST'), ]); - $readTrap = $obj->wr(['/interface'], false); - $this->assertCount(3, $readTrap); - $this->assertEquals('!trap', $readTrap[0]); + $readTrap = $obj->query('/quit')->read(); + $this->assertCount(2, $readTrap); + $this->assertEquals('!fatal', $readTrap[0]); } - public function testFatal(): void + public function testQueryEx1(): void { + $this->expectException(ClientException::class); + $obj = new Client([ 'user' => getenv('ROS_USER'), 'pass' => getenv('ROS_PASS'), 'host' => getenv('ROS_HOST'), ]); - $readTrap = $obj->wr('/quit'); - $this->assertCount(2, $readTrap); - $this->assertEquals('!fatal', $readTrap[0]); + $obj->query('/quiet', ['a', 'b', 'c', 'd']); } - public function testWriteEx(): void + public function testQueryEx2(): void { - $this->expectException(QueryException::class); + $this->expectException(ClientException::class); $obj = new Client([ 'user' => getenv('ROS_USER'), @@ -233,7 +254,6 @@ class ClientTest extends TestCase 'host' => getenv('ROS_HOST'), ]); - $obj->write($obj)->read(false); + $obj->query('/quiet', [[]]); } - } diff --git a/tests/QueryTest.php b/tests/QueryTest.php index 26964c6..2f5c701 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -101,7 +101,7 @@ class QueryTest extends TestCase $attrs = $obj->getAttributes(); $this->assertCount(2, $attrs); - $this->assertEquals($attrs[1], '?=key2=value2'); + $this->assertEquals($attrs[1], '?key2=value2'); } public function testTag(): void