Completed
Pull Request — 3.x (#380)
by
unknown
01:21
created

testTemplateTypesWithInvalidValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrineMongoDBAdminBundle\Tests\DependencyInjection;
15
16
use PHPUnit\Framework\TestCase;
17
use Sonata\DoctrineMongoDBAdminBundle\DependencyInjection\Configuration;
18
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
19
use Symfony\Component\Config\Definition\Processor;
20
21
class ConfigurationTest extends TestCase
22
{
23
    public function testDefaultOptions(): void
24
    {
25
        $config = $this->process([]);
26
27
        $this->assertContains(
28
            '@SonataDoctrineMongoDBAdmin/Form/form_admin_fields.html.twig',
29
            $config['templates']['form']
30
        );
31
        $this->assertContains(
32
            '@SonataDoctrineMongoDBAdmin/Form/filter_admin_fields.html.twig',
33
            $config['templates']['filter']
34
        );
35
        $this->assertArrayNotHasKey('types', $config['templates']);
36
    }
37
38
    public function testCustomTemplates(): void
39
    {
40
        $config = $this->process([[
41
            'templates' => [
42
                'form' => ['form.twig.html', 'form_extra.twig.html'],
43
                'filter' => ['filter.twig.html'],
44
                'types' => [
45
                    'list' => [
46
                        'array' => 'list_array.twig.html',
47
                    ],
48
                    'show' => [
49
                        'array' => 'show_array.twig.html',
50
                    ],
51
                ],
52
            ],
53
        ]]);
54
55
        $this->assertSame(['form.twig.html', 'form_extra.twig.html'], $config['templates']['form']);
56
        $this->assertSame(['filter.twig.html'], $config['templates']['filter']);
57
        $this->assertSame([
58
            'list' => [
59
                'array' => 'list_array.twig.html',
60
            ],
61
            'show' => [
62
                'array' => 'show_array.twig.html',
63
            ],
64
        ], $config['templates']['types']);
65
    }
66
67
    public function testTemplateTypesWithInvalidValues(): void
68
    {
69
        $this->expectException(InvalidConfigurationException::class);
70
71
        $this->process([[
72
            'templates' => [
73
                'types' => [
74
                    'edit' => [],
75
                ],
76
            ],
77
        ]]);
78
    }
79
80
    private function process(array $configs): array
81
    {
82
        $processor = new Processor();
83
84
        return $processor->processConfiguration(new Configuration(), $configs);
85
    }
86
}
87