Completed
Push — master ( e4a43c...c6b5e7 )
by Tomáš
15:17
created

testLoadBundlesEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Symplify\NetteAdapterForSymfonyBundles\Tests;
4
5
use Nette\DI\Compiler;
6
use Nette\DI\Config\Loader;
7
use Nette\DI\ContainerBuilder;
8
use PHPUnit\Framework\TestCase;
9
use Symplify\NetteAdapterForSymfonyBundles\DI\NetteAdapterForSymfonyBundlesExtension;
10
11
final class NetteAdapterForSymfonyBundlesTest extends TestCase
12
{
13
    /**
14
     * @var NetteAdapterForSymfonyBundlesExtension
15
     */
16
    private $extension;
17
18
    protected function setUp()
19
    {
20
        $this->extension = new NetteAdapterForSymfonyBundlesExtension();
21
        $compiler = new Compiler(new ContainerBuilder());
22
        $this->extension->setCompiler($compiler, 'symfonyBundles');
23
24
        // simulates required Nette\Configurator default parameters
25
        $compiler->addConfig([
26
            'parameters' => [
27
                'appDir' => '',
28
                'tempDir' => ContainerFactory::createAndReturnTempDir(),
29
                'debugMode' => true,
30
                'productionMode' => true,
31
                'environment' => '',
32
            ],
33
        ]);
34
    }
35
36
    public function testLoadBundlesEmpty()
37
    {
38
        $bundles = (new Loader())->load(__DIR__.'/NetteAdapterForSymfonyBundlesSource/bundles.neon');
39
        $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 38 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...
40
        $this->extension->loadConfiguration();
41
        $this->extension->beforeCompile();
42
43
        $builder = $this->extension->getContainerBuilder();
44
        $this->assertGreaterThan(17, $builder->getDefinitions());
45
    }
46
}
47