scratch – Blame information for rev 115
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
115 | office | 1 | <?php |
2 | |||
3 | namespace Tests\FFMpeg\Unit\Format\ProgressListener; |
||
4 | |||
5 | use Tests\FFMpeg\Unit\TestCase; |
||
6 | use FFMpeg\Format\ProgressListener\VideoProgressListener; |
||
7 | use FFMpeg\FFProbe\DataMapping\Format; |
||
8 | |||
9 | class VideoProgressListenerTest extends TestCase |
||
10 | { |
||
11 | /** |
||
12 | * @dataProvider provideData |
||
13 | */ |
||
14 | public function testHandle($size, $duration, |
||
15 | $data, $expectedPercent, $expectedRemaining, $expectedRate, |
||
16 | $data2, $expectedPercent2, $expectedRemaining2, $expectedRate2, |
||
17 | $currentPass, $totalPass |
||
18 | ) |
||
19 | { |
||
20 | $ffprobe = $this->getFFProbeMock(); |
||
21 | $ffprobe->expects($this->once()) |
||
22 | ->method('format') |
||
23 | ->with(__FILE__) |
||
24 | ->will($this->returnValue(new Format(array( |
||
25 | 'size' => $size, |
||
26 | 'duration' => $duration, |
||
27 | )))); |
||
28 | |||
29 | $listener = new VideoProgressListener($ffprobe, __FILE__, $currentPass, $totalPass); |
||
30 | $phpunit = $this; |
||
31 | $n = 0; |
||
32 | $listener->on('progress', function ($percent, $remaining, $rate) use (&$n, $phpunit, $expectedPercent, $expectedRemaining, $expectedRate, $expectedPercent2, $expectedRemaining2, $expectedRate2) { |
||
33 | if (0 === $n) { |
||
34 | $phpunit->assertEquals($expectedPercent, $percent); |
||
35 | $phpunit->assertEquals($expectedRemaining, $remaining); |
||
36 | $phpunit->assertEquals($expectedRate, $rate); |
||
37 | } elseif (1 === $n) { |
||
38 | $phpunit->assertEquals($expectedPercent2, $percent); |
||
39 | $phpunit->assertEquals($expectedRemaining2, $remaining); |
||
40 | $phpunit->assertLessThan($expectedRate2 + 10, $rate); |
||
41 | $phpunit->assertGreaterThan($expectedRate2 - 10, $rate); |
||
42 | } |
||
43 | $n++; |
||
44 | }); |
||
45 | // first one does not trigger progress event |
||
46 | $listener->handle('any-type'.mt_rand(), $data); |
||
47 | sleep(1); |
||
48 | $listener->handle('any-type'.mt_rand(), $data); |
||
49 | sleep(1); |
||
50 | $listener->handle('any-type'.mt_rand(), $data2); |
||
51 | $this->assertEquals(2, $n); |
||
52 | } |
||
53 | |||
54 | public function provideData() |
||
55 | { |
||
56 | return array( |
||
57 | array( |
||
58 | 147073958, |
||
59 | 281.147533, |
||
60 | 'frame= 206 fps=202 q=10.0 size= 571kB time=00:00:07.12 bitrate= 656.8kbits/s dup=9 drop=0', |
||
61 | 2, |
||
62 | 0, |
||
63 | 0, |
||
64 | 'frame= 854 fps=113 q=20.0 size= 4430kB time=00:00:33.04 bitrate=1098.5kbits/s dup=36 drop=0', |
||
65 | 11, |
||
66 | 32, |
||
67 | 3868, |
||
68 | 1, |
||
69 | 1 |
||
70 | ), |
||
71 | array( |
||
72 | 147073958, |
||
73 | 281.147533, |
||
74 | 'frame= 206 fps=202 q=10.0 size= 571kB time=00:00:07.12 bitrate= 656.8kbits/s dup=9 drop=0', |
||
75 | 1, |
||
76 | 0, |
||
77 | 0, |
||
78 | 'frame= 854 fps=113 q=20.0 size= 4430kB time=00:00:33.04 bitrate=1098.5kbits/s dup=36 drop=0', |
||
79 | 5, |
||
80 | 32, |
||
81 | 3868, |
||
82 | 1, |
||
83 | 2 |
||
84 | ) |
||
85 | ); |
||
86 | } |
||
87 | } |