-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
FeatureTest.php
110 lines (92 loc) · 3.1 KB
/
FeatureTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
declare(strict_types=1);
namespace Pheature\Test\Core\Toggle\Write;
use Pheature\Core\Toggle\Write\Feature;
use Pheature\Core\Toggle\Write\FeatureId;
use Pheature\Core\Toggle\Write\Strategy;
use Pheature\Core\Toggle\Write\StrategyId;
use Pheature\Core\Toggle\Write\StrategyType;
use PHPUnit\Framework\TestCase;
final class FeatureTest extends TestCase
{
private const FEATURE_ID = 'some_feature';
private const STRATEGY_ID = 'some_strategy';
private const STRATEGY_TYPE = 'some_strategy_type';
public function testItShouldBeCreatedWithId(): void
{
$feature = $this->createFeature();
$this->assertFalse($feature->isEnabled());
}
public function testItShouldBeSerializeAsArray(): void
{
$feature = $this->getFeatureWithAnStrategy();
$this->assertSame([
'feature_id' => self::FEATURE_ID,
'enabled' => false,
'strategies' => [
self::STRATEGY_ID => [
'strategy_id' => self::STRATEGY_ID,
'strategy_type' => self::STRATEGY_TYPE,
'segments' => [],
],
],
], $feature->jsonSerialize());
}
public function testItShouldBeEnabled(): void
{
$feature = $this->createFeature();
$this->assertFalse($feature->isEnabled());
$feature->enable();
$this->assertTrue($feature->isEnabled());
$events = $feature->release();
$this->assertCount(0, $events);
}
public function testItShouldBeDisabled(): void
{
$feature = $this->getEnabledFeature();
$this->assertTrue($feature->isEnabled());
$feature->disable();
$this->assertFalse($feature->isEnabled());
$events = $feature->release();
$this->assertCount(0, $events);
}
public function testItShouldHaveAddedStrategies(): void
{
$feature = $this->getFeatureWithAnStrategy();
$this->assertCount(1, $feature->strategies());
$events = $feature->release();
$this->assertCount(0, $events);
}
public function testItShouldRemoveAddedStrategies(): void
{
$feature = $this->getFeatureWithAnStrategy();
$this->assertCount(1, $feature->strategies());
$feature->removeStrategy(StrategyId::fromString(self::STRATEGY_ID));
$this->assertCount(0, $feature->strategies());
$events = $feature->release();
$this->assertCount(0, $events);
}
private function createFeature(): Feature
{
return Feature::withId(
FeatureId::fromString(self::FEATURE_ID)
);
}
private function getEnabledFeature(): Feature
{
$feature = $this->createFeature();
$feature->enable();
return $feature;
}
private function getFeatureWithAnStrategy(): Feature
{
$strategy = new Strategy(
StrategyId::fromString(self::STRATEGY_ID),
StrategyType::fromString(self::STRATEGY_TYPE),
[]
);
$feature = $this->createFeature();
$feature->setStrategy($strategy);
return $feature;
}
}