diff --git a/.gitignore b/.gitignore index f4686f8..24c6b28 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.idea/ /vendor/ /composer.lock +/.phpunit.result.cache diff --git a/composer.json b/composer.json index 5a7af1b..57109fc 100644 --- a/composer.json +++ b/composer.json @@ -33,10 +33,10 @@ "extra": { "laravel": { "providers": [ - "RouterOS\\Laravel\\ClientServiceProvider" + "RouterOS\\Laravel\\ServiceProvider" ], "aliases": { - "RouterOS": "RouterOS\\Laravel\\ClientFacade" + "RouterOS": "RouterOS\\Laravel\\Facade" } } }, @@ -45,7 +45,8 @@ "ext-sockets": "*" }, "require-dev": { - "phpunit/phpunit": "^7.0", - "orchestra/testbench": "^3.0" + "limedeck/phpunit-detailed-printer": "^5.0", + "orchestra/testbench": "^4.0|^5.0", + "phpunit/phpunit": "^8.0" } } diff --git a/phpunit.xml b/phpunit.xml index b065af3..df8ac12 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,6 +6,7 @@ convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" + printerClass="LimeDeck\Testing\Printer" processIsolation="false" stopOnFailure="true"> diff --git a/tests/APIConnectorTest.php b/tests/APIConnectorTest.php index b4784fe..f5da3e5 100644 --- a/tests/APIConnectorTest.php +++ b/tests/APIConnectorTest.php @@ -25,7 +25,7 @@ class APIConnectorTest extends TestCase * @param StreamInterface $stream Cannot typehint, PHP refuse it * @param bool $closeResource shall we close the resource ? */ - public function test_construct(StreamInterface $stream, bool $closeResource = false) + public function testConstruct(StreamInterface $stream, bool $closeResource = false): void { $apiStream = new APIConnector($stream); $this->assertInstanceOf(APIConnector::class, $apiStream); @@ -53,7 +53,7 @@ class APIConnectorTest extends TestCase * @param APIConnector $connector * @param string $expected */ - public function test__readWord(APIConnector $connector, string $expected) + public function testReadWord(APIConnector $connector, string $expected): void { $this->assertSame($expected, $connector->readWord()); } @@ -79,7 +79,7 @@ class APIConnectorTest extends TestCase * @param string $toWrite * @param int $expected */ - public function test_writeWord(APIConnector $connector, string $toWrite, int $expected) + public function testWriteWord(APIConnector $connector, string $toWrite, int $expected): void { $this->assertEquals($expected, $connector->writeWord($toWrite)); } diff --git a/tests/APILengthCoDecTest.php b/tests/APILengthCoDecTest.php index 5b59514..5abd818 100644 --- a/tests/APILengthCoDecTest.php +++ b/tests/APILengthCoDecTest.php @@ -18,11 +18,13 @@ class APILengthCoDecTest extends TestCase { /** * @dataProvider encodeLengthNegativeProvider - * @expectedException \DomainException * @covers ::encodeLength + * + * @param $length */ - public function test__encodeLengthNegative($length) + public function testEncodeLengthNegative($length): void { + $this->expectException(\DomainException::class); APILengthCoDec::encodeLength($length); } @@ -37,8 +39,11 @@ class APILengthCoDecTest extends TestCase /** * @dataProvider encodedLengthProvider * @covers ::encodeLength + * + * @param $expected + * @param $length */ - public function test__encodeLength($expected, $length) + public function testEncodeLength($expected, $length): void { $this->assertEquals(BinaryStringHelper::IntegerToNBOBinaryString((int) $expected), APILengthCoDec::encodeLength($length)); } @@ -76,8 +81,11 @@ class APILengthCoDecTest extends TestCase /** * @dataProvider encodedLengthProvider * @covers ::decodeLength + * + * @param $encodedLength + * @param $expected */ - public function test__decodeLength($encodedLength, $expected) + public function testDecodeLength($encodedLength, $expected): void { // We have to provide $encodedLength as a "bytes" stream $stream = new StringStream(BinaryStringHelper::IntegerToNBOBinaryString($encodedLength)); @@ -87,10 +95,12 @@ class APILengthCoDecTest extends TestCase /** * @dataProvider decodeLengthControlWordProvider * @covers ::decodeLength - * @expectedException \UnexpectedValueException + * + * @param string $encodedLength */ - public function test_decodeLengthControlWord(string $encodedLength) + public function testDecodeLengthControlWord(string $encodedLength): void { + $this->expectException(\UnexpectedValueException::class); APILengthCoDec::decodeLength(new StringStream($encodedLength)); } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 6dda7da..0417287 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -2,6 +2,7 @@ namespace RouterOS\Tests; +use Exception; use PHPUnit\Framework\TestCase; use RouterOS\Client; use RouterOS\Exceptions\ConfigException; @@ -27,7 +28,7 @@ class ClientTest extends TestCase */ public $port_legacy; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -41,7 +42,7 @@ class ClientTest extends TestCase $this->port_legacy = (int) getenv('ROS_PORT_LEGACY'); } - public function test__construct(): void + public function testConstruct(): void { try { $config = new Config(); @@ -54,12 +55,12 @@ class ClientTest extends TestCase $this->assertIsObject($obj); $socket = $obj->getSocket(); $this->assertIsResource($socket); - } catch (\Exception $e) { - $this->assertContains('Must be initialized ', $e->getMessage()); + } catch (Exception $e) { + $this->assertStringContainsString('Must be initialized ', $e->getMessage()); } } - public function test__construct2(): void + public function testConstruct2(): void { try { $config = new Config($this->router); @@ -67,24 +68,24 @@ class ClientTest extends TestCase $this->assertIsObject($obj); $socket = $obj->getSocket(); $this->assertIsResource($socket); - } catch (\Exception $e) { - $this->assertContains('Must be initialized ', $e->getMessage()); + } catch (Exception $e) { + $this->assertStringContainsString('Must be initialized ', $e->getMessage()); } } - public function test__construct3(): void + public function testConstruct3(): void { try { $obj = new Client($this->router); $this->assertIsObject($obj); $socket = $obj->getSocket(); $this->assertIsResource($socket); - } catch (\Exception $e) { - $this->assertContains('Must be initialized ', $e->getMessage()); + } catch (Exception $e) { + $this->assertStringContainsString('Must be initialized ', $e->getMessage()); } } - public function test__constructEx(): void + public function testConstructEx(): void { $this->expectException(ConfigException::class); @@ -94,7 +95,7 @@ class ClientTest extends TestCase ]); } - public function test__constructLegacy(): void + public function testConstructLegacy(): void { try { $obj = new Client([ @@ -105,8 +106,8 @@ class ClientTest extends TestCase 'legacy' => true ]); $this->assertIsObject($obj); - } catch (\Exception $e) { - $this->assertContains('Must be initialized ', $e->getMessage()); + } catch (Exception $e) { + $this->assertStringContainsString('Must be initialized ', $e->getMessage()); } } @@ -115,7 +116,7 @@ class ClientTest extends TestCase * * login() method recognise legacy router response and swap to legacy mode */ - public function test__constructLegacy2(): void + public function testConstructLegacy2(): void { try { $obj = new Client([ @@ -126,13 +127,13 @@ class ClientTest extends TestCase 'legacy' => false ]); $this->assertIsObject($obj); - } catch (\Exception $e) { - $this->assertContains('Must be initialized ', $e->getMessage()); + } catch (Exception $e) { + $this->assertStringContainsString('Must be initialized ', $e->getMessage()); } } - public function test__constructWrongPass(): void + public function testConstructWrongPass(): void { $this->expectException(ClientException::class); @@ -144,13 +145,9 @@ class ClientTest extends TestCase ]); } - /** - * @expectedException ClientException - */ - public function test__constructWrongNet(): void + public function testConstructWrongNet(): void { $this->expectException(ClientException::class); - $obj = new Client([ 'user' => $this->router['user'], 'pass' => $this->router['pass'], @@ -216,7 +213,7 @@ class ClientTest extends TestCase { $obj = new Client($this->router); - $obj = $obj->write('/system/package/print')->readAsIterator(); + $obj = $obj->query('/system/package/print')->readAsIterator(); $this->assertIsObject($obj); } @@ -228,7 +225,7 @@ class ClientTest extends TestCase 'host' => $this->router['host'], ]); - $readTrap = $obj->wr('/interface', false); + $readTrap = $obj->query('/interface')->read(false); $this->assertCount(3, $readTrap); $this->assertEquals('!trap', $readTrap[0]); } diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index d444888..f12459e 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -8,58 +8,58 @@ use RouterOS\Exceptions\ConfigException; class ConfigTest extends TestCase { - public function test__construct() + public function testConstruct(): void { try { $obj = new Config(); - $this->assertInternalType('object', $obj); + $this->assertIsObject($obj); } catch (\Exception $e) { - $this->assertContains('Must be initialized ', $e->getMessage()); + $this->assertStringContainsString('Must be initialized ', $e->getMessage()); } } - public function testGetParameters() + public function testGetParameters(): void { $obj = new Config(); $params = $obj->getParameters(); $this->assertCount(5, $params); - $this->assertEquals($params['legacy'], false); - $this->assertEquals($params['ssl'], false); - $this->assertEquals($params['timeout'], 10); - $this->assertEquals($params['attempts'], 10); - $this->assertEquals($params['delay'], 1); + $this->assertEquals(false, $params['legacy']); + $this->assertEquals(false, $params['ssl']); + $this->assertEquals(10, $params['timeout']); + $this->assertEquals(10, $params['attempts']); + $this->assertEquals(1, $params['delay']); } - public function testGetParameters2() + public function testGetParameters2(): void { $obj = new Config(['timeout' => 100]); $params = $obj->getParameters(); $this->assertCount(5, $params); - $this->assertEquals($params['timeout'], 100); + $this->assertEquals(100, $params['timeout']); } - public function testSet() + public function testSet(): void { $obj = new Config(); $obj->set('timeout', 111); $params = $obj->getParameters(); - $this->assertEquals($params['timeout'], 111); + $this->assertEquals(111, $params['timeout']); } - public function testSetArr() + public function testSetArr(): void { $obj = new Config([ 'timeout' => 111 ]); $params = $obj->getParameters(); - $this->assertEquals($params['timeout'], 111); + $this->assertEquals(111, $params['timeout']); } - public function testDelete() + public function testDelete(): void { $obj = new Config(); $obj->delete('timeout'); @@ -68,7 +68,7 @@ class ConfigTest extends TestCase $this->assertArrayNotHasKey('timeout', $params); } - public function testDeleteEx() + public function testDeleteEx(): void { $this->expectException(ConfigException::class); @@ -76,7 +76,7 @@ class ConfigTest extends TestCase $obj->delete('wrong'); } - public function testSetEx1() + public function testSetEx1(): void { $this->expectException(ConfigException::class); @@ -84,7 +84,7 @@ class ConfigTest extends TestCase $obj->set('delay', 'some string'); } - public function testSetEx2() + public function testSetEx2(): void { $this->expectException(ConfigException::class); @@ -92,27 +92,26 @@ class ConfigTest extends TestCase $obj->set('wrong', 'some string'); } - public function testGet() + public function testGet(): void { $obj = new Config(); $test1 = $obj->get('legacy'); - $this->assertEquals($test1, false); + $this->assertEquals(false, $test1); $test2 = $obj->get('port'); - $this->assertEquals($test2, 8728); + $this->assertEquals(8728, $test2); $obj->set('port', 10000); $test3 = $obj->get('port'); - $this->assertEquals($test3, 10000); - + $this->assertEquals(10000, $test3); $obj->delete('port'); $obj->set('ssl', true); $test3 = $obj->get('port'); - $this->assertEquals($test3, 8729); + $this->assertEquals(8729, $test3); } - public function testGetEx() + public function testGetEx(): void { $this->expectException(ConfigException::class); diff --git a/tests/Helpers/ArrayHelperTest.php b/tests/Helpers/ArrayHelperTest.php index bb4a2dc..d980a40 100644 --- a/tests/Helpers/ArrayHelperTest.php +++ b/tests/Helpers/ArrayHelperTest.php @@ -7,7 +7,7 @@ use RouterOS\Helpers\ArrayHelper; class ArrayHelperTest extends TestCase { - public function testCheckIfKeyNotExist() + public function testCheckIfKeyNotExist(): void { $test1 = ArrayHelper::checkIfKeyNotExist(1, [0 => 'a', 1 => 'b', 2 => 'c']); $this->assertFalse($test1); @@ -16,7 +16,7 @@ class ArrayHelperTest extends TestCase $this->assertTrue($test2); } - public function testCheckIfKeysNotExist() + public function testCheckIfKeysNotExist(): void { $test1 = ArrayHelper::checkIfKeysNotExist([1, 2], [0 => 'a', 1 => 'b', 2 => 'c']); $this->assertTrue($test1); diff --git a/tests/Helpers/BinaryStringHelperTest.php b/tests/Helpers/BinaryStringHelperTest.php index 014f17a..716ebff 100644 --- a/tests/Helpers/BinaryStringHelperTest.php +++ b/tests/Helpers/BinaryStringHelperTest.php @@ -16,8 +16,11 @@ class BinaryStringHelperTest extends TestCase /** * @dataProvider IntegerToNBOBinaryStringProvider * @covers ::IntegerToNBOBinaryString + * + * @param $value + * @param $expected */ - public function test__IntegerToNBOBinaryString($value, $expected) + public function testIntegerToNBOBinaryString($value, $expected): void { $this->assertEquals($expected, BinaryStringHelper::IntegerToNBOBinaryString($value)); } diff --git a/tests/Helpers/TypeHelperTest.php b/tests/Helpers/TypeHelperTest.php index ab08d2b..c00468e 100644 --- a/tests/Helpers/TypeHelperTest.php +++ b/tests/Helpers/TypeHelperTest.php @@ -7,7 +7,7 @@ use RouterOS\Helpers\TypeHelper; class TypeHelperTest extends TestCase { - public function testCheckIfTypeMismatch() + public function testCheckIfTypeMismatch(): void { $test1 = TypeHelper::checkIfTypeMismatch(gettype(true), gettype(false)); $this->assertFalse($test1); diff --git a/tests/QueryTest.php b/tests/QueryTest.php index 2f5c701..0568d21 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -8,33 +8,33 @@ use RouterOS\Query; class QueryTest extends TestCase { - public function test__construct(): void + public function testConstruct(): void { try { $obj = new Query('test'); $this->assertIsObject($obj); } catch (\Exception $e) { - $this->assertContains('Must be initialized ', $e->getMessage()); + $this->assertStringContainsString('Must be initialized ', $e->getMessage()); } } - public function test__construct_arr(): void + public function testConstructArr(): void { try { $obj = new Query('test', ['line1', 'line2', 'line3']); $this->assertIsObject($obj); } catch (\Exception $e) { - $this->assertContains('Must be initialized ', $e->getMessage()); + $this->assertStringContainsString('Must be initialized ', $e->getMessage()); } } - public function test__construct_arr2(): void + public function testConstructArr2(): void { try { $obj = new Query(['test', 'line1', 'line2', 'line3']); $this->assertIsObject($obj); } catch (\Exception $e) { - $this->assertContains('Must be initialized ', $e->getMessage()); + $this->assertStringContainsString('Must be initialized ', $e->getMessage()); } } @@ -42,14 +42,14 @@ class QueryTest extends TestCase { $obj = new Query('test'); $test = $obj->getEndpoint(); - $this->assertEquals($test, 'test'); + $this->assertEquals('test', $test); } public function testGetEndpoint2(): void { $obj = new Query(['zzz', 'line1', 'line2', 'line3']); $test = $obj->getEndpoint(); - $this->assertEquals($test, 'zzz'); + $this->assertEquals('zzz', $test); } public function testGetEndpointEx(): void @@ -65,7 +65,7 @@ class QueryTest extends TestCase $obj = new Query('test'); $obj->setEndpoint('zzz'); $test = $obj->getEndpoint(); - $this->assertEquals($test, 'zzz'); + $this->assertEquals('zzz', $test); } public function testGetAttributes(): void diff --git a/tests/ResponseIteratorTest.php b/tests/ResponseIteratorTest.php index 33d2dbd..3b3e027 100644 --- a/tests/ResponseIteratorTest.php +++ b/tests/ResponseIteratorTest.php @@ -7,7 +7,7 @@ use RouterOS\Client; class ResponseIteratorTest extends TestCase { - public function test__construct() + public function testConstruct(): void { $obj = new Client([ 'user' => getenv('ROS_USER'), @@ -15,11 +15,11 @@ class ResponseIteratorTest extends TestCase 'host' => getenv('ROS_HOST'), ]); - $obj = $obj->write('/system/package/print')->readAsIterator(); + $obj = $obj->query('/system/package/print')->readAsIterator(); $this->assertIsObject($obj); } - public function testReadWrite() + public function testReadWrite(): void { $obj = new Client([ 'user' => getenv('ROS_USER'), @@ -27,15 +27,15 @@ class ResponseIteratorTest extends TestCase 'host' => getenv('ROS_HOST'), ]); - $readTrap = $obj->write('/system/package/print')->readAsIterator(); + $readTrap = $obj->query('/system/package/print')->readAsIterator(); // Read from RAW $this->assertCount(13, $readTrap); - $readTrap = $obj->write('/ip/address/print')->readAsIterator(); + $readTrap = $obj->query('/ip/address/print')->readAsIterator(); $this->assertCount(1, $readTrap); $this->assertEquals('ether1', $readTrap[0]['interface']); - $readTrap = $obj->write('/system/package/print')->readAsIterator(); + $readTrap = $obj->query('/system/package/print')->readAsIterator(); $key = $readTrap->key(); $this->assertEquals(0, $key); $current = $readTrap->current(); @@ -68,7 +68,7 @@ class ResponseIteratorTest extends TestCase 'host' => getenv('ROS_HOST'), ]); - $read = $obj->write('/queue/simple/print')->readAsIterator(); + $read = $obj->query('/queue/simple/print')->readAsIterator(); $serialize = $read->serialize(); $this->assertEquals('a:1:{i:0;a:1:{i:0;s:5:"!done";}}', $serialize); } diff --git a/tests/Streams/ResourceStreamTest.php b/tests/Streams/ResourceStreamTest.php index fedb316..8ce56d4 100644 --- a/tests/Streams/ResourceStreamTest.php +++ b/tests/Streams/ResourceStreamTest.php @@ -2,8 +2,10 @@ namespace RouterOS\Tests\Streams; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Constraint\IsType; +use RouterOS\Exceptions\StreamException; use RouterOS\Streams\ResourceStream; /** @@ -17,14 +19,14 @@ class ResourceStreamTest extends TestCase * Test that constructor throws an InvalidArgumentException on bad parameter type * * @covers ::__construct - * @expectedException \InvalidArgumentException * @dataProvider constructNotResourceProvider * * @param $notResource */ - public function test__constructNotResource($notResource) + public function testConstructNotResource($notResource): void { + $this->expectException(InvalidArgumentException::class); new ResourceStream($notResource); } @@ -56,12 +58,17 @@ class ResourceStreamTest extends TestCase * @param resource $resource Cannot typehint, PHP refuse it * @param bool $closeResource shall we close the resource ? */ - public function test_construct($resource, bool $closeResource = true) + public function testConstruct($resource, bool $closeResource = true): void { - $resourceStream = new ResourceStream($resource); + $resourceStream = new class($resource) extends ResourceStream { + public function getStream() + { + return $this->stream; + } + }; - $stream = $this->getObjectAttribute($resourceStream, 'stream'); - $this->assertInternalType(IsType::TYPE_RESOURCE, $stream); + $stream = $resourceStream->getStream(); + $this->assertIsResource($stream); if ($closeResource) { fclose($resource); @@ -89,12 +96,13 @@ class ResourceStreamTest extends TestCase * @covers ::read * @dataProvider readProvider * - * @param ResourceStream $stream Cannot typehint, PHP refuse it - * @param string $expected the result we should have - * @throws \RouterOS\Exceptions\StreamException - * @throws \InvalidArgumentException + * @param ResourceStream $stream Cannot typehint, PHP refuse it + * @param string $expected the result we should have + * + * @throws \RouterOS\Exceptions\StreamException + * @throws \InvalidArgumentException */ - public function test__read(ResourceStream $stream, string $expected) + public function testRead(ResourceStream $stream, string $expected): void { $this->assertSame($expected, $stream->read(strlen($expected))); } @@ -115,15 +123,16 @@ class ResourceStreamTest extends TestCase * * @covers ::read * @dataProvider readBadLengthProvider - * @expectedException \InvalidArgumentException * - * @param ResourceStream $stream Cannot typehint, PHP refuse it - * @param int $length + * @param ResourceStream $stream Cannot typehint, PHP refuse it + * @param int $length + * * @throws \RouterOS\Exceptions\StreamException * @throws \InvalidArgumentException */ - public function test__readBadLength(ResourceStream $stream, int $length) + public function testReadBadLength(ResourceStream $stream, int $length): void { + $this->expectException(InvalidArgumentException::class); $stream->read($length); } @@ -143,13 +152,13 @@ class ResourceStreamTest extends TestCase * * @covers ::read * @dataProvider readBadResourceProvider - * @expectedException \RouterOS\Exceptions\StreamException * - * @param ResourceStream $stream Cannot typehint, PHP refuse it - * @param int $length + * @param ResourceStream $stream Cannot typehint, PHP refuse it + * @param int $length */ - public function test__readBadResource(ResourceStream $stream, int $length) + public function testReadBadResource(ResourceStream $stream, int $length): void { + $this->expectException(StreamException::class); $stream->read($length); } @@ -169,11 +178,12 @@ class ResourceStreamTest extends TestCase * @covers ::write * @dataProvider writeProvider * - * @param ResourceStream $stream to test - * @param string $toWrite the writed string + * @param ResourceStream $stream to test + * @param string $toWrite the writed string + * * @throws \RouterOS\Exceptions\StreamException */ - public function test__write(ResourceStream $stream, string $toWrite) + public function testWrite(ResourceStream $stream, string $toWrite): void { $this->assertEquals(strlen($toWrite), $stream->write($toWrite)); } @@ -193,13 +203,13 @@ class ResourceStreamTest extends TestCase * * @covers ::write * @dataProvider writeBadResourceProvider - * @expectedException \RouterOS\Exceptions\StreamException * * @param ResourceStream $stream to test * @param string $toWrite the written string */ - public function test__writeBadResource(ResourceStream $stream, string $toWrite) + public function testWriteBadResource(ResourceStream $stream, string $toWrite): void { + $this->expectException(StreamException::class); $stream->write($toWrite); } @@ -219,12 +229,12 @@ class ResourceStreamTest extends TestCase * * @covers ::close * @dataProvider doubleCloseProvider - * @expectedException \RouterOS\Exceptions\StreamException * * @param ResourceStream $stream to test */ - public function test_doubleClose(ResourceStream $stream) + public function testDoubleClose(ResourceStream $stream): void { + $this->expectException(StreamException::class); $stream->close(); $stream->close(); } @@ -242,13 +252,13 @@ class ResourceStreamTest extends TestCase * @covers ::close * @covers ::write * @dataProvider writeClosedResourceProvider - * @expectedException \RouterOS\Exceptions\StreamException * * @param ResourceStream $stream to test * @param string $toWrite the written string */ - public function test_close(ResourceStream $stream, string $toWrite) + public function testClose(ResourceStream $stream, string $toWrite) { + $this->expectException(StreamException::class); $stream->close(); $stream->write($toWrite); } diff --git a/tests/Streams/StringStreamTest.php b/tests/Streams/StringStreamTest.php index 4fb4f1c..9943a5a 100644 --- a/tests/Streams/StringStreamTest.php +++ b/tests/Streams/StringStreamTest.php @@ -19,9 +19,9 @@ class StringStreamTest extends TestCase * @covers ::__construct * @dataProvider constructProvider * - * @param string $string + * @param string $string */ - public function test__construct(string $string) + public function testConstruct(string $string): void { $this->assertInstanceOf(StringStream::class, new StringStream($string)); } @@ -36,19 +36,18 @@ class StringStreamTest extends TestCase ]; } - /** * Test that write function returns the effective written bytes * * @covers ::write * @dataProvider writeProvider * - * @param string $string the string to write - * @param int|null $length the count if bytes to write - * @param int $expected the number of bytes that must be writen + * @param string $string the string to write + * @param int|null $length the count if bytes to write + * @param int $expected the number of bytes that must be writen */ - public function test__write(string $string, $length, int $expected) + public function testWrite(string $string, $length, int $expected): void { $stream = new StringStream('Does not matters'); if (null === $length) { @@ -79,10 +78,10 @@ class StringStreamTest extends TestCase /** * @covers ::write - * @expectedException \InvalidArgumentException */ - public function test__writeWithNegativeLength() + public function testWriteWithNegativeLength(): void { + $this->expectException(\InvalidArgumentException::class); $stream = new StringStream('Does not matters'); $stream->write('PLOP', -1); } @@ -92,7 +91,7 @@ class StringStreamTest extends TestCase * * @throws \RouterOS\Exceptions\StreamException */ - public function test__read() + public function testRead(): void { $stream = new StringStream('123456789'); @@ -105,12 +104,11 @@ class StringStreamTest extends TestCase } /** - * @expectedException \InvalidArgumentException - * * @throws \RouterOS\Exceptions\StreamException */ - public function test__readBadLength() + public function testReadBadLength(): void { + $this->expectException(\InvalidArgumentException::class); $stream = new StringStream('123456789'); $stream->read(-1); } @@ -118,14 +116,15 @@ class StringStreamTest extends TestCase /** * @covers ::read * @dataProvider readWhileEmptyProvider - * @expectedException \RouterOS\Exceptions\StreamException * - * @param StringStream $stream - * @param int $length - * @throws \RouterOS\Exceptions\StreamException + * @param StringStream $stream + * @param int $length + * + * @throws \RouterOS\Exceptions\StreamException */ - public function test__readWhileEmpty(StringStream $stream, int $length) + public function testReadWhileEmpty(StringStream $stream, int $length): void { + $this->expectException(\RouterOS\Exceptions\StreamException::class); $stream->read($length); } @@ -133,7 +132,7 @@ class StringStreamTest extends TestCase * @return \Generator * @throws StreamException */ - public function readWhileEmptyProvider() + public function readWhileEmptyProvider(): ?\Generator { $stream = new StringStream('123456789'); $stream->read(9); @@ -148,11 +147,9 @@ class StringStreamTest extends TestCase yield [$stream, 1]; } - /** - * @expectedException \RouterOS\Exceptions\StreamException - */ - public function testReadClosed() + public function testReadClosed(): void { + $this->expectException(\RouterOS\Exceptions\StreamException::class); $stream = new StringStream('123456789'); $stream->close(); $stream->read(1);