|
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
|
|
|
|