Completed
Push — master ( dd1955...c3a87b )
by Michael
10s
created

ResourceOutputStreamTest::testNotWritable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace PhpSchool\TerminalTest\IO;
4
5
use PhpSchool\Terminal\IO\ResourceOutputStream;
6
use PHPUnit\Framework\TestCase;
7
8
/**
9
 * @author Aydin Hassan <[email protected]>
10
 */
11
class ResourceOutputStreamTest extends TestCase
12
{
13
    public function testNonStream() : void
14
    {
15
        $this->expectException(\InvalidArgumentException::class);
16
        $this->expectExceptionMessage('Expected a valid stream');
17
        new ResourceOutputStream(42);
18
    }
19
20
    public function testNotWritable() : void
21
    {
22
        $this->expectException(\InvalidArgumentException::class);
23
        $this->expectExceptionMessage('Expected a writable stream');
24
        new ResourceOutputStream(\STDIN);
25
    }
26
27
    public function testWrite() : void
28
    {
29
        $stream = fopen('php://memory', 'r+');
30
        $outputStream = new ResourceOutputStream($stream);
31
        $outputStream->write('123456789');
32
33
        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

33
        rewind(/** @scrutinizer ignore-type */ $stream);
Loading history...
34
        static::assertEquals('123456789', stream_get_contents($stream));
0 ignored issues
show
Bug introduced by
It seems like $stream can also be of type false; however, parameter $handle of stream_get_contents() 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

34
        static::assertEquals('123456789', stream_get_contents(/** @scrutinizer ignore-type */ $stream));
Loading history...
35
    }
36
}
37