scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 1 <?php
2  
3 namespace Tests\FFMpeg\Unit\FFProbe;
4  
5 use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
6 use Tests\FFMpeg\Unit\TestCase;
7 use FFMpeg\FFProbe\OptionsTester;
8  
9 class OptionsTesterTest extends TestCase
10 {
11 /**
12 * @expectedException FFMpeg\Exception\RuntimeException
13 * @expectedExceptionMessage Your FFProbe version is too old and does not support `-help` option, please upgrade.
14 */
15 public function testHasOptionWithOldFFProbe()
16 {
17 $cache = $this->getCacheMock();
18  
19 $ffprobe = $this->getFFProbeDriverMock();
20 $ffprobe->expects($this->once())
21 ->method('command')
22 ->with(array('-help', '-loglevel', 'quiet'))
23 ->will($this->throwException(new ExecutionFailureException('Failed to execute')));
24  
25 $tester = new OptionsTester($ffprobe, $cache);
26 $tester->has('-print_format');
27 }
28  
29 /**
30 * @dataProvider provideOptions
31 */
32 public function testHasOptionWithCacheEmpty($isPresent, $data, $optionName)
33 {
34 $cache = $this->getCacheMock();
35  
36 $cache->expects($this->never())
37 ->method('fetch');
38  
39 $cache->expects($this->exactly(2))
40 ->method('contains')
41 ->will($this->returnValue(false));
42  
43 $cache->expects($this->exactly(2))
44 ->method('save');
45  
46 $ffprobe = $this->getFFProbeDriverMock();
47 $ffprobe->expects($this->once())
48 ->method('command')
49 ->with(array('-help', '-loglevel', 'quiet'))
50 ->will($this->returnValue($data));
51  
52 $tester = new OptionsTester($ffprobe, $cache);
53 $this->assertTrue($isPresent === $tester->has($optionName));
54 }
55  
56 public function provideOptions()
57 {
58 $data = file_get_contents(__DIR__ . '/../../fixtures/ffprobe/help.raw');
59  
60 return array(
61 array(true, $data, '-print_format'),
62 array(false, $data, '-another_print_format'),
63 );
64 }
65  
66 /**
67 * @dataProvider provideOptions
68 */
69 public function testHasOptionWithHelpCacheLoaded($isPresent, $data, $optionName)
70 {
71 $cache = $this->getCacheMock();
72  
73 $cache->expects($this->once())
74 ->method('fetch')
75 ->will($this->returnValue($data));
76  
77 $cache->expects($this->at(0))
78 ->method('contains')
79 ->will($this->returnValue(false));
80  
81 $cache->expects($this->at(1))
82 ->method('contains')
83 ->will($this->returnValue(true));
84  
85 $cache->expects($this->once())
86 ->method('save');
87  
88 $ffprobe = $this->getFFProbeDriverMock();
89 $ffprobe->expects($this->never())
90 ->method('command');
91  
92 $tester = new OptionsTester($ffprobe, $cache);
93 $this->assertTrue($isPresent === $tester->has($optionName));
94 }
95  
96 /**
97 * @dataProvider provideOptions
98 */
99 public function testHasOptionWithCacheFullyLoaded($isPresent, $data, $optionName)
100 {
101 $cache = $this->getCacheMock();
102  
103 $cache->expects($this->once())
104 ->method('fetch')
105 ->with('option-' . $optionName)
106 ->will($this->returnValue($isPresent));
107  
108 $cache->expects($this->once())
109 ->method('contains')
110 ->with('option-' . $optionName)
111 ->will($this->returnValue(true));
112  
113 $ffprobe = $this->getFFProbeDriverMock();
114 $ffprobe->expects($this->never())
115 ->method('command');
116  
117 $tester = new OptionsTester($ffprobe, $cache);
118 $this->assertTrue($isPresent === $tester->has($optionName));
119 }
120 }