Completed
Pull Request — develop (#27)
by Chris
04:25
created

StreamInfTest::testParse()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 24
nc 1
nop 0
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';
0 ignored issues
show
Unused Code introduced by
$value is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
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