1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Azine\MailgunWebhooksBundle\Tests\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Azine\MailgunWebhooksBundle\DependencyInjection\AzineMailgunWebhooksExtension; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\Yaml\Parser; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* This is the class that loads and manages your bundle configuration. |
11
|
|
|
* |
12
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
13
|
|
|
*/ |
14
|
|
|
class AzineMailgunWebhooksExtensionTest extends \PHPUnit\Framework\TestCase |
15
|
|
|
{ |
16
|
|
|
/** @var ContainerBuilder */ |
17
|
|
|
protected $configuration; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* This should throw an exception. |
21
|
|
|
* |
22
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
23
|
|
|
*/ |
24
|
|
|
public function testEmptyConfig() |
25
|
|
|
{ |
26
|
|
|
$loader = new AzineMailgunWebhooksExtension(); |
27
|
|
|
$config = $this->getEmptyConfig(); |
28
|
|
|
$loader->load(array($config), new ContainerBuilder()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* This should not throw an exception. |
33
|
|
|
*/ |
34
|
|
|
public function testMinimalConfigEmpty() |
35
|
|
|
{ |
36
|
|
|
$this->configuration = new ContainerBuilder(); |
37
|
|
|
$loader = new AzineMailgunWebhooksExtension(); |
38
|
|
|
$config = $this->getMinimalConfig(); |
39
|
|
|
$loader->load(array($config), $this->configuration); |
40
|
|
|
|
41
|
|
|
$this->assertTrue($this->configuration instanceof ContainerBuilder); |
42
|
|
|
$this->assertParameter('someKey_adf4343lki5432543cfcab54325fabiacbzfac', 'azine_mailgun_webhooks_api_key'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testFullConfig() |
46
|
|
|
{ |
47
|
|
|
$this->configuration = new ContainerBuilder(); |
48
|
|
|
$loader = new AzineMailgunWebhooksExtension(); |
49
|
|
|
$config = $this->getFullConfig(); |
50
|
|
|
$loader->load(array($config), $this->configuration); |
51
|
|
|
|
52
|
|
|
$this->assertTrue($this->configuration instanceof ContainerBuilder); |
53
|
|
|
$this->assertParameter('someKey_adf4343lki5432543cfcab54325fabiacbzfac', 'azine_mailgun_webhooks_api_key'); |
54
|
|
|
$this->assertParameter('somePublicKey_adflkiacfcajkhkhkjhkj8767654654bfabiacbzfac', 'azine_mailgun_webhooks_public_api_key'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get a full config for this bundle. |
59
|
|
|
*/ |
60
|
|
|
protected function getFullConfig() |
61
|
|
|
{ |
62
|
|
|
$yaml = <<<EOF |
63
|
|
|
|
64
|
|
|
# api-key |
65
|
|
|
api_key: someKey_adf4343lki5432543cfcab54325fabiacbzfac |
66
|
|
|
|
67
|
|
|
# public api-key |
68
|
|
|
public_api_key: somePublicKey_adflkiacfcajkhkhkjhkj8767654654bfabiacbzfac |
69
|
|
|
|
70
|
|
|
EOF; |
71
|
|
|
$parser = new Parser(); |
72
|
|
|
|
73
|
|
|
return $parser->parse($yaml); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get a the minimal config for this bundle. |
78
|
|
|
*/ |
79
|
|
|
protected function getMinimalConfig() |
80
|
|
|
{ |
81
|
|
|
$yaml = <<<EOF |
82
|
|
|
|
83
|
|
|
# api-key |
84
|
|
|
api_key: someKey_adf4343lki5432543cfcab54325fabiacbzfac |
85
|
|
|
|
86
|
|
|
EOF; |
87
|
|
|
$parser = new Parser(); |
88
|
|
|
|
89
|
|
|
return $parser->parse($yaml); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Get the minimal config. |
94
|
|
|
* |
95
|
|
|
* @return array |
96
|
|
|
*/ |
97
|
|
|
protected function getEmptyConfig() |
98
|
|
|
{ |
99
|
|
|
$yaml = <<<EOF |
100
|
|
|
|
101
|
|
|
EOF; |
102
|
|
|
$parser = new Parser(); |
103
|
|
|
|
104
|
|
|
return $parser->parse($yaml); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param string $value |
109
|
|
|
* @param string $key |
110
|
|
|
*/ |
111
|
|
|
private function assertParameter($value, $key) |
112
|
|
|
{ |
113
|
|
|
$this->assertSame($value, $this->configuration->getParameter($key), sprintf('%s parameter is correct', $key)); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
protected function tearDown() |
117
|
|
|
{ |
118
|
|
|
unset($this->configuration); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|