1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Chrisyue\PhpM3u8\Tests\M3u8\Core; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Chrisyue\PhpM3u8\M3u8\Core\Tag; |
7
|
|
|
use Chrisyue\PhpM3u8\M3u8\Lines\LinesInterface; |
8
|
|
|
use Chrisyue\PhpM3u8\M3u8\Core\StreamInf; |
9
|
|
|
use Chrisyue\PhpM3u8\Document\Rfc8216; |
10
|
|
|
|
11
|
|
|
class StreamInfTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testParse() |
14
|
|
|
{ |
15
|
|
|
// case 1: stream-inf tag parsed |
16
|
|
|
$uri = 'https://path/to/media'; |
17
|
|
|
$streamInf = new Rfc8216\Tag\StreamInf(); |
18
|
|
|
|
19
|
|
|
$linesProphecy = $this->prophesize(LinesInterface::class); |
20
|
|
|
$linesProphecy->goNext()->shouldBeCalledTimes(1); |
21
|
|
|
// in StreamInf's read method, the LinesInterface::read should be called 1 time; |
22
|
|
|
$linesProphecy->read()->shouldBeCalledTimes(1)->willReturn(['value' => $uri]); |
23
|
|
|
|
24
|
|
|
$tagProphecy = $this->prophesize(Tag::class); |
25
|
|
|
$tagProphecy->setLines($linesProphecy->reveal())->shouldBeCalledTimes(1); |
26
|
|
|
$tagProphecy->parse()->shouldBeCalledTimes(1)->willReturn(clone $streamInf); |
27
|
|
|
|
28
|
|
|
$core = new StreamInf(); |
29
|
|
|
$core->tag = $tagProphecy->reveal(); |
30
|
|
|
$core->setLines($linesProphecy->reveal()); |
31
|
|
|
|
32
|
|
|
$streamInf->uri = $uri; |
33
|
|
|
$this->assertEquals($streamInf, $core->parse()); |
34
|
|
|
|
35
|
|
|
// case 2: non stream-inf tag parsed |
36
|
|
|
$linesProphecy = $this->prophesize(LinesInterface::class); |
37
|
|
|
$linesProphecy->goNext()->shouldBeCalledTimes(0); |
38
|
|
|
$linesProphecy->read()->shouldBeCalledTimes(0); |
39
|
|
|
|
40
|
|
|
$tagProphecy = $this->prophesize(Tag::class); |
41
|
|
|
$tagProphecy->setLines($linesProphecy->reveal())->shouldBeCalledTimes(1); |
42
|
|
|
$tagProphecy->parse()->shouldBeCalledTimes(1)->willReturn(null); |
43
|
|
|
|
44
|
|
|
$core = new StreamInf(); |
45
|
|
|
$core->tag = $tagProphecy->reveal(); |
46
|
|
|
$core->setLines($linesProphecy->reveal()); |
47
|
|
|
|
48
|
|
|
$this->assertNull($core->parse()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testDump() |
52
|
|
|
{ |
53
|
|
|
$uri = 'https://path/to/media'; |
54
|
|
|
$streamInf = new Rfc8216\Tag\StreamInf(); |
55
|
|
|
$streamInf->uri = $uri; |
56
|
|
|
|
57
|
|
|
$value = 'http://path/to/media'; |
|
|
|
|
58
|
|
|
$linesProphecy = $this->prophesize(LinesInterface::class); |
59
|
|
|
$linesProphecy->write(['value' => $uri])->shouldBeCalledTimes(1); |
60
|
|
|
|
61
|
|
|
$tagProphecy = $this->prophesize(Tag::class); |
62
|
|
|
$tagProphecy->setLines($linesProphecy->reveal())->shouldBeCalledTimes(1); |
63
|
|
|
$tagProphecy->dump($streamInf)->shouldBeCalledTimes(1); |
64
|
|
|
|
65
|
|
|
$core = new StreamInf(); |
66
|
|
|
$core->tag = $tagProphecy->reveal(); |
67
|
|
|
$core->setLines($linesProphecy->reveal()); |
68
|
|
|
|
69
|
|
|
$core->dump($streamInf); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.