Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

Stable tag: 0.3.2
Requires at least: 6.2
Tested up to: 6.6
Tested up to: 6.8
Requires PHP: 8.1

WordPress Feature flags plugin allow developers to configure features in plugins/themes behind the feature flags on both
Expand Down
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
},
"require-dev": {
"brain/monkey": "^2.6",
"newsuk/nuk-wp-phpcs-config": "^0.2.0",
"newsuk/nuk-wp-phpmd-config": "^0.1.0",
"newsuk/nuk-wp-phpstan-config": "^0.1.0",
"phpunit/phpunit": "^9.4",
"yoast/wp-test-utils": "^1.2"
"yoast/wp-test-utils": "^1.2",
"squizlabs/php_codesniffer": "^3.7",
"m0hanraj/phpcs-config": "0.2.1",
"m0hanraj/phpstan-config": "0.1.0",
"m0hanraj/phpmd-config": "0.1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -29,7 +30,8 @@
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
"phpstan/extension-installer": true,
"ergebnis/composer-normalize": true
},
"platform": {
"php": "8.1"
Expand Down
1,908 changes: 1,369 additions & 539 deletions composer.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion includes/Flag.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ class Flag {
/**
* Check if given feature is enabled or not.
*
* @since 0.1.0
*
* @param string $flag name of the flag.
* @return bool
* @since 0.1.0
*/
public static function is_enabled( string $flag ): bool {
$flags = get_option( self::$option_name, [] );
Expand Down
3 changes: 2 additions & 1 deletion includes/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ class Helper {
/**
* Flag search helper, returns true if flag is found and enabled.
*
* @since 0.1.0
*
* @param array<int, array{id: int, name: string, enabled: bool}> $flags flags array.
* @param string $field field to search.
* @param string $flag name of the flag.
* @return boolean
* @since 0.1.0
*/
public function search_flag( $flags, $field, $flag ) {

Expand Down
6 changes: 4 additions & 2 deletions includes/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ class Settings {
/**
* Register feature flag settings page.
*
* @return void
* @since 0.1.0
*
* @return void
*/
public function register_feature_settings() {
add_action( 'admin_menu', [ $this, 'register_settings' ] );
Expand All @@ -31,8 +32,9 @@ public function register_feature_settings() {
/**
* Register settings action method.
*
* @return void
* @since 0.1.0
*
* @return void
*/
public function register_settings() {

Expand Down
4 changes: 2 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<ruleset name="NewsUK WP PHPCS Rules">
<rule ref="NewsUK"/>
<ruleset name="WP PHPCS Rules">
<rule ref="WPDev"/>
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
Expand Down
2 changes: 1 addition & 1 deletion phpmd.xml.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<ruleset>
<rule ref="vendor/newsuk/nuk-wp-phpmd-config/ruleset.xml" />
<rule ref="vendor/m0hanraj/phpmd-config/ruleset.xml" />
</ruleset>
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/**
* The plugin bootstrap file
*
* @since 0.1.0
* @package codeb-feature-flags
* @since 0.1.0
*
* @wordpress-plugin
* Plugin Name: Feature Flags
Expand Down
68 changes: 43 additions & 25 deletions tests/integration/FlagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,70 @@
use CodeB\FeatureFlags\Flag;
use Yoast\WPTestUtils\WPIntegration\TestCase;

class FlagTest extends TestCase{
class FlagTest extends TestCase {

public function test_is_enabled_returns_true_if_flags_exists_and_enabled(): void {
// Set up test data
$optionValue = [['id' => 1, 'name' => 'test', 'enabled' => true ]];
update_option(Flag::$option_name, $optionValue);

$result = Flag::is_enabled('test');

$this->assertTrue($result);
$option_value = [
[
'id' => 1,
'name' => 'test',
'enabled' => true,
],
];
update_option( Flag::$option_name, $option_value );

$result = Flag::is_enabled( 'test' );

$this->assertTrue( $result );
}

public function test_is_enabled_returns_false_if_flags_exists_and_disabled(): void {
// Set up test data
$optionValue = [['id' => 1, 'name' => 'test', 'enabled' => false ]];
update_option(Flag::$option_name, $optionValue);

$result = Flag::is_enabled('test');

$this->assertFalse($result);
$option_value = [
[
'id' => 1,
'name' => 'test',
'enabled' => false,
],
];
update_option( Flag::$option_name, $option_value );

$result = Flag::is_enabled( 'test' );

$this->assertFalse( $result );
}

public function test_is_enabled_returns_false_if_flags_not_exists(): void {
// Set up test data
$optionValue = [['id' => 1, 'name' => 'test2', 'enabled' => true ]];
update_option(Flag::$option_name, $optionValue);

$result = Flag::is_enabled('test');

$this->assertFalse($result);
$option_value = [
[
'id' => 1,
'name' => 'test2',
'enabled' => true,
],
];
update_option( Flag::$option_name, $option_value );

$result = Flag::is_enabled( 'test' );

$this->assertFalse( $result );
}

public function test_is_enabled_returns_false_if_option_is_empty(): void {
// Set up test data
$optionValue = [];
update_option(Flag::$option_name, $optionValue);
$option_value = [];
update_option( Flag::$option_name, $option_value );

$result = Flag::is_enabled('test');
$result = Flag::is_enabled( 'test' );

$this->assertFalse($result);
$this->assertFalse( $result );
}

public function test_is_enabled_returns_false_if_option_not_exists(): void {

$result = Flag::is_enabled('test');
$result = Flag::is_enabled( 'test' );

$this->assertFalse($result);
$this->assertFalse( $result );
}
}
Loading
Loading