Page MenuHomeDevCentral

D215.id508.diff
No OneTemporary

D215.id508.diff

diff --git a/app/Features.php b/app/Features.php
--- a/app/Features.php
+++ b/app/Features.php
@@ -12,6 +12,18 @@
*/
class Features {
+ ///
+ /// Feature information
+ ///
+
+ /**
+ * @param string $feature The feature to get the config key
+ * @return string The config key
+ */
+ private static function getFeatureConfigKey ($feature) {
+ return 'app.features.' . $feature;
+ }
+
/**
* Determines if the specified feature is enabled
*
@@ -19,11 +31,35 @@
* @return bool
*/
public static function isEnabled ($feature) {
- $key = 'app.features.' . $feature;
+ $key = self::getFeatureConfigKey($feature);
return Config::has($key) && (bool)Config::get($key);
}
/**
+ * Enables a feature in our current configuration instance
+ *
+ * @param string $feature The feature
+ */
+ public static function enable ($feature) {
+ $key = self::getFeatureConfigKey($feature);
+ Config::set($key, true);
+ }
+
+ /**
+ * Disables a feature in our current configuration instance
+ *
+ * @param string $feature The feature
+ */
+ public static function disable ($feature) {
+ $key = self::getFeatureConfigKey($feature);
+ Config::set($key, false);
+ }
+
+ ///
+ /// Features lists
+ ///
+
+ /**
* Gets all the features, with the toggle status
*
* @return array An array with features as keys, bool as values (true if enabled)
@@ -52,5 +88,4 @@
$enabledFeatures = array_filter($features);
return array_keys($enabledFeatures);
}
-
}
diff --git a/tests/FeaturesTest.php b/tests/FeaturesTest.php
new file mode 100644
--- /dev/null
+++ b/tests/FeaturesTest.php
@@ -0,0 +1,28 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests;
+
+use Nasqueron\Notifications\Features;
+
+class FeaturesTest extends TestCase {
+ public function testEnable () {
+ // Find it (en vain …)
+ $this->assertNotContains('Quux', Features::getEnabled());
+ $this->assertFalse(Features::isEnabled('Quux'));
+
+ // Enable it
+ Features::enable('Quux');
+ $this->assertTrue(Features::isEnabled('Quux'));
+ $this->assertContains('Quux', Features::getEnabled());
+
+ // Disable it
+ Features::disable('Quux');
+ $this->assertFalse(Features::isEnabled('Quux'));
+
+ // Count it
+ $this->assertContains('Quux', Features::getAll());
+ $this->assertContains('Quux', Features::getAvailable());
+ $this->assertNotContains('Quux', Features::getEnabled());
+
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 18, 09:34 (21 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2250463
Default Alt Text
D215.id508.diff (2 KB)

Event Timeline