1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace MovingImage\Bundle\VMProApiBundle\Tests\DependencyInjection; |
6
|
|
|
|
7
|
|
|
use MovingImage\Bundle\VMProApiBundle\DependencyInjection\VMProApiExtension; |
8
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
10
|
|
|
|
11
|
|
|
class VMProApiExtensionTest extends AbstractTestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Assert whether an exception is thrown when required configuration |
15
|
|
|
* key 'vm_pro_api.credentials' is missing. |
16
|
|
|
*/ |
17
|
|
View Code Duplication |
public function testConfigurationLoadThrowsExceptionUnlessCredentials(): void |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
$this->expectException(InvalidConfigurationException::class); |
20
|
|
|
$loader = new VMProApiExtension(); |
21
|
|
|
$config = $this->getEmptyConfig(); |
22
|
|
|
|
23
|
|
|
unset($config['vm_pro_api']['credentials']); |
24
|
|
|
$loader->load($config, new ContainerBuilder()); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Assert whether an exception is thrown when required configuration |
29
|
|
|
* key 'vm_pro_api.credentials.username' is missing. |
30
|
|
|
*/ |
31
|
|
View Code Duplication |
public function testConfigurationLoadThrowsExceptionUnlessUsername(): void |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$this->expectException(InvalidConfigurationException::class); |
34
|
|
|
$loader = new VMProApiExtension(); |
35
|
|
|
$config = $this->getEmptyConfig(); |
36
|
|
|
|
37
|
|
|
unset($config['vm_pro_api']['credentials']['username']); |
38
|
|
|
$loader->load($config, new ContainerBuilder()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Assert whether an exception is thrown when required configuration |
43
|
|
|
* key 'vm_pro_api.credentials.password' is missing. |
44
|
|
|
*/ |
45
|
|
View Code Duplication |
public function testConfigurationLoadThrowsExceptionUnlessPassword(): void |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$this->expectException(InvalidConfigurationException::class); |
48
|
|
|
$loader = new VMProApiExtension(); |
49
|
|
|
$config = $this->getEmptyConfig(); |
50
|
|
|
|
51
|
|
|
unset($config['vm_pro_api']['credentials']['password']); |
52
|
|
|
$loader->load($config, new ContainerBuilder()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Assert whether the configuration keys and values are successfully |
57
|
|
|
* written as parameters. |
58
|
|
|
*/ |
59
|
|
|
public function testParametersForFullConfig(): void |
60
|
|
|
{ |
61
|
|
|
$container = new ContainerBuilder(); |
62
|
|
|
$loader = new VMProApiExtension(); |
63
|
|
|
$config = $this->getFullConfig(); |
64
|
|
|
|
65
|
|
|
$loader->load($config, $container); |
66
|
|
|
|
67
|
|
|
$this->assertEquals('http://google.com/', $container->getParameter('vm_pro_api_base_url')); |
68
|
|
|
$this->assertEquals(5, $container->getParameter('vm_pro_api_default_vm_id')); |
69
|
|
|
$this->assertEquals('[email protected]', $container->getParameter('vm_pro_api_credentials_username')); |
70
|
|
|
$this->assertEquals('test_password', $container->getParameter('vm_pro_api_credentials_password')); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Assert whether the configuration keys and values are successfully |
75
|
|
|
* written as parameters with the right default values. |
76
|
|
|
*/ |
77
|
|
|
public function testDefaultParameters(): void |
78
|
|
|
{ |
79
|
|
|
$container = new ContainerBuilder(); |
80
|
|
|
$loader = new VMProApiExtension(); |
81
|
|
|
$config = $this->getEmptyConfig(); |
82
|
|
|
|
83
|
|
|
$loader->load($config, $container); |
84
|
|
|
|
85
|
|
|
$this->assertEquals('https://api.video-cdn.net/v1/vms/', $container->getParameter('vm_pro_api_base_url')); |
86
|
|
|
$this->assertEquals(0, $container->getParameter('vm_pro_api_default_vm_id')); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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.