1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Mala 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 Tests; |
13
|
|
|
|
14
|
|
|
use Chrisyue\Mala\M3u8Generator; |
15
|
|
|
use Prophecy\Argument; |
16
|
|
|
|
17
|
|
|
class M3u8GeneratorTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
public function testGenerateWithNoMediaSegments() |
20
|
|
|
{ |
21
|
|
|
$targetDuration = 10; |
22
|
|
|
$msManager = $this->prophesizeMediaSegmentManager(new \DateTime(), $targetDuration, array()); |
23
|
|
|
|
24
|
|
|
$m3u8Generator = new M3u8Generator($msManager->reveal(), array('target_duration' => $targetDuration)); |
25
|
|
|
$m3u8Generator->generate($this->prophesizeChannel()->reveal()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testGenerateWithMediaSegments() |
29
|
|
|
{ |
30
|
|
|
$targetDuration = rand(5, 15); |
31
|
|
|
$programSequence = rand(1, 9999); |
32
|
|
|
$version = rand(2, 3); |
33
|
|
|
$segment = $this->prophesizeMediaSegment(new \DateTime(), $programSequence); |
34
|
|
|
$msManager = $this->prophesizeMediaSegmentManager(new \DateTime(), $targetDuration, array($segment->reveal())); |
35
|
|
|
|
36
|
|
|
$m3u8Generator = new M3u8Generator($msManager->reveal(), array('target_duration' => $targetDuration, 'version' => $version)); |
37
|
|
|
$m3u8 = $m3u8Generator->generate($this->prophesizeChannel()->reveal()); |
38
|
|
|
|
39
|
|
|
$this->assertEquals($m3u8->getTargetDuration(), $targetDuration); |
40
|
|
|
$this->assertEquals($m3u8->getVersion(), $version); |
41
|
|
|
$this->assertEquals($m3u8->getDiscontinuitySequence(), $programSequence); |
42
|
|
|
$this->assertEquals($m3u8->getAge(), 1); // even if program will end at once, the age should be one second |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
private function prophesizeMediaSegmentManager(\DateTime $startsAt, $targetDuration, array $segments) |
46
|
|
|
{ |
47
|
|
|
$msManager = $this->prophesize('Chrisyue\Mala\Manager\MediaSegmentManagerInterface'); |
48
|
|
|
|
49
|
|
|
$now = new \DateTime(); |
|
|
|
|
50
|
|
|
$msManager->findPlaying(Argument::type('Chrisyue\Mala\Model\ChannelInterface'), $startsAt, $targetDuration) |
51
|
|
|
->shouldBeCalledTimes(1)->willReturn($segments); |
52
|
|
|
|
53
|
|
|
return $msManager; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
private function prophesizeChannel() |
57
|
|
|
{ |
58
|
|
|
$channel = $this->prophesize('Chrisyue\Mala\Model\ChannelInterface'); |
59
|
|
|
|
60
|
|
|
return $channel; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private function prophesizeMediaSegment(\DateTime $endsAt, $programSequence) |
64
|
|
|
{ |
65
|
|
|
$mediaSegment = $this->prophesize('Chrisyue\Mala\Model\ScheduledMediaSegment'); |
66
|
|
|
$mediaSegment->getEndsAt()->shouldBeCalledTimes(1)->willReturn($endsAt); |
67
|
|
|
|
68
|
|
|
$program = $this->prophesizeProgram($programSequence); |
69
|
|
|
$mediaSegment->getProgram()->shouldBeCalledTimes(1)->willReturn($program->reveal()); |
70
|
|
|
|
71
|
|
|
return $mediaSegment; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
private function prophesizeProgram($sequence) |
75
|
|
|
{ |
76
|
|
|
$program = $this->prophesize('Chrisyue\Mala\Model\ProgramInterface'); |
77
|
|
|
$program->getSequence()->willReturn($sequence); |
78
|
|
|
|
79
|
|
|
return $program; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
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.