1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OrbitaleCmsBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Alexandre Rock Ancelet <[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 Orbitale\Bundle\CmsBundle\Tests\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Orbitale\Bundle\CmsBundle\DependencyInjection\OrbitaleCmsExtension; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\Yaml\Yaml; |
18
|
|
|
use Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Category; |
19
|
|
|
use Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Page; |
20
|
|
|
|
21
|
|
|
class OrbitaleCmsExtensionTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
25
|
|
|
* @expectedExceptionMessage Page class must be a valid class extending Orbitale\Bundle\CmsBundle\Entity\Page. "inexistent_page_class" given. |
26
|
|
|
*/ |
27
|
|
View Code Duplication |
public function testInexistentPageClass() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$builder = new ContainerBuilder(); |
30
|
|
|
|
31
|
|
|
$ext = new OrbitaleCmsExtension(); |
32
|
|
|
|
33
|
|
|
$ext->load([ |
34
|
|
|
'orbitale_cms' => [ |
35
|
|
|
'page_class' => 'inexistent_page_class', |
36
|
|
|
'category_class' => Category::class, |
37
|
|
|
], |
38
|
|
|
], $builder); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
43
|
|
|
* @expectedExceptionMessage Category class must be a valid class extending Orbitale\Bundle\CmsBundle\Entity\Category. "inexistent_category_class" given. |
44
|
|
|
*/ |
45
|
|
View Code Duplication |
public function testInexistentCategoryClass() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$builder = new ContainerBuilder(); |
48
|
|
|
|
49
|
|
|
$ext = new OrbitaleCmsExtension(); |
50
|
|
|
|
51
|
|
|
$ext->load([ |
52
|
|
|
'orbitale_cms' => [ |
53
|
|
|
'page_class' => Page::class, |
54
|
|
|
'category_class' => 'inexistent_category_class', |
55
|
|
|
], |
56
|
|
|
], $builder); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @dataProvider provideYamlConfiguration |
61
|
|
|
* |
62
|
|
|
* @param $config |
63
|
|
|
* @param $expected |
64
|
|
|
*/ |
65
|
|
|
public function testYamlConfiguration($config, $expected) |
66
|
|
|
{ |
67
|
|
|
$builder = new ContainerBuilder(); |
68
|
|
|
|
69
|
|
|
$ext = new OrbitaleCmsExtension(); |
70
|
|
|
|
71
|
|
|
$ext->load($config, $builder); |
72
|
|
|
|
73
|
|
|
static::assertArrayHasKey('orbitale_cms', $expected); |
74
|
|
|
|
75
|
|
|
foreach ($expected['orbitale_cms'] as $key => $expectedValue) { |
76
|
|
|
static::assertEquals($expectedValue, $builder->getParameter('orbitale_cms.'.$key)); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function provideYamlConfiguration(): array |
81
|
|
|
{ |
82
|
|
|
$dir = __DIR__.'/../Fixtures/App/extension_test/'; |
83
|
|
|
|
84
|
|
|
$configFiles = glob($dir.'config_*.yaml'); |
85
|
|
|
$resultFiles = glob($dir.'result_*.yaml'); |
86
|
|
|
|
87
|
|
|
sort($configFiles); |
88
|
|
|
sort($resultFiles); |
89
|
|
|
|
90
|
|
|
$tests = []; |
91
|
|
|
|
92
|
|
|
foreach ($configFiles as $k => $file) { |
93
|
|
|
$tests[] = [ |
94
|
|
|
Yaml::parse(file_get_contents($file)), |
95
|
|
|
Yaml::parse(file_get_contents($resultFiles[$k])), |
96
|
|
|
]; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return $tests; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.