Completed
Pull Request — develop (#27)
by Chris
02:23
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 Chrisyue\PhpM3u8\Document\Rfc8216;
6
use Chrisyue\PhpM3u8\M3u8\Core\StreamInf;
7
use Chrisyue\PhpM3u8\M3u8\Core\Tag;
8
use Chrisyue\PhpM3u8\M3u8\Lines\LinesInterface;
9
use PHPUnit\Framework\TestCase;
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
        $linesProphecy = $this->prophesize(LinesInterface::class);
58
        $linesProphecy->write(['value' => $uri])->shouldBeCalledTimes(1);
59
60
        $tagProphecy = $this->prophesize(Tag::class);
61
        $tagProphecy->setLines($linesProphecy->reveal())->shouldBeCalledTimes(1);
62
        $tagProphecy->dump($streamInf)->shouldBeCalledTimes(1);
63
64
        $core = new StreamInf();
65
        $core->tag = $tagProphecy->reveal();
66
        $core->setLines($linesProphecy->reveal());
67
68
        $core->dump($streamInf);
69
    }
70
}
71