Completed
Pull Request — develop (#27)
by Chris
10:40
created

StreamTest::testReadEmptyLine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Chrisyue\PhpM3u8\Tests\Stream;
4
5
use PHPUnit\Framework\TestCase;
6
use Chrisyue\PhpM3u8\Stream\AbstractStream;
7
8
class StreamTest extends TestCase
9
{
10
    /**
11
     * @dataProvider dataProvider
12
     */
13
    public function testRead($line, $info)
14
    {
15
        $stream = $this->createStream();
16
        $stream->method('getLine')->willReturn($line);
17
        $this->assertSame($info, $stream->read());
18
    }
19
20
    public function testReadEmptyLine()
21
    {
22
        $stream = $this->createStream();
23
        $stream->method('getLine')->willReturn('  ');
24
        $this->assertNull($stream->read());
25
    }
26
27
    public function testReadSameLine()
28
    {
29
        $stream = $this->createStream();
30
        $stream->method('getLine')->willReturn('#TAG');
31
        $stream->expects($this->once())->method('getLineInfo')->with(['#TAG']);
32
        $stream->read();
33
        $stream->read();
34
    }
35
36
    /**
37
     * @dataProvider dataProvider
38
     */
39
    public function testWrite($line, $info)
40
    {
41
        $stream = $this->createStream();
42
        $stream->method('putLine')->with($this->equalTo($line));
43
        $stream->write($info);
44
    }
45
46
    public function dataProvider()
47
    {
48
        return [
49
            ['#TAG:VALUE', ['tag' => '#TAG', 'value' => 'VALUE']],
50
            ['#TAG', ['tag' => '#TAG', 'value' => '']],
51
            ['VALUE', ['value' => 'VALUE']],
52
        ];
53
    }
54
55
    private function createStream()
56
    {
57
        return $this->getMockForAbstractClass(AbstractStream::class);
58
    }
59
}
60