FFMpegProviderTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 102
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 46 2
A tearDown() 0 6 1
A testDurationIsValid() 0 4 1
A testHeightIsValid() 0 4 1
A testWidthIsValid() 0 4 1
A testRuntimeException() 0 11 1
1
<?php
2
3
namespace Toa\Component\Validator\Tests\Provider;
4
5
use Toa\Component\Validator\Provider\FFMpegProvider;
6
7
/**
8
 * Class FFMpegProviderTest
9
 *
10
 * @author Enrico Thies <[email protected]>
11
 */
12
class FFMpegProviderTest extends \PHPUnit_Framework_TestCase
13
{
14
    protected $ffmpeg;
15
    protected $provider;
16
    protected $video;
17
18
    protected function setUp()
19
    {
20
        if (!class_exists('FFMpeg\FFMpeg')) {
21
            $this->markTestSkipped('The "FFMpeg" component is not available');
22
        }
23
24
        $this->video = __DIR__.'/../Constraints/Fixtures/white.m4v';
25
26
        $streamMock = $this->getMockForAbstractClass(
27
            'FFMpeg\FFProbe\DataMapping\AbstractData',
28
            array(
29
                array(
30
                    'duration' => 11.516667,
31
                    'height' => 240,
32
                    'width' => 480,
33
                )
34
            )
35
        );
36
37
        $streamCollectionMock = $this->getMock('FFMpeg\FFProbe\DataMapping\StreamCollection');
38
        $streamCollectionMock
39
            ->expects($this->any())
40
            ->method('first')
41
            ->will($this->returnValue($streamMock));
42
43
        $abstractStreamableMediaMock = $this->getMock(
44
            'FFMpeg\Media\AbstractStreamableMedia',
45
            array(),
46
            array(),
47
            '',
48
            false
49
        );
50
        $abstractStreamableMediaMock
51
            ->expects($this->any())
52
            ->method('getStreams')
53
            ->will($this->returnValue($streamCollectionMock));
54
55
        $this->ffmpeg = $this->getMock('FFMpeg\FFMpeg', array(), array(), '', false);
56
        $this->ffmpeg
57
            ->expects($this->any())
58
            ->method('open')
59
            ->will($this->returnValue($abstractStreamableMediaMock));
60
61
62
        $this->provider = new FFMpegProvider($this->ffmpeg);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    protected function tearDown()
69
    {
70
        $this->ffmpeg = null;
71
        $this->provider = null;
72
        $this->video = null;
73
    }
74
75
    /**
76
     * @test
77
     */
78
    public function testDurationIsValid()
79
    {
80
        $this->assertEquals(11.516667, $this->provider->getDuration($this->video));
81
    }
82
83
    /**
84
     * @test
85
     */
86
    public function testHeightIsValid()
87
    {
88
        $this->assertEquals(240, $this->provider->getHeight($this->video));
89
    }
90
91
    /**
92
     * @test
93
     */
94
    public function testWidthIsValid()
95
    {
96
        $this->assertEquals(480, $this->provider->getWidth($this->video));
97
    }
98
99
    /**
100
     * @expectedException \Toa\Component\Validator\Exception\ProviderException
101
     */
102
    public function testRuntimeException()
103
    {
104
        $this->ffmpeg
105
            ->expects($this->once())
106
            ->method('open')
107
            ->with($this->video)
108
            ->will($this->throwException(new \RuntimeException()));
109
110
111
        $this->provider->getDuration($this->video);
112
    }
113
}
114