4
4
5
5
use Flagception \Activator \CookieActivator ;
6
6
use Flagception \Activator \FeatureActivatorInterface ;
7
+ use Flagception \Exception \InvalidArgumentException ;
7
8
use Flagception \Model \Context ;
8
9
use PHPUnit \Framework \TestCase ;
9
10
@@ -30,6 +31,8 @@ protected function setUp()
30
31
* Test implement interface
31
32
*
32
33
* @return void
34
+ *
35
+ * @throws InvalidArgumentException
33
36
*/
34
37
public function testImplementInterface ()
35
38
{
@@ -40,6 +43,8 @@ public function testImplementInterface()
40
43
* Test name
41
44
*
42
45
* @return void
46
+ *
47
+ * @throws InvalidArgumentException
43
48
*/
44
49
public function testName ()
45
50
{
@@ -51,6 +56,8 @@ public function testName()
51
56
* Test feature is unknown
52
57
*
53
58
* @return void
59
+ *
60
+ * @throws InvalidArgumentException
54
61
*/
55
62
public function testFeatureIsUnknown ()
56
63
{
@@ -64,6 +71,8 @@ public function testFeatureIsUnknown()
64
71
* Test feature is known
65
72
*
66
73
* @return void
74
+ *
75
+ * @throws InvalidArgumentException
67
76
*/
68
77
public function testFeatureIsKnown ()
69
78
{
@@ -79,6 +88,8 @@ public function testFeatureIsKnown()
79
88
* Test multiple features
80
89
*
81
90
* @return void
91
+ *
92
+ * @throws InvalidArgumentException
82
93
*/
83
94
public function testMultipleFeatures ()
84
95
{
@@ -101,6 +112,8 @@ public function testMultipleFeatures()
101
112
* Test changed cookie name is unknown
102
113
*
103
114
* @return void
115
+ *
116
+ * @throws InvalidArgumentException
104
117
*/
105
118
public function testCookieNameChangeUnknown ()
106
119
{
@@ -116,6 +129,8 @@ public function testCookieNameChangeUnknown()
116
129
* Test changed cookie name is known
117
130
*
118
131
* @return void
132
+ *
133
+ * @throws InvalidArgumentException
119
134
*/
120
135
public function testCookieNameChangeKnown ()
121
136
{
@@ -131,6 +146,8 @@ public function testCookieNameChangeKnown()
131
146
* Test multiple features with changed separator
132
147
*
133
148
* @return void
149
+ *
150
+ * @throws InvalidArgumentException
134
151
*/
135
152
public function testMultipleFeaturesWithChangedSeparator ()
136
153
{
@@ -148,4 +165,79 @@ public function testMultipleFeaturesWithChangedSeparator()
148
165
static ::assertFalse ($ activator ->isActive ('foobar ' , new Context ()));
149
166
static ::assertFalse ($ activator ->isActive ('feature_xyz ' , new Context ()));
150
167
}
168
+
169
+ /**
170
+ * Test multiple features by blacklist
171
+ *
172
+ * @return void
173
+ *
174
+ * @throws InvalidArgumentException
175
+ */
176
+ public function testMultipleFeaturesByBlacklist ()
177
+ {
178
+ $ activator = new CookieActivator ([
179
+ 'feature_abc ' ,
180
+ 'feature_def ' ,
181
+ 'feature_ghi ' ,
182
+ 'feature_xyz '
183
+ ], 'flagception ' , ', ' , CookieActivator::BLACKLIST );
184
+
185
+ $ _COOKIE ['flagception ' ] = 'feature_abc,feature_def, feature_ghi, foobar ' ;
186
+ static ::assertFalse ($ activator ->isActive ('feature_abc ' , new Context ()));
187
+ static ::assertFalse ($ activator ->isActive ('feature_def ' , new Context ()));
188
+ static ::assertFalse ($ activator ->isActive ('feature_ghi ' , new Context ()));
189
+ static ::assertTrue ($ activator ->isActive ('foobar ' , new Context ()));
190
+ static ::assertFalse ($ activator ->isActive ('feature_xyz ' , new Context ()));
191
+ }
192
+
193
+ /**
194
+ * Test public constants
195
+ *
196
+ * @return void
197
+ */
198
+ public function testConstants ()
199
+ {
200
+ static ::assertEquals ('whitelist ' , CookieActivator::WHITELIST );
201
+ static ::assertEquals ('blacklist ' , CookieActivator::BLACKLIST );
202
+ }
203
+
204
+ /**
205
+ * Test if "whitelist" is a valid argument as mode
206
+ *
207
+ * @return void
208
+ *
209
+ * @throws InvalidArgumentException
210
+ */
211
+ public function testWhitelistModeArgument ()
212
+ {
213
+ $ activator = new CookieActivator ([], 'flagception ' , ', ' , 'whitelist ' );
214
+ static ::assertEquals ('cookie ' , $ activator ->getName ());
215
+ }
216
+
217
+ /**
218
+ * Test if "blacklist" is a valid argument as mode
219
+ *
220
+ * @return void
221
+ *
222
+ * @throws InvalidArgumentException
223
+ */
224
+ public function testBlacklistModeArgument ()
225
+ {
226
+ $ activator = new CookieActivator ([], 'flagception ' , ', ' , 'blacklist ' );
227
+ static ::assertEquals ('cookie ' , $ activator ->getName ());
228
+ }
229
+
230
+ /**
231
+ * Test if "foobar" is an invalid argument as mode
232
+ *
233
+ * @return void
234
+ *
235
+ * @throws InvalidArgumentException
236
+ */
237
+ public function testFoobarModeArgument ()
238
+ {
239
+ $ this ->expectException (InvalidArgumentException::class);
240
+
241
+ new CookieActivator ([], 'flagception ' , ', ' , 'foobar ' );
242
+ }
151
243
}
0 commit comments