From ea57eefabea5af806b1428f36a40a29e9e85d6ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ch=C3=A1bek?= Date: Sat, 4 Jul 2020 13:09:59 +0200 Subject: [PATCH] tmp fix coverage --- src/Helpers/ValueGetter.php | 4 ++-- tests/Transport/ApiSnmpClientTest.php | 8 ++++++++ tests/Transport/FallbackSnmpClientTest.php | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Helpers/ValueGetter.php b/src/Helpers/ValueGetter.php index d274dfb..b01846a 100644 --- a/src/Helpers/ValueGetter.php +++ b/src/Helpers/ValueGetter.php @@ -30,13 +30,13 @@ public static function first(array $response) /** * @param list> $responses * - * @return mixed + * @return list * * @psalm-template T * @psalm-param list> $responses * @psalm-return list */ - public static function batchFirst(array $responses) + public static function batchFirst(array $responses) : array { $result = []; foreach ($responses as $response) { diff --git a/tests/Transport/ApiSnmpClientTest.php b/tests/Transport/ApiSnmpClientTest.php index 1212e0a..559d068 100644 --- a/tests/Transport/ApiSnmpClientTest.php +++ b/tests/Transport/ApiSnmpClientTest.php @@ -13,6 +13,7 @@ use Psr\Http\Message\RequestInterface; use SimPod\PhpSnmp\Exception\EndOfMibReached; use SimPod\PhpSnmp\Exception\GeneralException; +use SimPod\PhpSnmp\Exception\NoRequestsProvided; use SimPod\PhpSnmp\Exception\NoSuchInstanceExists; use SimPod\PhpSnmp\Exception\NoSuchObjectExists; use SimPod\PhpSnmp\Transport\ApiSnmpClient; @@ -282,6 +283,13 @@ static function (RequestInterface $request) : bool { ); } + public function testBatchNoRequests() : void + { + $this->expectExceptionObject(NoRequestsProvided::new()); + + $this->createApiSnmp()->batch(); + } + public function testThatParametersAreCorrectlyPropagatedToTheJsonRequest() : void { $this->client = $this->createMock(Client::class); diff --git a/tests/Transport/FallbackSnmpClientTest.php b/tests/Transport/FallbackSnmpClientTest.php index 4d32038..0be6854 100644 --- a/tests/Transport/FallbackSnmpClientTest.php +++ b/tests/Transport/FallbackSnmpClientTest.php @@ -9,6 +9,7 @@ use Psr\Log\Test\TestLogger; use SimPod\PhpSnmp\Exception\GeneralException; use SimPod\PhpSnmp\Transport\FallbackSnmpClient; +use SimPod\PhpSnmp\Transport\Request; use SimPod\PhpSnmp\Transport\SnmpClient; final class FallbackSnmpClientTest extends TestCase @@ -55,6 +56,20 @@ public function testWalk() : void self::assertSame($expected, $result); } + public function testBatch() : void + { + $client1 = $this->createMock(SnmpClient::class); + $client1->expects(self::once()) + ->method('batch') + ->with($request1 = Request::walk('.1.2.3', 10), $request2 = Request::get(['.4.5.6'])) + ->willReturn($expected = [['.1.2.3' => 123], ['.4.5.6' => 456]]); + + $fallbackClient = new FallbackSnmpClient(new NullLogger(), $client1); + $result = $fallbackClient->batch($request1, $request2); + + self::assertSame($expected, $result); + } + public function testOnlyLastClientWorks() : void { $client1 = $this->createMock(SnmpClient::class);