Passed
Pull Request — master (#1)
by Aydin
02:19
created

ResourceInputStreamTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 32
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testNonStream() 0 5 1
A testNotReadable() 0 5 1
A testRead() 0 16 1
1
<?php
2
3
namespace PhpSchool\TerminalTest\IO;
4
5
use PhpSchool\Terminal\IO\ResourceInputStream;
6
use PHPUnit\Framework\TestCase;
7
8
/**
9
 * @author Aydin Hassan <[email protected]>
10
 */
11
class ResourceInputStreamTest extends TestCase
12
{
13
    public function testNonStream() : void
14
    {
15
        $this->expectException(\InvalidArgumentException::class);
16
        $this->expectExceptionMessage('Expected a valid stream');
17
        new ResourceInputStream(42);
18
    }
19
20
    public function testNotReadable() : void
21
    {
22
        $this->expectException(\InvalidArgumentException::class);
23
        $this->expectExceptionMessage('Expected a readable stream');
24
        new ResourceInputStream(\STDOUT);
25
    }
26
27
    public function testRead() : void
28
    {
29
        $stream = fopen('php://memory', 'r+');
30
        fwrite($stream, '1234');
0 ignored issues
show
Bug introduced by
It seems like $stream can also be of type false; however, parameter $handle of fwrite() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
        fwrite(/** @scrutinizer ignore-type */ $stream, '1234');
Loading history...
31
        rewind($stream);
0 ignored issues
show
Bug introduced by
It seems like $stream can also be of type false; however, parameter $handle of rewind() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
        rewind(/** @scrutinizer ignore-type */ $stream);
Loading history...
32
33
        $inputStream = new ResourceInputStream($stream);
34
35
        $input = '';
36
        $inputStream->read(4, function ($buffer) use (&$input) {
37
            $input .= $buffer;
38
        });
39
40
        static::assertSame('1234', $input);
41
42
        fclose($stream);
0 ignored issues
show
Bug introduced by
It seems like $stream can also be of type false; however, parameter $handle of fclose() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
        fclose(/** @scrutinizer ignore-type */ $stream);
Loading history...
43
    }
44
}
45