1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the FreshSinchBundle |
4
|
|
|
* |
5
|
|
|
* (c) Artem Genvald <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Fresh\SinchBundle\Tests\DependencyInjection; |
12
|
|
|
|
13
|
|
|
use Fresh\SinchBundle\DependencyInjection\FreshSinchExtension; |
14
|
|
|
use Symfony\Component\Config\Resource\FileResource; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\Yaml\Parser; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* FreshSinchExtensionTest. |
20
|
|
|
* |
21
|
|
|
* @author Artem Genvald <[email protected]> |
22
|
|
|
* |
23
|
|
|
* @see \Fresh\SinchBundle\DependencyInjection\FreshSinchExtension |
24
|
|
|
*/ |
25
|
|
|
class FreshSinchExtensionTest extends \PHPUnit_Framework_TestCase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var FreshSinchExtension $extension Extension |
29
|
|
|
*/ |
30
|
|
|
private $extension; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var ContainerBuilder $container Container |
34
|
|
|
*/ |
35
|
|
|
private $container; |
36
|
|
|
|
37
|
|
|
protected function setUp() |
38
|
|
|
{ |
39
|
|
|
$this->extension = new FreshSinchExtension(); |
40
|
|
|
$this->container = new ContainerBuilder(); |
41
|
|
|
$this->container->registerExtension($this->extension); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testLoadExtension() |
45
|
|
|
{ |
46
|
|
|
$yaml |
47
|
|
|
= <<<EOF |
48
|
|
|
fresh_sinch: |
49
|
|
|
key: some_dummy_key |
50
|
|
|
secret: some_dummy_secret |
51
|
|
|
EOF; |
52
|
|
|
$parser = new Parser(); |
53
|
|
|
$config = $parser->parse($yaml); |
54
|
|
|
|
55
|
|
|
$this->extension->load($config, $this->container); |
56
|
|
|
$this->container->loadFromExtension($this->extension->getAlias(), $config['fresh_sinch']); |
57
|
|
|
$this->container->set('event_dispatcher', new \stdClass()); // Dummy class |
58
|
|
|
$this->container->compile(); |
59
|
|
|
|
60
|
|
|
// Check loaded resources |
61
|
|
|
$resources = $this->container->getResources(); |
62
|
|
|
$resourceList = []; |
63
|
|
|
foreach ($resources as $resource) { |
64
|
|
|
if ($resource instanceof FileResource) { |
65
|
|
|
$path = $resource->getResource(); |
66
|
|
|
$resourceList[] = substr($path, strrpos($path, '/') + 1); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
$this->assertContains('services.yml', $resourceList); |
70
|
|
|
|
71
|
|
|
// Check auto generated parameters |
72
|
|
|
$this->assertTrue($this->container->hasParameter('sinch.host')); |
73
|
|
|
$this->assertTrue($this->container->hasParameter('sinch.key')); |
74
|
|
|
$this->assertTrue($this->container->hasParameter('sinch.secret')); |
75
|
|
|
$this->assertTrue($this->container->hasParameter('sinch.from')); |
76
|
|
|
|
77
|
|
|
// Check that service has been loaded |
78
|
|
|
$this->assertTrue($this->container->has('sinch')); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|