Completed
Push — 1.x ( e997bd )
by Sullivan
19:38
created

SonataDoctrinePHPCRAdminExtensionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 141
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B getDocumentTreeConfigTests() 0 112 1
A setUp() 0 8 1
A testProcessDocumentTreeConfig() 0 12 2
1
<?php
2
3
/*
4
 * This file is part of the Sonata package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\DoctrinePHPCRAdminBundle\Tests\DependencyInjection;
13
14
use Sonata\DoctrinePHPCRAdminBundle\DependencyInjection\SonataDoctrinePHPCRAdminExtension;
15
16
class SonataDoctrinePHPCRAdminExtensionTest extends \PHPUnit_Framework_TestCase
17
{
18
    public function setUp()
19
    {
20
        parent::setUp();
21
        $this->extension = new SonataDoctrinePHPCRAdminExtension();
22
        $refl = new \ReflectionClass($this->extension);
23
        $this->processDocumentTreeConfigMethod = $refl->getMethod('processDocumentTreeConfig');
24
        $this->processDocumentTreeConfigMethod->setAccessible(true);
25
    }
26
27
    public function getDocumentTreeConfigTests()
28
    {
29
        return array(
30
            // Valid expansion of single all
31
            array(
32
                array(
33
                    '\StdClass' => array(
34
                        'valid_children' => array('all')
35
                    )
36
                ),
37
                array(
38
                    '\StdClass' => array(
39
                        'valid_children' => array('\StdClass')
40
                    )
41
                ),
42
            ),
43
            // Expansion with a valid_children array with all and a class
44
            array(
45
                array(
46
                    '\StdClass' => array(
47
                        'valid_children' => array('all', '\StdClass')
48
                    )
49
                ),
50
                array(
51
                    '\StdClass' => array(
52
                        'valid_children' => array('\StdClass')
53
                    )
54
                ),
55
            ),
56
            // Empty config ignored
57
            array(array(), array()),
58
            // Empty valid children
59
            array(
60
                array('\StdClass' => array('valid_children' => array())),
61
                array('\StdClass' => array('valid_children' => array())),
62
            ),
63
            // Ensure all 'all' values do not appear in expanded valid_children
64
            array(
65
                array(
66
                    '\StdClass' => array('valid_children' => array('all')),
67
                    '\SplFileInfo' => array('valid_children' => array('all'))
68
                ),
69
                array(
70
                    '\StdClass' => array('valid_children' => array('\StdClass', '\SplFileInfo')),
71
                    '\SplFileInfo' => array('valid_children' => array('\StdClass', '\SplFileInfo'))
72
                ),
73
            ),
74
            // Allow valid children that are not mapped in the top level
75
            array(
76
                array(
77
                    '\StdClass' => array('valid_children' => array('\SplFileInfo'))
78
                ),
79
                array(
80
                    '\StdClass' => array('valid_children' => array('\SplFileInfo'))
81
                )
82
            ),
83
            // Complex example
84
            array(
85
                array(
86
                    'Doctrine\ODM\PHPCR\Document\Generic' => array('valid_children' => array(
87
                        'all'
88
                    )),
89
                    '\SplFileInfo' => array('valid_children' => array(
90
                        '\StdClass'
91
                    )),
92
                    '\StdClass' => array('valid_children' => array(
93
                        '\StdClass'
94
                    )),
95
                    '\ArrayIterator' => array('valid_children' => array()),
96
                ),
97
                array(
98
                    'Doctrine\ODM\PHPCR\Document\Generic' => array('valid_children' => array(
99
                        'Doctrine\ODM\PHPCR\Document\Generic',
100
                        '\SplFileInfo',
101
                        '\StdClass',
102
                        '\ArrayIterator',
103
                    )),
104
                    '\SplFileInfo' => array('valid_children' => array(
105
                        '\StdClass'
106
                    )),
107
                    '\StdClass' => array('valid_children' => array(
108
                        '\StdClass'
109
                    )),
110
                    '\ArrayIterator' => array('valid_children' => array()),
111
                )
112
            ),
113
            // Exception due to invalid child class
114
            array(
115
                array(
116
                    '\StdClass' => array('valid_children' => array('\Foo\Bar'))
117
                ),
118
                null,
119
                'InvalidArgumentException'
120
            ),
121
            // Exception due to invalid parent class
122
            array(
123
                array(
124
                    'Foo\Bar' => array('valid_children' => array('all'))
125
                ),
126
                null,
127
                'InvalidArgumentException'
128
            ),
129
            // Exception due to invalid class in an array with special 'all' value
130
            array(
131
                array(
132
                    '\StdClass' => array('valid_children' => array('all', 'Foo\Bar'))
133
                ),
134
                null,
135
                'InvalidArgumentException'
136
            ),
137
        );
138
    }
139
140
    /**
141
     * @dataProvider getDocumentTreeConfigTests
142
     */
143
    public function testProcessDocumentTreeConfig($config, $processed, $expectedException = null)
144
    {
145
        if ($expectedException) {
146
            $this->setExpectedException($expectedException);
147
            $this->processDocumentTreeConfigMethod->invokeArgs($this->extension, array($config));
148
        } else {
149
            $this->assertEquals(
150
                $processed,
151
                $this->processDocumentTreeConfigMethod->invokeArgs($this->extension, array($config))
152
            );
153
        }
154
    }
155
156
}
157