ConfigurationTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetConfigTreeBuilder() 0 18 1
A testYamlFile() 0 19 1
1
<?php
2
namespace Vresh\TwilioBundle\Tests\DependencyInjection;
3
4
use Symfony\Component\Yaml\Parser;
5
use Vresh\TwilioBundle\DependencyInjection\Configuration;
6
/**
7
 * Test the configuration tree
8
 *
9
 * @author Fridolin Koch <[email protected]>
10
 *
11
 */
12
class ConfigurationTest extends \PHPUnit_Framework_TestCase
13
{
14
    /**
15
     * @test
16
     */
17
    public function testGetConfigTreeBuilder()
18
    {
19
        $config = new Configuration();
20
        /** @var \Symfony\Component\Config\Definition\ArrayNode $node  */
21
        $tree = $config->getConfigTreeBuilder()->buildTree();
22
        //check root name
23
        $this->assertEquals('twilio', $tree->getName());
24
        //get child nodes and check them
25
        /** @var \Symfony\Component\Config\Definition\ScalarNode[] $children  */
26
        $children = $tree->getChildren();
27
        //check length
28
        $this->assertEquals(4, count($children));
29
        //check if all config values are available
30
        $this->assertArrayHasKey('sid', $children);
31
        $this->assertArrayHasKey('authToken', $children);
32
        $this->assertArrayHasKey('version', $children);
33
        $this->assertArrayHasKey('retryAttempts', $children);
34
    }
35
36
    /**
37
     * @test
38
     */
39
    public function testYamlFile()
40
    {
41
        $yaml = new Parser();
42
        $config = $yaml->parse(file_get_contents(realpath(__DIR__ . '/../../Resources/config/services.yml')));
43
        //validate config
44
        $this->assertArrayHasKey('parameters', $config);
45
        $this->assertArrayHasKey('services', $config);
46
        $this->assertArrayHasKey('twilio.api', $config['services']);
47
        $this->assertArrayHasKey('class', $config['services']['twilio.api']);
48
        // capability test
49
        $this->assertArrayHasKey('twilio.capability', $config['services']);
50
        $this->assertArrayHasKey('class', $config['services']['twilio.capability']);
51
        $this->assertArrayHasKey(str_replace('%', '', $config['services']['twilio.capability']['class']), $config['parameters']);
52
        $this->assertArrayHasKey(str_replace('%', '', $config['services']['twilio.api']['class']), $config['parameters']);
53
        // lookups
54
        $this->assertArrayHasKey('twilio.lookups', $config['services']);
55
        $this->assertArrayHasKey('class', $config['services']['twilio.lookups']);
56
        $this->assertArrayHasKey(str_replace('%', '', $config['services']['twilio.lookups']['class']), $config['parameters']);
57
    }
58
}
59