Skip to content

Commit b08c536

Browse files
committed
updated Splitter test for TrafficAllocation
1 parent e089f2b commit b08c536

File tree

3 files changed

+77
-141
lines changed

3 files changed

+77
-141
lines changed

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<testsuite name="engine">
3131
<directory suffix="Test.php">tests/Suite/Engine/</directory>
3232
</testsuite>
33+
<testsuite name="traffic_allocation">
34+
<directory suffix="Test.php">tests/Suite/TrafficAllocation/</directory>
35+
</testsuite>
3336
<testsuite name="input_validation">
3437
<directory suffix="Test.php">tests/Suite/InputValidation/</directory>
3538
</testsuite>
@@ -55,6 +58,7 @@
5558
<directory suffix="Test.php">tests/Suite/Component/</directory>
5659
<directory suffix="Test.php">tests/Suite/DynamicConfigurations/</directory>
5760
<directory suffix="Test.php">tests/Suite/Engine/</directory>
61+
<directory suffix="Test.php">tests/Suite/TrafficAllocation/</directory>
5862
<directory suffix="Test.php">tests/Suite/InputValidation/</directory>
5963
<directory suffix="Test.php">tests/Suite/Matchers/</directory>
6064
<directory suffix="Test.php">tests/Suite/Metrics/</directory>

tests/Suite/Engine/SplitterTrafficAllocationTest.php

Lines changed: 0 additions & 141 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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

Comments
 (0)