NetteAdapterForSymfonyBundlesTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 6
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 17 1
A testLoadBundlesEmpty() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Symplify\NetteAdapterForSymfonyBundles\Tests\DI;
6
7
use Nette\DI\Compiler;
8
use Nette\DI\Config\Loader;
9
use Nette\DI\ContainerBuilder;
10
use PHPUnit\Framework\TestCase;
11
use Symplify\NetteAdapterForSymfonyBundles\DI\NetteAdapterForSymfonyBundlesExtension;
12
use Symplify\NetteAdapterForSymfonyBundles\Tests\ContainerFactory;
13
14
final class NetteAdapterForSymfonyBundlesTest extends TestCase
15
{
16
    /**
17
     * @var NetteAdapterForSymfonyBundlesExtension
18
     */
19
    private $extension;
20
21
    protected function setUp()
22
    {
23
        $this->extension = new NetteAdapterForSymfonyBundlesExtension();
24
        $compiler = new Compiler(new ContainerBuilder());
25
        $this->extension->setCompiler($compiler, 'symfonyBundles');
26
27
        // simulates required Nette\Configurator default parameters
28
        $compiler->addConfig([
29
            'parameters' => [
30
                'appDir' => '',
31
                'tempDir' => ContainerFactory::createAndReturnTempDir(),
32
                'debugMode' => true,
33
                'productionMode' => true,
34
                'environment' => '',
35
            ],
36
        ]);
37
    }
38
39
    public function testLoadBundlesEmpty()
40
    {
41
        $bundles = (new Loader())->load(__DIR__ . '/NetteAdapterForSymfonyBundlesSource/bundles.neon');
42
        $this->extension->setConfig($bundles);
0 ignored issues
show
Bug introduced by
It seems like $bundles defined by (new \Nette\DI\Config\Lo...esSource/bundles.neon') on line 41 can also be of type string; however, Nette\DI\CompilerExtension::setConfig() 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...
43
        $this->extension->loadConfiguration();
44
        $this->extension->beforeCompile();
45
46
        $builder = $this->extension->getContainerBuilder();
47
        $this->assertGreaterThan(17, $builder->getDefinitions());
48
    }
49
}
50