DecoderProviderTest::testSupports()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
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