1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alawar\NginxPushStreamBundle\Tests\Connection\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Alawar\NginxPushStreamBundle\DependencyInjection\Configuration; |
6
|
|
|
use Symfony\Component\Config\Definition\Processor; |
7
|
|
|
|
8
|
|
|
class ConfigurationTest extends \PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
public function testProcessMinimalConfig() |
11
|
|
|
{ |
12
|
|
|
$configs = array( |
13
|
|
|
array( |
14
|
|
|
'pub_url' => 'http://localhost/pub?id={token}', |
15
|
|
|
'sub_urls' => array( |
16
|
|
|
'polling' => 'http://localhost/sub-p/{tokens}', |
17
|
|
|
'long-polling' => 'http://localhost/sub-lp/{tokens}', |
18
|
|
|
) |
19
|
|
|
) |
20
|
|
|
); |
21
|
|
|
|
22
|
|
|
$config = $this->process($configs); |
23
|
|
|
|
24
|
|
|
$this->assertEquals( |
25
|
|
|
$config, |
26
|
|
|
array( |
27
|
|
|
'default_connection' => 'default', |
28
|
|
|
'connections' => array( |
29
|
|
|
'default' => array( |
30
|
|
|
'pub_url' => 'http://localhost/pub?id={token}', |
31
|
|
|
'sub_urls' => array( |
32
|
|
|
'polling' => 'http://localhost/sub-p/{tokens}', |
33
|
|
|
'long_polling' => 'http://localhost/sub-lp/{tokens}', |
34
|
|
|
), |
35
|
|
|
'id_generator' => true, |
36
|
|
|
'sender' => true, |
37
|
|
|
'filters' => array(), |
38
|
|
|
), |
39
|
|
|
), |
40
|
|
|
) |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testProcessOneConnection() |
45
|
|
|
{ |
46
|
|
|
$configs = array( |
47
|
|
|
array( |
48
|
|
|
'default_connection' => 'default', |
49
|
|
|
'connections' => array( |
50
|
|
|
'default' => array( |
51
|
|
|
'pub_url' => 'http://localhost/pub?id={token}', |
52
|
|
|
'sub_urls' => array( |
53
|
|
|
'polling' => 'http://localhost/sub-p/{tokens}', |
54
|
|
|
'long-polling' => 'http://localhost/sub-lp/{tokens}', |
55
|
|
|
) |
56
|
|
|
) |
57
|
|
|
) |
58
|
|
|
) |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
$config = $this->process($configs); |
62
|
|
|
|
63
|
|
|
$this->assertEquals( |
64
|
|
|
$config, |
65
|
|
|
array( |
66
|
|
|
'default_connection' => 'default', |
67
|
|
|
'connections' => array( |
68
|
|
|
'default' => array( |
69
|
|
|
'pub_url' => 'http://localhost/pub?id={token}', |
70
|
|
|
'sub_urls' => array( |
71
|
|
|
'polling' => 'http://localhost/sub-p/{tokens}', |
72
|
|
|
'long_polling' => 'http://localhost/sub-lp/{tokens}', |
73
|
|
|
), |
74
|
|
|
'id_generator' => true, |
75
|
|
|
'sender' => true, |
76
|
|
|
'filters' => array(), |
77
|
|
|
), |
78
|
|
|
), |
79
|
|
|
) |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testProcessFilters() |
84
|
|
|
{ |
85
|
|
|
$configs = array( |
86
|
|
|
array( |
87
|
|
|
'pub_url' => 'http://localhost/pub?id={token}', |
88
|
|
|
'sub_urls' => array( |
89
|
|
|
'polling' => 'http://localhost/sub-p/{tokens}', |
90
|
|
|
'long-polling' => 'http://localhost/sub-lp/{tokens}', |
91
|
|
|
), |
92
|
|
|
'filters' => array( |
93
|
|
|
'hash' => array( |
94
|
|
|
'class' => 'hash', |
95
|
|
|
'secret' => 'mysecret', |
96
|
|
|
'algo' => 'md5' |
97
|
|
|
), |
98
|
|
|
'prefix' => array( |
99
|
|
|
'class' => 'prefix', |
100
|
|
|
'prefix' => '123' |
101
|
|
|
) |
102
|
|
|
) |
103
|
|
|
) |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
$config = $this->process($configs); |
107
|
|
|
|
108
|
|
|
$this->assertEquals( |
109
|
|
|
$config, |
110
|
|
|
array( |
111
|
|
|
'default_connection' => 'default', |
112
|
|
|
'connections' => array( |
113
|
|
|
'default' => array( |
114
|
|
|
'pub_url' => 'http://localhost/pub?id={token}', |
115
|
|
|
'sub_urls' => array( |
116
|
|
|
'polling' => 'http://localhost/sub-p/{tokens}', |
117
|
|
|
'long_polling' => 'http://localhost/sub-lp/{tokens}', |
118
|
|
|
), |
119
|
|
|
'id_generator' => true, |
120
|
|
|
'sender' => true, |
121
|
|
|
'filters' => array( |
122
|
|
|
'hash' => array( |
123
|
|
|
'class' => 'hash', |
124
|
|
|
'secret' => 'mysecret', |
125
|
|
|
'algo' => 'md5' |
126
|
|
|
), |
127
|
|
|
'prefix' => array( |
128
|
|
|
'class' => 'prefix', |
129
|
|
|
'prefix' => '123' |
130
|
|
|
) |
131
|
|
|
), |
132
|
|
|
), |
133
|
|
|
), |
134
|
|
|
) |
135
|
|
|
); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
protected function process($configs) |
139
|
|
|
{ |
140
|
|
|
$processor = new Processor(); |
141
|
|
|
|
142
|
|
|
return $processor->processConfiguration(new Configuration(), $configs); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|