These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\ConfigBundle\Tests\DependencyInjection; |
||
4 | |||
5 | use Kunstmaan\ConfigBundle\DependencyInjection\Configuration; |
||
6 | use Kunstmaan\ConfigBundle\Entity\ConfigurationInterface; |
||
7 | use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; |
||
8 | use PHPUnit\Framework\TestCase; |
||
9 | |||
10 | /** |
||
11 | * Class ConfigurationTest |
||
12 | */ |
||
13 | class ConfigurationTest extends TestCase |
||
14 | { |
||
15 | use ConfigurationTestCaseTrait; |
||
16 | |||
17 | /** |
||
18 | * @return \Symfony\Component\Config\Definition\ConfigurationInterface |
||
19 | */ |
||
20 | protected function getConfiguration() |
||
21 | { |
||
22 | return new Configuration(); |
||
23 | } |
||
24 | |||
25 | public function testConfigGeneratesAsExpected() |
||
26 | { |
||
27 | $array = [ |
||
28 | 'entities' => [], |
||
29 | ]; |
||
30 | |||
31 | $this->assertProcessedConfigurationEquals([$array], $array); |
||
32 | } |
||
33 | |||
34 | public function testConfigDoesntGenerateAsExpected() |
||
35 | { |
||
36 | $this->assertPartialConfigurationIsInvalid([['fail']], 'entities'); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @expectedException \InvalidArgumentException |
||
41 | * @expectedExceptionMessage Entity "App\UndefinedEntity" does not exist |
||
42 | */ |
||
43 | public function testConfigUndefinedEntity() |
||
44 | { |
||
45 | $array = [ |
||
46 | 'entities' => [ |
||
47 | 'App\\UndefinedEntity', |
||
48 | ], |
||
49 | ]; |
||
50 | |||
51 | $this->assertProcessedConfigurationEquals([$array], $array); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @expectedException \RuntimeException |
||
56 | * @expectedExceptionMessage The entity class "Kunstmaan\ConfigBundle\Tests\DependencyInjection\InvalidConfigEntity" needs to implement the Kunstmaan\ConfigBundle\Entity\ConfigurationInterface |
||
57 | */ |
||
58 | public function testConfigInvalidEntity() |
||
59 | { |
||
60 | $array = [ |
||
61 | 'entities' => [ |
||
62 | InvalidConfigEntity::class, |
||
63 | ], |
||
64 | ]; |
||
65 | |||
66 | $this->assertProcessedConfigurationEquals([$array], $array); |
||
67 | } |
||
68 | |||
69 | public function testConfigValidEntity() |
||
70 | { |
||
71 | $array = [ |
||
72 | 'entities' => [ |
||
73 | ValidConfigEntity::class, |
||
74 | ], |
||
75 | ]; |
||
76 | |||
77 | $this->assertProcessedConfigurationEquals([$array], $array); |
||
78 | } |
||
79 | } |
||
80 | |||
81 | class ValidConfigEntity implements ConfigurationInterface |
||
0 ignored issues
–
show
|
|||
82 | { |
||
83 | public function getDefaultAdminType() |
||
84 | { |
||
85 | return 'whatever'; |
||
86 | } |
||
87 | |||
88 | public function getInternalName() |
||
89 | { |
||
90 | return 'whatever'; |
||
91 | } |
||
92 | |||
93 | public function getLabel() |
||
94 | { |
||
95 | return 'whatever'; |
||
96 | } |
||
97 | |||
98 | public function getRoles() |
||
99 | { |
||
100 | return []; |
||
101 | } |
||
102 | } |
||
103 | |||
104 | class InvalidConfigEntity |
||
0 ignored issues
–
show
|
|||
105 | { |
||
106 | } |
||
107 |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.