1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BestIt\KitchensinkBundle\Tests\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use BestIt\KitchensinkBundle\DependencyInjection\BestItKitchensinkExtension; |
6
|
|
|
use BestIt\KitchensinkBundle\Tests\ContainerProviderTrait; |
7
|
|
|
use BestIt\KitchensinkBundle\Tests\DataProviderFake; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class BestItKitchensinkExtensionTest |
12
|
|
|
* @author blange <[email protected]> |
13
|
|
|
* @category Tests |
14
|
|
|
* @package BestIt\KitchensinkBundle |
15
|
|
|
* @subpackage DependencyInjection |
16
|
|
|
* @version $id$ |
17
|
|
|
*/ |
18
|
|
|
class BestItKitchensinkExtensionTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
use ContainerProviderTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The used prefix in the bundle. |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
const BUNDLE_PREFIX = 'best_it_kitchensink'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Returns some rules for the config value tests. |
30
|
|
|
* @return array |
31
|
|
|
*/ |
32
|
|
|
public function getConfigValueAssertions(): array |
33
|
|
|
{ |
34
|
|
|
return [ |
35
|
|
|
// key, wrong value, is required |
36
|
|
|
['data_provider', mt_rand(0, 1000), true], |
37
|
|
|
['template', null], |
38
|
|
|
]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Checks the config value. |
43
|
|
|
* @dataProvider getConfigValueAssertions |
44
|
|
|
* @param string $key |
45
|
|
|
*/ |
46
|
|
|
public function testConfigValue(string $key) |
47
|
|
|
{ |
48
|
|
|
$config = $this->getFullConfig(); |
49
|
|
|
|
50
|
|
|
$container = $this->getFullyLoadedContainer($config); |
51
|
|
|
|
52
|
|
|
static::assertTrue( |
53
|
|
|
$container->hasParameter(self::BUNDLE_PREFIX . '.' . $key), |
54
|
|
|
'Parameter is missing.' |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
static::assertSame( |
58
|
|
|
$config[self::BUNDLE_PREFIX][$key], |
59
|
|
|
$container->getParameter(self::BUNDLE_PREFIX . '.' . $key), |
60
|
|
|
'Value was wrong.' |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Checks if the data provider is loaded. |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function testDataProviderInstance() |
69
|
|
|
{ |
70
|
|
|
$container = $this->getFullyLoadedContainer(); |
71
|
|
|
|
72
|
|
|
static::assertTrue($container->hasAlias(self::BUNDLE_PREFIX . '.data_provider')); |
73
|
|
|
static::assertInstanceOf(DataProviderFake::class, $container->get(self::BUNDLE_PREFIX . '.data_provider')); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Checks the default value of the template. |
78
|
|
|
* @covers BestItKitchensinkExtension::load() |
79
|
|
|
* @covers Configuration::getConfigTreeBuilder() |
80
|
|
|
* @return void |
81
|
|
|
*/ |
82
|
|
|
public function testTemplateDefaultValue() |
83
|
|
|
{ |
84
|
|
|
$config = $this->getFullConfig(); |
85
|
|
|
|
86
|
|
|
unset($config[self::BUNDLE_PREFIX]['template']); |
87
|
|
|
|
88
|
|
|
$container = $this->getFullyLoadedContainer($config); |
89
|
|
|
|
90
|
|
|
static::assertTrue($container->hasParameter(self::BUNDLE_PREFIX . '.template')); |
91
|
|
|
static::assertSame('kitchensink/index.html.twig', $container->getParameter(self::BUNDLE_PREFIX . '.template')); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|