MyBuilderCronosExtensionTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MyBuilder\Bundle\CronosBundle\Tests\DependencyInjection;
4
5
use MyBuilder\Bundle\CronosBundle\DependencyInjection\MyBuilderCronosExtension;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\Config\FileLocator;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\HttpKernel\Kernel;
10
use Symfony\Component\Yaml\Yaml;
11
12
class MyBuilderCronosExtensionTest extends TestCase
13
{
14
    /** @var MyBuilderCronosExtension */
15
    private $loader;
16
17
    /** @var ContainerBuilder */
18
    private $container;
19
20
    protected function setUp(): void
21
    {
22
        $this->container = new ContainerBuilder();
23
        $this->loader = new MyBuilderCronosExtension();
24
    }
25
26
    /**
27
     * @dataProvider providerTestConfig
28
     */
29
    public function test_config(array $expected, string $file): void
30
    {
31
        $this->loader->load($this->getConfig($file), $this->container);
32
33
        static::assertEquals($expected, $this->container->getParameter('mybuilder.cronos_bundle.exporter_config'));
34
    }
35
36
    public function providerTestConfig(): array
37
    {
38
        if (method_exists(Kernel::class, 'getProjectDir')) {
39
            $pathToConsole = '%kernel.project_dir%/bin/console';
40
        } else {
41
            $pathToConsole = '%kernel.root_dir%/../bin/console';
42
        }
43
44
        return [
45
            [
46
                [
47
                    'executor' => 'php',
48
                    'console' => $pathToConsole,
49
                ],
50
                'empty.yml',
51
            ],
52
            [
53
                [
54
                    'key' => 'test',
55
                    'mailto' => '[email protected]',
56
                    'path' => '/bin:/usr/local/bin',
57
                    'executor' => 'php',
58
                    'console' => 'bin/console',
59
                    'shell' => '/bin/bash',
60
                ],
61
                'full.yml',
62
            ],
63
        ];
64
    }
65
66
    /**
67
     * Load the specified yaml config file.
68
     */
69
    private function getConfig(string $fileName): array
70
    {
71
        $locator = new FileLocator(__DIR__ . '/config');
72
        $file = $locator->locate($fileName, null, true);
73
74
        $config = Yaml::parse(file_get_contents($file));
75
76
        if (null === $config) {
77
            return [];
78
        }
79
80
        return $config;
81
    }
82
}
83