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
|
|
|
class FreshSinchExtensionTest extends \PHPUnit_Framework_TestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var FreshSinchExtension $extension FreshSinchExtension |
27
|
|
|
*/ |
28
|
|
|
private $extension; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var ContainerBuilder $container Container builder |
32
|
|
|
*/ |
33
|
|
|
private $container; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
protected function setUp() |
39
|
|
|
{ |
40
|
|
|
$this->extension = new FreshSinchExtension(); |
41
|
|
|
$this->container = new ContainerBuilder(); |
42
|
|
|
$this->container->registerExtension($this->extension); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Test load extension |
47
|
|
|
*/ |
48
|
|
|
public function testLoadExtension() |
49
|
|
|
{ |
50
|
|
|
$yaml = <<<EOF |
51
|
|
|
fresh_sinch: |
52
|
|
|
key: some_dummy_key |
53
|
|
|
secret: some_dummy_secret |
54
|
|
|
EOF; |
55
|
|
|
$parser = new Parser(); |
56
|
|
|
$config = $parser->parse($yaml); |
57
|
|
|
|
58
|
|
|
$this->extension->load($config, $this->container); |
|
|
|
|
59
|
|
|
$this->container->loadFromExtension($this->extension->getAlias(), $config['fresh_sinch']); |
60
|
|
|
$this->container->compile(); |
61
|
|
|
|
62
|
|
|
// Check loaded resources |
63
|
|
|
$resources = $this->container->getResources(); |
64
|
|
|
$resourceList = []; |
65
|
|
|
foreach ($resources as $resource) { |
66
|
|
|
if ($resource instanceof FileResource) { |
67
|
|
|
$path = $resource->getResource(); |
68
|
|
|
$resourceList[] = substr($path, strrpos($path, 'fresh/sinch-bundle')); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
$this->assertContains('fresh/sinch-bundle/Resources/config/services.yml', $resourceList); |
72
|
|
|
|
73
|
|
|
// Check auto generated parameters |
74
|
|
|
$this->assertTrue($this->container->hasParameter('sinch.host')); |
75
|
|
|
$this->assertTrue($this->container->hasParameter('sinch.key')); |
76
|
|
|
$this->assertTrue($this->container->hasParameter('sinch.secret')); |
77
|
|
|
|
78
|
|
|
// Check that service has been loaded |
79
|
|
|
$this->assertTrue($this->container->has('sinch')); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.