Completed
Pull Request — develop (#27)
by Chris
13:09
created

ParserTest::testRead()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 33
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 25
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the PhpM3u8 package.
5
 *
6
 * (c) Chrisyue <http://chrisyue.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Chrisyue\PhpM3u8\tests;
13
14
use PHPUnit\Framework\TestCase;
15
use Chrisyue\PhpM3u8\Parser\Parser;
16
use Chrisyue\PhpM3u8\Parser\PlaylistBuilder;
17
use Chrisyue\PhpM3u8\Parser\PlaylistComponentFactory;
18
use Chrisyue\PhpM3u8\Dumper\Dumper;
19
20
class ParserTest extends TestCase
21
{
22
    public function testRead()
23
    {
24
        $content = DummyM3u8Factory::createM3u8Content(2);
25
26
        $parser = new Parser(new PlaylistBuilder(new PlaylistComponentFactory()));
27
        foreach (explode("\n", $content) as $line) {
28
            $parser->parseLine($line);
29
        }
30
31
        $playlist = $parser->getPlaylist();
32
        $this->assertEquals(2, $playlist->getVersion());
33
        $this->assertEquals(12, $playlist->getTargetduration());
34
        $this->assertEquals(33, $playlist->getMediaSequence());
35
        $this->assertEquals(3, $playlist->getDiscontinuitySequence());
36
37
        $segment = $playlist->getSegments()->offsetGet(0);
38
        $this->assertEquals('AES-128', $segment->getKeys()[0]->getMethod());
39
        $this->assertEquals('com.apple', $segment->getKeys()[1]->getKeyformat());
40
        $this->assertEquals('1', $segment->getKeys()[1]->getKeyformatversions());
41
        $this->assertEquals(12, $segment->getInf()->getDuration());
42
        $this->assertEquals('hello world', $segment->getInf()->getTitle());
43
        $this->assertEquals('stream33.ts', $segment->getUri());
44
        $this->assertEquals(10000, $segment->getByterange()->getLength());
45
        $this->assertEquals(100, $segment->getByterange()->getOffset());
46
        $this->assertFalse($segment->isDiscontinuity());
47
48
        $segment = $playlist->getSegments()->offsetGet(1);
49
        $this->assertEquals(10, $segment->getInf()->getDuration());
50
        $this->assertEquals('video01.ts', $segment->getUri());
51
        $this->assertTrue($segment->isDiscontinuity());
52
53
        $this->assertEquals(22, $playlist->getDuration());
54
    }
55
56
    public function testDump()
57
    {
58
        $playlist = DummyM3u8Factory::createM3u8(3);
59
        // var_dump($playlist); die();
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60
        $dumper = new Dumper();
61
62
        $this->assertEquals(DummyM3u8Factory::createM3u8Content(3), $dumper->dump($playlist));
63
    }
64
}
65
66