@ -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__c onstructNotResource ( $notResource )
public function testC onstructNotResource ( $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_c onstruct ( $resource , bool $closeResource = true )
public function testC onstruct ( $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 );
@ -91,10 +98,11 @@ class ResourceStreamTest extends TestCase
*
* @ 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__r ead ( ResourceStream $stream , string $expected )
public function testR ead ( 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
*
* @ throws \RouterOS\Exceptions\StreamException
* @ throws \InvalidArgumentException
*/
public function test__r eadBadLength ( ResourceStream $stream , int $length )
public function testR eadBadLength ( 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
*/
public function test__r eadBadResource ( ResourceStream $stream , int $length )
public function testR eadBadResource ( ResourceStream $stream , int $length ) : void
{
$this -> expectException ( StreamException :: class );
$stream -> read ( $length );
}
@ -171,9 +180,10 @@ class ResourceStreamTest extends TestCase
*
* @ param ResourceStream $stream to test
* @ param string $toWrite the writed string
*
* @ throws \RouterOS\Exceptions\StreamException
*/
public function test__w rite ( ResourceStream $stream , string $toWrite )
public function testW rite ( 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__w riteBadResource ( ResourceStream $stream , string $toWrite )
public function testW riteBadResource ( 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_d oubleClose ( ResourceStream $stream )
public function testD oubleClose ( 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_c lose ( ResourceStream $stream , string $toWrite )
public function testC lose ( ResourceStream $stream , string $toWrite )
{
$this -> expectException ( StreamException :: class );
$stream -> close ();
$stream -> write ( $toWrite );
}