Completed
Push — master-dev-kit ( 6ecaed...1e7a30 )
by Grégoire
03:42 queued 01:57
created

testAuditForceWithInvalidFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
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\DoctrineORMAdminBundle\Tests;
15
16
use PHPUnit\Framework\TestCase;
17
use Sonata\DoctrineORMAdminBundle\DependencyInjection\Configuration;
18
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
19
use Symfony\Component\Config\Definition\Exception\InvalidTypeException;
20
use Symfony\Component\Config\Definition\Processor;
21
22
class ConfigurationTest extends TestCase
23
{
24
    public function testDefaultOptions(): void
25
    {
26
        $config = $this->process([]);
27
28
        $this->assertNull($config['entity_manager']);
29
        $this->assertTrue($config['audit']['force']);
30
        $this->assertArraySubset(['@SonataDoctrineORMAdmin/Form/form_admin_fields.html.twig'], $config['templates']['form']);
31
        $this->assertArraySubset(['@SonataDoctrineORMAdmin/Form/filter_admin_fields.html.twig'], $config['templates']['filter']);
32
        $this->assertArrayNotHasKey('types', $config['templates']);
33
    }
34
35
    public function testAuditForceWithInvalidFormat(): void
36
    {
37
        $this->expectException(InvalidTypeException::class);
38
39
        $this->process([[
40
            'audit' => [
41
                'force' => '1',
42
            ],
43
        ]]);
44
    }
45
46
    public function testCustomTemplates(): void
47
    {
48
        $config = $this->process([[
49
            'templates' => [
50
                'form' => ['form.twig.html', 'form_extra.twig.html'],
51
                'filter' => ['filter.twig.html'],
52
                'types' => [
53
                    'list' => [
54
                        'array' => 'list_array.twig.html',
55
                    ],
56
                    'show' => [
57
                        'array' => 'show_array.twig.html',
58
                    ],
59
                ],
60
            ],
61
        ]]);
62
63
        $this->assertSame(['form.twig.html', 'form_extra.twig.html'], $config['templates']['form']);
64
        $this->assertSame(['filter.twig.html'], $config['templates']['filter']);
65
        $this->assertSame([
66
            'list' => [
67
                'array' => 'list_array.twig.html',
68
            ],
69
            'show' => [
70
                'array' => 'show_array.twig.html',
71
            ],
72
        ], $config['templates']['types']);
73
    }
74
75
    public function testTemplateTypesWithInvalidValues(): void
76
    {
77
        $this->expectException(InvalidConfigurationException::class);
78
79
        $this->process([[
80
            'templates' => [
81
                'types' => [
82
                    'edit' => [],
83
                ],
84
            ],
85
        ]]);
86
    }
87
88
    /**
89
     * Processes an array of configurations and returns a compiled version.
90
     *
91
     * @param array $configs An array of raw configurations
92
     *
93
     * @return array A normalized array
94
     */
95
    protected function process($configs)
96
    {
97
        $processor = new Processor();
98
99
        return $processor->processConfiguration(new Configuration(), $configs);
100
    }
101
}
102