1
+ <?php
2
+ namespace SplitIO \Test \Suite \TrafficAllocation ;
3
+
4
+ use SplitIO \Component \Initialization \LoggerFactory ;
5
+ use SplitIO \Component \Common \ServiceProvider ;
6
+ use SplitIO \Grammar \Split ;
7
+
8
+ class TrafficAllocationTest extends \PHPUnit \Framework \TestCase
9
+ {
10
+ /**
11
+ * @runInSeparateProcess
12
+ * @preserveGlobalState disabled
13
+ */
14
+ public function testTrafficAllocation ()
15
+ {
16
+ $ mock = \Mockery::mock ('alias:\SplitIO\Engine\Splitter ' );
17
+ $ mock ->shouldReceive ([
18
+ 'getBucket ' => 1 ,
19
+ 'getTreatment ' => 'on ' ,
20
+ ]);
21
+
22
+ $ logger = LoggerFactory::setupLogger (array ('adapter ' => 'stdout ' , 'level ' => 'error ' ));
23
+ ServiceProvider::registerLogger ($ logger );
24
+
25
+ $ rawSplit = array (
26
+ 'name ' => 'test1 ' ,
27
+ 'algo ' => 1 ,
28
+ 'killed ' => false ,
29
+ 'status ' => 'ACTIVE ' ,
30
+ 'defaultTreatment ' => 'default ' ,
31
+ 'seed ' => -1222652054 ,
32
+ 'orgId ' => null ,
33
+ 'environment ' => null ,
34
+ 'trafficTypeId ' => null ,
35
+ 'trafficTypeName ' => null ,
36
+ 'conditions ' => array (
37
+ array (
38
+ 'conditionType ' => 'WHITELIST ' ,
39
+ 'matcherGroup ' => array (
40
+ 'combiner ' => 'AND ' ,
41
+ 'matchers ' => array (
42
+ array (
43
+ 'matcherType ' => 'ALL_KEYS ' ,
44
+ 'negate ' => false ,
45
+ 'userDefinedSegmentMatcherData ' => null ,
46
+ 'whitelistMatcherData ' => null
47
+ )
48
+ )
49
+ ),
50
+ 'partitions ' => array (
51
+ array (
52
+ 'treatment ' => 'on ' ,
53
+ 'size ' => 100
54
+ )
55
+ ),
56
+ 'label ' => 'in segment all '
57
+ )
58
+ )
59
+ );
60
+
61
+ $ rawSplit ['trafficAllocation ' ] = 1 ;
62
+ $ rawSplit ['trafficAllocationSeed ' ] = -1 ;
63
+ $ split4 = new Split ($ rawSplit );
64
+ $ treatment4 = \SplitIO \Engine::getTreatment ('testKey ' , null , $ split4 );
65
+ $ this ->assertEquals ('on ' , $ treatment4 [\SplitIO \Engine::EVALUATION_RESULT_TREATMENT ]);
66
+
67
+ $ rawSplit ['trafficAllocation ' ] = 1 ;
68
+ $ rawSplit ['trafficAllocationSeed ' ] = -1 ;
69
+ $ split4 = new Split ($ rawSplit );
70
+ $ treatment4 = \SplitIO \Engine::getTreatment ('testKey ' , null , $ split4 );
71
+ $ this ->assertEquals ('on ' , $ treatment4 [\SplitIO \Engine::EVALUATION_RESULT_TREATMENT ]);
72
+ }
73
+ };
0 commit comments