scratch – Blame information for rev 115

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 1 <?php
2  
3 namespace Tests\FFMpeg\Unit;
4  
5 use FFMpeg\FFMpeg;
6 use FFMpeg\FFProbe\DataMapping\StreamCollection;
7 use FFMpeg\FFProbe\DataMapping\Stream;
8  
9 class FFMpegTest extends TestCase
10 {
11 /**
12 * @expectedException \FFMpeg\Exception\RuntimeException
13 * @expectedExceptionMessage Unable to probe "/path/to/unknown/file".
14 */
15 public function testOpenInvalid()
16 {
17 $ffmpeg = new FFMpeg($this->getFFMpegDriverMock(), $this->getFFProbeMock());
18 $ffmpeg->open('/path/to/unknown/file');
19 }
20  
21 public function testOpenAudio()
22 {
23 $streams = $this->getStreamCollectionMock();
24 $streams->expects($this->once())
25 ->method('audios')
26 ->will($this->returnValue(new StreamCollection(array(new Stream(array())))));
27 $streams->expects($this->once())
28 ->method('videos')
29 ->will($this->returnValue(array()));
30  
31 $ffprobe = $this->getFFProbeMock();
32 $ffprobe->expects($this->once())
33 ->method('streams')
34 ->with(__FILE__)
35 ->will($this->returnValue($streams));
36  
37 $ffmpeg = new FFMpeg($this->getFFMpegDriverMock(), $ffprobe);
38 $this->assertInstanceOf('FFMpeg\Media\Audio', $ffmpeg->open(__FILE__));
39 }
40  
41 public function testOpenVideo()
42 {
43 $streams = $this->getStreamCollectionMock();
44 $streams->expects($this->once())
45 ->method('videos')
46 ->will($this->returnValue(new StreamCollection(array(new Stream(array())))));
47 $streams->expects($this->never())
48 ->method('audios');
49  
50 $ffprobe = $this->getFFProbeMock();
51 $ffprobe->expects($this->once())
52 ->method('streams')
53 ->with(__FILE__)
54 ->will($this->returnValue($streams));
55  
56 $ffmpeg = new FFMpeg($this->getFFMpegDriverMock(), $ffprobe);
57 $this->assertInstanceOf('FFMpeg\Media\Video', $ffmpeg->open(__FILE__));
58 }
59  
60 /**
61 * @expectedException \FFMpeg\Exception\InvalidArgumentException
62 */
63 public function testOpenUnknown()
64 {
65 $ffprobe = $this->getFFProbeMock();
66 $ffprobe->expects($this->once())
67 ->method('streams')
68 ->with(__FILE__)
69 ->will($this->returnValue(new StreamCollection()));
70  
71 $ffmpeg = new FFMpeg($this->getFFMpegDriverMock(), $ffprobe);
72 $ffmpeg->open(__FILE__);
73 }
74  
75 public function testCreateWithoutLoggerOrProbe()
76 {
77 $this->assertInstanceOf('FFMpeg\FFMpeg', FFMpeg::create());
78 }
79  
80 public function testCreateWithLoggerAndProbe()
81 {
82 $logger = $this->getLoggerMock();
83 $ffprobe = $this->getFFProbeMock();
84  
85 $ffmpeg = FFMpeg::create(array('timeout' => 42), $logger, $ffprobe);
86 $this->assertInstanceOf('FFMpeg\FFMpeg', $ffmpeg);
87  
88 $this->assertSame($logger, $ffmpeg->getFFMpegDriver()->getProcessRunner()->getLogger());
89 $this->assertSame($ffprobe, $ffmpeg->getFFProbe());
90 $this->assertSame(42, $ffmpeg->getFFMpegDriver()->getProcessBuilderFactory()->getTimeout());
91 }
92  
93 public function testGetSetFFProbe()
94 {
95 $ffprobe = $this->getFFProbeMock();
96 $ffmpeg = new FFMpeg($this->getFFMpegDriverMock(), $ffprobe);
97 $this->assertSame($ffprobe, $ffmpeg->getFFProbe());
98 $anotherFFProbe = $this->getFFProbeMock();
99 $ffmpeg->setFFProbe($anotherFFProbe);
100 $this->assertSame($anotherFFProbe, $ffmpeg->getFFProbe());
101 }
102  
103 public function testGetSetDriver()
104 {
105 $driver = $this->getFFMpegDriverMock();
106 $ffmpeg = new FFMpeg($driver, $this->getFFProbeMock());
107 $this->assertSame($driver, $ffmpeg->getFFMpegDriver());
108 $anotherDriver = $this->getFFMpegDriverMock();
109 $ffmpeg->setFFMpegDriver($anotherDriver);
110 $this->assertSame($anotherDriver, $ffmpeg->getFFMpegDriver());
111 }
112 }