/**
  * @dataProvider provideData
  */
 public function testHandle($size, $duration, $data, $expectedPercent, $expectedRemaining, $expectedRate, $data2, $expectedPercent2, $expectedRemaining2, $expectedRate2, $currentPass, $totalPass)
 {
     $ffprobe = $this->getFFProbeMock();
     $ffprobe->expects($this->once())->method('format')->with(__FILE__)->will($this->returnValue(new Format(array('size' => $size, 'duration' => $duration))));
     $listener = new AudioProgressListener($ffprobe, __FILE__, $currentPass, $totalPass);
     $phpunit = $this;
     $n = 0;
     $listener->on('progress', function ($percent, $remaining, $rate) use(&$n, $phpunit, $expectedPercent, $expectedRemaining, $expectedRate, $expectedPercent2, $expectedRemaining2, $expectedRate2) {
         if (0 === $n) {
             $phpunit->assertEquals($expectedPercent, $percent);
             $phpunit->assertEquals($expectedRemaining, $remaining);
             $phpunit->assertEquals($expectedRate, $rate);
         } elseif (1 === $n) {
             $phpunit->assertEquals($expectedPercent2, $percent);
             $phpunit->assertEquals($expectedRemaining2, $remaining);
             $phpunit->assertLessThan($expectedRate2 + 3, $rate);
             $phpunit->assertGreaterThan($expectedRate2 - 3, $rate);
         }
         $n++;
     });
     // first one does not trigger progress event
     $listener->handle('any-type' . mt_rand(), $data);
     sleep(1);
     $listener->handle('any-type' . mt_rand(), $data);
     sleep(1);
     $listener->handle('any-type' . mt_rand(), $data2);
     $this->assertEquals(2, $n);
 }
 /**
  * {@inheritdoc}
  */
 public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total)
 {
     $format = $this;
     $listener = new AudioProgressListener($ffprobe, $media->getPathfile(), $pass, $total);
     $listener->on('progress', function () use($media, $format) {
         $format->emit('progress', array_merge(array($media, $format), func_get_args()));
     });
     return array($listener);
 }