|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Alawar\NginxPushStreamBundle\Tests\Connection\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Alawar\NginxPushStreamBundle\DependencyInjection\NginxPushStreamExtension; |
|
6
|
|
|
use Alawar\NginxPushStreamBundle\Tests\DependencyInjection\DependencyInjectionTest; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
9
|
|
|
|
|
10
|
|
|
class NginxPushStreamExtensionTest extends DependencyInjectionTest |
|
11
|
|
|
{ |
|
12
|
|
|
public function testDefaultConfig() |
|
13
|
|
|
{ |
|
14
|
|
|
$configs = array( |
|
15
|
|
|
array( |
|
16
|
|
|
'pub_url' => 'http://localhost/pub?id={token}', |
|
17
|
|
|
'sub_urls' => array( |
|
18
|
|
|
'polling' => 'http://localhost/sub-p/{tokens}', |
|
19
|
|
|
'long-polling' => 'http://localhost/sub-lp/{tokens}', |
|
20
|
|
|
) |
|
21
|
|
|
) |
|
22
|
|
|
); |
|
23
|
|
|
|
|
24
|
|
|
$container = $this->getContainer($configs); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertTrue($container->hasDefinition('nginx_push_stream.default_connection')); |
|
27
|
|
|
$defaultConnection = $container->getDefinition('nginx_push_stream.default_connection'); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertDICDefinitionMethodCallAt(0, $defaultConnection, 'setIdGenerator', array( |
|
30
|
|
|
new Reference('nginx_push_stream.id_generator') |
|
31
|
|
|
)); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertDICDefinitionMethodCallAt(1, $defaultConnection, 'setSender', array( |
|
34
|
|
|
new Reference('nginx_push_stream.sender') |
|
35
|
|
|
)); |
|
36
|
|
|
|
|
37
|
|
|
$connection = $container->get('nginx_push_stream.default_connection'); |
|
38
|
|
|
$this->assertInstanceOf('\Alawar\NginxPushStreamBundle\Connection', $connection); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testManyConnections() |
|
42
|
|
|
{ |
|
43
|
|
|
$configs = array( |
|
44
|
|
|
array( |
|
45
|
|
|
'connections' => array( |
|
46
|
|
|
'foo' => array( |
|
47
|
|
|
'pub_url' => 'http://localhost/pub?id={token}', |
|
48
|
|
|
'sub_urls' => array( |
|
49
|
|
|
'polling' => 'http://localhost/sub-p/{tokens}', |
|
50
|
|
|
) |
|
51
|
|
|
), |
|
52
|
|
|
'bar' => array( |
|
53
|
|
|
'pub_url' => 'http://bar/pub?id={token}', |
|
54
|
|
|
'sub_urls' => array( |
|
55
|
|
|
'polling' => 'http://localhost/sub-p/{tokens}', |
|
56
|
|
|
) |
|
57
|
|
|
) |
|
58
|
|
|
) |
|
59
|
|
|
) |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
$container = $this->getContainer($configs); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertTrue($container->hasDefinition('nginx_push_stream.foo_connection')); |
|
65
|
|
|
$this->assertTrue($container->hasDefinition('nginx_push_stream.bar_connection')); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testIdGeneratorAndSenderDisabled() |
|
69
|
|
|
{ |
|
70
|
|
|
$configs = array( |
|
71
|
|
|
array( |
|
72
|
|
|
'pub_url' => 'http://localhost/pub?id={token}', |
|
73
|
|
|
'sub_urls' => array( |
|
74
|
|
|
'polling' => 'http://localhost/sub-p/{tokens}', |
|
75
|
|
|
), |
|
76
|
|
|
'id_generator' => false, |
|
77
|
|
|
'sender' => false, |
|
78
|
|
|
) |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
$container = $this->getContainer($configs); |
|
82
|
|
|
|
|
83
|
|
|
$this->assertTrue($container->hasDefinition('nginx_push_stream.default_connection')); |
|
84
|
|
|
$defaultConnection = $container->getDefinition('nginx_push_stream.default_connection'); |
|
85
|
|
|
$this->assertCount(0, $defaultConnection->getMethodCalls()); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function testIdGeneratorCustomService() |
|
89
|
|
|
{ |
|
90
|
|
|
$configs = array( |
|
91
|
|
|
array( |
|
92
|
|
|
'pub_url' => 'http://localhost/pub?id={token}', |
|
93
|
|
|
'sub_urls' => array( |
|
94
|
|
|
'polling' => 'http://localhost/sub-p/{tokens}', |
|
95
|
|
|
), |
|
96
|
|
|
'id_generator' => 'nginx_push_stream.my_id_generator', |
|
97
|
|
|
) |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
$container = $this->getContainer($configs); |
|
101
|
|
|
|
|
102
|
|
|
$this->assertTrue($container->hasDefinition('nginx_push_stream.default_connection')); |
|
103
|
|
|
$defaultConnection = $container->getDefinition('nginx_push_stream.default_connection'); |
|
104
|
|
|
$this->assertDICDefinitionMethodCallAt(0, $defaultConnection, 'setIdGenerator', array( |
|
105
|
|
|
new Reference('nginx_push_stream.my_id_generator') |
|
106
|
|
|
)); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
public function testFilters() |
|
111
|
|
|
{ |
|
112
|
|
|
$configs = array( |
|
113
|
|
|
array( |
|
114
|
|
|
'pub_url' => 'http://localhost/pub?id={token}', |
|
115
|
|
|
'sub_urls' => array( |
|
116
|
|
|
'polling' => 'http://localhost/sub-p/{tokens}', |
|
117
|
|
|
), |
|
118
|
|
|
'filters' => array( |
|
119
|
|
|
'hash' => array('class' => 'hash', 'secret' => 'x'), |
|
120
|
|
|
'prefix' => array('class' => 'prefix', 'prefix' => 'x'), |
|
121
|
|
|
) |
|
122
|
|
|
) |
|
123
|
|
|
); |
|
124
|
|
|
|
|
125
|
|
|
$container = $this->getContainer($configs); |
|
126
|
|
|
|
|
127
|
|
|
$this->assertTrue($container->hasDefinition('nginx_push_stream.default_connection')); |
|
128
|
|
|
$defaultConnection = $container->getDefinition('nginx_push_stream.default_connection'); |
|
129
|
|
|
$this->assertDICDefinitionMethodCallAt(0, $defaultConnection, 'setIdGenerator'); |
|
130
|
|
|
$this->assertDICDefinitionMethodCallAt(1, $defaultConnection, 'setSender'); |
|
131
|
|
|
$this->assertDICDefinitionMethodCallAt(2, $defaultConnection, 'addFilter', array( |
|
132
|
|
|
new Reference('nginx_push_stream.hash_filter') |
|
133
|
|
|
)); |
|
134
|
|
|
$this->assertDICDefinitionMethodCallAt(3, $defaultConnection, 'addFilter', array( |
|
135
|
|
|
new Reference('nginx_push_stream.prefix_filter') |
|
136
|
|
|
)); |
|
137
|
|
|
|
|
138
|
|
|
$this->assertTrue($container->hasDefinition('nginx_push_stream.hash_filter')); |
|
139
|
|
|
$hashFilterDefinition = $container->getDefinition('nginx_push_stream.hash_filter'); |
|
140
|
|
|
$this->assertDICDefinitionClass($hashFilterDefinition, '%nginx_push_stream.filter.hash.class%'); |
|
141
|
|
|
|
|
142
|
|
|
$this->assertTrue($container->hasDefinition('nginx_push_stream.prefix_filter')); |
|
143
|
|
|
$prefixFilterDefinition = $container->getDefinition('nginx_push_stream.prefix_filter'); |
|
144
|
|
|
$this->assertDICDefinitionClass($prefixFilterDefinition, '%nginx_push_stream.filter.prefix.class%'); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
protected function getContainer(array $config = array()) |
|
148
|
|
|
{ |
|
149
|
|
|
$container = new ContainerBuilder(); |
|
150
|
|
|
$container->getCompilerPassConfig()->setOptimizationPasses(array()); |
|
151
|
|
|
$container->getCompilerPassConfig()->setRemovingPasses(array()); |
|
152
|
|
|
//$container->addCompilerPass(new LoggerChannelPass()); |
|
153
|
|
|
|
|
154
|
|
|
$loader = new NginxPushStreamExtension(); |
|
155
|
|
|
$loader->load($config, $container); |
|
156
|
|
|
$container->compile(); |
|
157
|
|
|
|
|
158
|
|
|
return $container; |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|