diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..49e09e7 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,40 @@ +name: PHP +on: [push] +jobs: + lint-test: + name: ${{ matrix.php-versions }} Lint & Test + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php-versions: ['8.1'] + steps: + - name: Checkout + uses: actions/checkout@v3 + + # Docs: https://github.com/shivammathur/setup-php + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install Composer dependencies + run: composer install + + - name: PHP Lint + run: vendor/bin/phpcs + + - name: PHP test + run: vendor/bin/phpunit --testdox diff --git a/phpunit.xml b/phpunit.xml index 5226b6a..c9abd89 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,16 +1,9 @@ - - - - ./tests/Unit/ - - - + + + + + ./tests/Unit/ + + diff --git a/plugin.php b/plugin.php index 8f7beb4..2a9b41a 100644 --- a/plugin.php +++ b/plugin.php @@ -19,6 +19,7 @@ declare( strict_types = 1 ); namespace MR\FeatureFlags; + use MR\FeatureFlags\Api\Flags; // If this file is called directly, abort. @@ -52,8 +53,8 @@ function(): void { $feature_flag_meta = get_option( FeatureFlags::$option_name ); - $flags_list = []; - if(is_array($feature_flag_meta)) { + $flags_list = []; + if ( is_array( $feature_flag_meta ) ) { $flags_list = $feature_flag_meta; } @@ -108,7 +109,7 @@ function load_settings_scripts(): void { add_action( 'admin_enqueue_scripts', - function(string $page): void { + function( string $page ): void { $plugin_url = plugin_dir_url( MR_FEATURE_FLAGS_PLUGIN_PATH ); $script_asset_file = include_once plugin_dir_path( MR_FEATURE_FLAGS_PLUGIN_PATH ) . 'build/index.asset.php'; @@ -121,8 +122,8 @@ function(string $page): void { ); $feature_flag_meta = get_option( Utils::$option_name ); - $flags_list = []; - if(is_array($feature_flag_meta)) { + $flags_list = []; + if ( is_array( $feature_flag_meta ) ) { $flags_list = $feature_flag_meta; } @@ -146,9 +147,9 @@ function(string $page): void { -add_filter( 'plugin_action_links_mr-feature-flags/plugin.php', function ( $links ) - { - +add_filter( + 'plugin_action_links_mr-feature-flags/plugin.php', + function ( $links ) { $url = esc_url( add_query_arg( 'page', diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a04dd1b..4dd974b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,4 +1,10 @@