|
8 | 8 | use LaunchDarkly\Impl\Events\EventFactory; |
9 | 9 | use LaunchDarkly\Impl\Model\FeatureFlag; |
10 | 10 | use LaunchDarkly\LDContext; |
| 11 | +use LaunchDarkly\Tests\ModelBuilders; |
11 | 12 | use PHPUnit\Framework\TestCase; |
12 | 13 |
|
13 | 14 | class EventFactoryTest extends TestCase |
@@ -76,6 +77,57 @@ public function testTrackEventTrue() |
76 | 77 | $this->assertTrue($result['trackEvents']); |
77 | 78 | } |
78 | 79 |
|
| 80 | + public function testEvalEventHandlesSamplingRatio() |
| 81 | + { |
| 82 | + $builder = ModelBuilders::flagBuilder('flag') |
| 83 | + ->variations('fall', 'off', 'on') |
| 84 | + ->on(true) |
| 85 | + ->offVariation(1) |
| 86 | + ->fallthroughVariation(0); |
| 87 | + |
| 88 | + $ef = new EventFactory(false); |
| 89 | + $context = LDContext::create('userkey'); |
| 90 | + $detail = new EvaluationDetail('off', 1, EvaluationReason::fallthrough()); |
| 91 | + |
| 92 | + $flag = $builder->build(); |
| 93 | + $result = $ef->newEvalEvent($flag, $context, new EvalResult($detail, false), null); |
| 94 | + $this->assertArrayNotHasKey('samplingRatio', $result); |
| 95 | + |
| 96 | + $flag = $builder->samplingRatio(0)->build(); |
| 97 | + $result = $ef->newEvalEvent($flag, $context, new EvalResult($detail, false), null); |
| 98 | + $this->assertEquals(0, $result['samplingRatio']); |
| 99 | + |
| 100 | + $flag = $builder->samplingRatio(1)->build(); |
| 101 | + $result = $ef->newEvalEvent($flag, $context, new EvalResult($detail, false), null); |
| 102 | + $this->assertArrayNotHasKey('samplingRatio', $result); |
| 103 | + |
| 104 | + $flag = $builder->samplingRatio(2)->build(); |
| 105 | + $result = $ef->newEvalEvent($flag, $context, new EvalResult($detail, false), null); |
| 106 | + $this->assertEquals(2, $result['samplingRatio']); |
| 107 | + } |
| 108 | + |
| 109 | + public function testEvalEventHandlesExcludeFromSummaries() |
| 110 | + { |
| 111 | + $builder = ModelBuilders::flagBuilder('flag') |
| 112 | + ->variations('fall', 'off', 'on') |
| 113 | + ->on(true) |
| 114 | + ->offVariation(1) |
| 115 | + ->fallthroughVariation(0); |
| 116 | + |
| 117 | + $ef = new EventFactory(false); |
| 118 | + $context = LDContext::create('userkey'); |
| 119 | + |
| 120 | + $detail = new EvaluationDetail('off', 1, EvaluationReason::fallthrough()); |
| 121 | + |
| 122 | + $flag = $builder->excludeFromSummaries(true)->build(); |
| 123 | + $result = $ef->newEvalEvent($flag, $context, new EvalResult($detail, false), null); |
| 124 | + $this->assertTrue($result['excludeFromSummaries']); |
| 125 | + |
| 126 | + $flag = $builder->excludeFromSummaries(false)->build(); |
| 127 | + $result = $ef->newEvalEvent($flag, $context, new EvalResult($detail, false), null); |
| 128 | + $this->assertArrayNotHasKey('excludeFromSummaries', $result); |
| 129 | + } |
| 130 | + |
79 | 131 | public function testTrackEventTrueWhenTrackEventsFalseButExperimentFallthroughReason() |
80 | 132 | { |
81 | 133 | $ef = new EventFactory(false); |
|
0 commit comments