1
|
|
|
<?php |
2
|
|
|
/* Copyright (C) 2017 Michael Giesler |
3
|
|
|
* |
4
|
|
|
* This file is part of Dembelo. |
5
|
|
|
* |
6
|
|
|
* Dembelo is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU Affero General Public License as published by |
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* Dembelo is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU Affero General Public License 3 for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU Affero General Public License 3 |
17
|
|
|
* along with Dembelo. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace DembeloMain\Tests\Model; |
21
|
|
|
|
22
|
|
|
use DembeloMain\Model\FeatureToggle; |
23
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
24
|
|
|
use Symfony\Component\DependencyInjection\Container; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class FeatureToggleTest |
28
|
|
|
*/ |
29
|
|
|
class FeatureToggleTest extends WebTestCase |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var FeatureToggle |
33
|
|
|
*/ |
34
|
|
|
private $featureToggle; |
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
public function testHasFeatureExists(): void |
40
|
|
|
{ |
41
|
|
|
$featureToggle = new FeatureToggle([]); |
42
|
|
|
$this->assertTrue(method_exists($featureToggle, 'hasFeature')); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return void |
47
|
|
|
*/ |
48
|
|
|
public function testHasFeatureThrowsErrorWithMissingParameter(): void |
49
|
|
|
{ |
50
|
|
|
$featureToggle = new FeatureToggle([]); |
51
|
|
|
|
52
|
|
|
$this->expectException(\ArgumentCountError::class); |
53
|
|
|
$featureToggle->hasFeature(); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* tests hasFeature() returns false for unknown feature |
58
|
|
|
*/ |
59
|
|
|
public function testHasFeatureReturnsFalseForUnknownFeature() |
60
|
|
|
{ |
61
|
|
|
$featureToggle = new FeatureToggle([]); |
62
|
|
|
self::assertFalse($featureToggle->hasFeature('unknownFeature')); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* tests hasFeature returns false for test feature |
67
|
|
|
*/ |
68
|
|
|
public function testHasFeatureReturnsFalseForTestFeature() |
69
|
|
|
{ |
70
|
|
|
$featureToggle = new FeatureToggle([]); |
71
|
|
|
self::assertFalse($featureToggle->hasFeature('test_feature')); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* tests hasFeature() returns false when no parameter exists for test feature |
76
|
|
|
*/ |
77
|
|
|
public function testHasFeatureReturnsWhenNoParameterExistsForTestFeature() |
78
|
|
|
{ |
79
|
|
|
$featureToggle = new FeatureToggle( |
80
|
|
|
[ |
81
|
|
|
[ |
82
|
|
|
'test_feature' => false, |
83
|
|
|
], |
84
|
|
|
] |
85
|
|
|
); |
86
|
|
|
self::assertFalse($featureToggle->hasFeature('test_feature')); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* tests hasFeature() returns true when test Feature is enabled by parameter |
91
|
|
|
*/ |
92
|
|
|
public function testHasFeatureReturnsTrueWhenTestFeatureIsEnabledByParameter() |
93
|
|
|
{ |
94
|
|
|
$featureToggle = new FeatureToggle([ |
95
|
|
|
['test_feature' => true], |
96
|
|
|
]); |
97
|
|
|
|
98
|
|
|
self::assertTrue($featureToggle->hasFeature('test_feature')); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* tests getFeatures() is existing |
103
|
|
|
*/ |
104
|
|
|
public function testGetFeaturesExists() |
105
|
|
|
{ |
106
|
|
|
$featureToggle = new FeatureToggle([]); |
107
|
|
|
self::assertTrue(method_exists($featureToggle, 'getFeatures')); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* tests getFeatures() returns an array |
112
|
|
|
*/ |
113
|
|
|
public function testGetFeaturesReturnsAnArray() |
114
|
|
|
{ |
115
|
|
|
$featureToggle = new FeatureToggle([]); |
116
|
|
|
self::assertInternalType('array', $featureToggle->getFeatures()); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* tests getFeature() count is greater than 1 |
121
|
|
|
*/ |
122
|
|
|
public function testGetFeaturesCountGreaterOne() |
123
|
|
|
{ |
124
|
|
|
$featureToggle = new FeatureToggle([]); |
125
|
|
|
self::assertGreaterThan(0, count($featureToggle->getFeatures())); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* tests getFeatures() contains the test feature |
130
|
|
|
*/ |
131
|
|
|
public function testGetFeaturesContainsTestFeature() |
132
|
|
|
{ |
133
|
|
|
$featureToggle = new FeatureToggle([]); |
134
|
|
|
$features = $featureToggle->getFeatures(); |
135
|
|
|
self::assertContains('test_feature', $features); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|