Completed
Push — master ( cb968d...3d8de1 )
by Artem
02:05
created

FreshSinchExtensionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
B testLoadExtension() 0 33 3
1
<?php
2
/*
3
 * This file is part of the FreshSinchBundle
4
 *
5
 * (c) Artem Genvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Fresh\SinchBundle\Tests\DependencyInjection;
12
13
use Fresh\SinchBundle\DependencyInjection\FreshSinchExtension;
14
use Symfony\Component\Config\Resource\FileResource;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\Yaml\Parser;
17
18
/**
19
 * FreshSinchExtensionTest
20
 *
21
 * @author Artem Genvald <[email protected]>
22
 */
23
class FreshSinchExtensionTest extends \PHPUnit_Framework_TestCase
24
{
25
    /**
26
     * @var FreshSinchExtension $extension FreshSinchExtension
27
     */
28
    private $extension;
29
30
    /**
31
     * @var ContainerBuilder $container Container builder
32
     */
33
    private $container;
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected function setUp()
39
    {
40
        $this->extension = new FreshSinchExtension();
41
        $this->container = new ContainerBuilder();
42
        $this->container->registerExtension($this->extension);
43
    }
44
45
    /**
46
     * Test load extension
47
     */
48
    public function testLoadExtension()
49
    {
50
        $yaml = <<<EOF
51
fresh_sinch:
52
    key: some_dummy_key
53
    secret: some_dummy_secret
54
EOF;
55
        $parser = new Parser();
56
        $config = $parser->parse($yaml);
57
58
        $this->extension->load($config, $this->container);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $parser->parse($yaml) on line 56 can also be of type string; however, Fresh\SinchBundle\Depend...hSinchExtension::load() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
59
        $this->container->loadFromExtension($this->extension->getAlias(), $config['fresh_sinch']);
60
        $this->container->compile();
61
62
        // Check loaded resources
63
        $resources = $this->container->getResources();
64
        $resourceList = [];
65
        foreach ($resources as $resource) {
66
            if ($resource instanceof FileResource) {
67
                $path = $resource->getResource();
68
                $resourceList[] = substr($path, strrpos($path, 'fresh/sinch-bundle'));
69
            }
70
        }
71
        $this->assertContains('fresh/sinch-bundle/Resources/config/services.yml', $resourceList);
72
73
        // Check auto generated parameters
74
        $this->assertTrue($this->container->hasParameter('sinch.host'));
75
        $this->assertTrue($this->container->hasParameter('sinch.key'));
76
        $this->assertTrue($this->container->hasParameter('sinch.secret'));
77
78
        // Check that service has been loaded
79
        $this->assertTrue($this->container->has('sinch'));
80
    }
81
}
82