DecoderProviderTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 45
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testSupports() 0 4 1
A providerSupports() 0 7 1
A testGetDecoder() 0 4 1
A testGetDecoderInexistentFormat() 0 4 1
1
<?php
2
3
namespace Seblegall\ApiValidatorBundle\Tests\Decoder;
4
5
use Seblegall\ApiValidatorBundle\Decoder\DecoderProvider;
6
use Seblegall\ApiValidatorBundle\Decoder\JsonDecoder;
7
use Symfony\Component\DependencyInjection\Container;
8
9
class DecoderProviderTest extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * @var DecoderProvider
13
     */
14
    protected $decoderProvider;
15
16
    public function setUp()
17
    {
18
        $container = new Container();
19
        $container->set('api_validator.decoder.json', new JsonDecoder());
20
        $this->decoderProvider = new DecoderProvider(array('json' => 'api_validator.decoder.json'));
21
        $this->decoderProvider->setContainer($container);
22
    }
23
24
    /**
25
     * @dataProvider providerSupports
26
     */
27
    public function testSupports($format, $expected)
28
    {
29
        $this->assertEquals($expected, $this->decoderProvider->supports($format));
30
    }
31
32
    public function providerSupports()
33
    {
34
        return array(
35
            array('json', true),
36
            array('html', false),
37
        );
38
    }
39
40
    public function testGetDecoder()
41
    {
42
        $this->assertInstanceOf('\Seblegall\ApiValidatorBundle\Decoder\JsonDecoder', $this->decoderProvider->getDecoder('json'));
43
    }
44
45
    /**
46
     * @expectedException \InvalidArgumentException
47
     * @expectedExceptionMessage Format 'markdown' is not supported by Seblegall\ApiValidatorBundle\Decoder\DecoderProvider.
48
     */
49
    public function testGetDecoderInexistentFormat()
50
    {
51
        $this->decoderProvider->getDecoder('markdown');
52
    }
53
}
54