forked from jgmullor/AzureDistributionBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContainerTest.php
160 lines (135 loc) · 5.98 KB
/
ContainerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* WindowsAzure DistributionBundle
*
* LICENSE
*
* This source file is subject to the MIT license that is bundled
* with this package in the file LICENSE.txt.
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
namespace WindowsAzure\DistributionBundle\Tests;
use WindowsAzure\DistributionBundle\DependencyInjection\WindowsAzureDistributionExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension;
use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass;
class ContainerTest extends \PHPUnit_Framework_TestCase
{
public function testAzureSdkCommandBuilder()
{
$container = $this->createContainer();
$service = $container->get('windows_azure_distribution.deployment.azure_sdk_command_builder');
$this->assertInstanceOf('WindowsAzure\DistributionBundle\Deployment\AzureSDKCommandBuilder', $service);
}
public function testDeploymentService()
{
$container = $this->createContainer();
$deployment = $container->get('windows_azure_distribution.deployment');
$this->assertInstanceOf('WindowsAzure\DistributionBundle\Deployment\AzureDeployment', $deployment);
}
public function testServices()
{
$config = array(
'services' => array(
'blob' => array(
'test' => 'UseDevelopmentStorage=true',
),
'queue' => array(
'test2' => 'DefaultEndpointsProtocol=[http|https];AccountName=[yourAccount];AccountKey=[yourKey]'
),
'table' => array(
'test3' => 'DefaultEndpointsProtocol=[http|https];AccountName=[yourAccount];AccountKey=[yourKey]'
),
'service_bus' => array(
'test4' => 'Endpoint=[yourEndpoint];SharedSecretIssuer=[yourWrapAuthenticationName];SharedSecretValue=[yourWrapPassword]',
),
'management' => array(
'test5' => 'SubscriptionID=[yourSubscriptionId];CertificatePath=[filePathToYourCertificate]',
),
),
);
$container = $this->createContainer($config);
$this->assertTrue($container->has('windows_azure.blob.test'));
$this->assertTrue($container->has('windows_azure.queue.test2'));
$this->assertTrue($container->has('windows_azure.table.test3'));
$this->assertTrue($container->has('windows_azure.service_bus.test4'));
$this->assertTrue($container->has('windows_azure.management.test5'));
$this->assertInstanceOf('WindowsAzure\Blob\BlobRestProxy', $container->get('windows_azure.blob.test'));
}
public function testAssets()
{
$config = array(
'services' => array(
'blob' => array(
'test' => 'UseDevelopmentStorage=true',
),
),
'assets' => array('type' => 'blob', 'connection_name' => 'test')
);
$container = $this->createContainer($config);
$this->assertInstanceOf('WindowsAzure\DistributionBundle\Deployment\Assets\BlobStrategy', $container->get('windows_azure_distribution.assets'));
}
public function testSessionStorage()
{
$config = array(
'session' => array(
'type' => 'pdo',
'database' => array(
'host' => 'localhost',
'username' => 'foo',
'password' => 'bar',
'database' => 'db',
)
),
);
$container = $this->createContainer($config);
$def = $container->findDefinition('session.storage');
$this->assertEquals('%windows_azure_distribution.session_storage.pdo.class%', $def->getClass());
$def = $container->findDefinition('windows_azure_distribution.session.pdo');
$args = $def->getArguments();
$this->assertEquals('sqlsrv:server=localhost;Database=db', $args[0]);
}
public function testKeyValueStore()
{
$config = array(
'services' => array(
'table' => array(
'test' => 'DefaultEndpointsProtocol=[http|https];AccountName=[yourAccount];AccountKey=[yourKey]'
),
),
'key_value_store' => array(
'connection_name' => 'test'
)
);
$container = $this->createContainer($config);
$this->assertTrue($container->has('windows_azure_distribution.key_value_store.entity_manager'));
$this->assertTrue($container->has('windows_azure_distribution.key_value_store.storage_client'));
}
public function testStreams()
{
$config = array('streams' => array('foo' => 'bar'));
$container = $this->createContainer($config);
$this->assertEquals(array('foo' => 'bar'), $container->getParameter('windows_azure_distribution.streams'));
}
public function createContainer(array $config = array())
{
$container = new ContainerBuilder(new ParameterBag(array(
'kernel.debug' => false,
'kernel.bundles' => array(),
'kernel.cache_dir' => sys_get_temp_dir(),
'kernel.environment' => 'test',
'kernel.root_dir' => __DIR__ . '/_files/app',
'session.storage.options' => array(),
)));
$loader = new WindowsAzureDistributionExtension();
$container->registerExtension($loader);
$loader->load(array($config), $container);
$container->getCompilerPassConfig()->setOptimizationPasses(array(new ResolveDefinitionTemplatesPass()));
$container->getCompilerPassConfig()->setRemovingPasses(array());
$container->compile();
return $container;
}
}