Fix test workflow issues with WP_Mock, PHP 7.0 compatibility, and code style
Release / Build and Release (push) Canceled after 0s
Release / Build and Release (push) Canceled after 0s
This commit is contained in:
1 parent
af48e84614
commit
31d475beca
9 files changed
+239
-15
No files matched your search
@@ -27,7 +27,15 @@ jobs:
|
|||||||
tools: composer:v2
|
tools: composer:v2
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: composer install --prefer-dist --no-progress
|
run: |
|
||||||
|
if [[ "${{ matrix.php-versions }}" == "7.0" ]]; then
|
||||||
|
composer require --dev phpunit/phpunit:"^6.5" --update-with-dependencies
|
||||||
|
composer require --dev 10up/wp_mock:"0.3.0" --update-with-dependencies
|
||||||
|
composer require --dev antecedent/patchwork:"^2.1.21" --update-with-dependencies
|
||||||
|
else
|
||||||
|
composer install --prefer-dist --no-progress
|
||||||
|
composer require --dev 10up/wp_mock:"0.3.0" --update-with-dependencies
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: ./vendor/bin/phpunit
|
run: ./vendor/bin/phpunit
|
||||||
@@ -51,4 +59,4 @@ jobs:
|
|||||||
run: composer install --prefer-dist --no-progress
|
run: composer install --prefer-dist --no-progress
|
||||||
|
|
||||||
- name: Run PHPCS
|
- name: Run PHPCS
|
||||||
run: ./vendor/bin/phpcs --standard=WordPress --runtime-set installed_paths vendor/wp-coding-standards/wpcs
|
run: ./vendor/bin/phpcs --standard=WordPress --runtime-set installed_paths vendor/wp-coding-standards/wpcs ./includes ./admin ./wp-plugin-starter-template.php
|
||||||
@@ -1 +1,75 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Admin functionality
|
||||||
|
*
|
||||||
|
* @package WPALLSTARS\PluginStarterTemplate
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace WPALLSTARS\PluginStarterTemplate\Admin;
|
||||||
|
|
||||||
|
use WPALLSTARS\PluginStarterTemplate\Core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Admin class
|
||||||
|
*/
|
||||||
|
class Admin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Core instance
|
||||||
|
*
|
||||||
|
* @var Core
|
||||||
|
*/
|
||||||
|
private $core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param Core $core Core instance.
|
||||||
|
*/
|
||||||
|
public function __construct( $core ) {
|
||||||
|
$this->core = $core;
|
||||||
|
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize admin
|
||||||
|
*/
|
||||||
|
public function init() {
|
||||||
|
// Initialize admin
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueue admin assets
|
||||||
|
*
|
||||||
|
* @param string $hook Current admin page.
|
||||||
|
*/
|
||||||
|
public function enqueue_admin_assets( $hook ) {
|
||||||
|
wp_enqueue_style(
|
||||||
|
'wpst-admin-styles',
|
||||||
|
WPST_PLUGIN_URL . 'assets/css/admin.css',
|
||||||
|
[],
|
||||||
|
WPST_VERSION
|
||||||
|
);
|
||||||
|
|
||||||
|
wp_enqueue_script(
|
||||||
|
'wpst-admin-scripts',
|
||||||
|
WPST_PLUGIN_URL . 'assets/js/admin.js',
|
||||||
|
[ 'jquery' ],
|
||||||
|
WPST_VERSION,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
wp_localize_script(
|
||||||
|
'wpst-admin-scripts',
|
||||||
|
'wpstData',
|
||||||
|
[
|
||||||
|
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
|
||||||
|
'nonce' => wp_create_nonce( 'wpst-admin-nonce' ),
|
||||||
|
'strings' => [
|
||||||
|
'success' => esc_html__( 'Success!', 'wp-plugin-starter-template' ),
|
||||||
|
'error' => esc_html__( 'Error!', 'wp-plugin-starter-template' ),
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-2
@@ -14,10 +14,12 @@
|
|||||||
"php": ">=7.0"
|
"php": ">=7.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.0",
|
"phpunit/phpunit": "^6.5 || ^7.5 || ^8.0 || ^9.0",
|
||||||
"squizlabs/php_codesniffer": "^3.5",
|
"squizlabs/php_codesniffer": "^3.5",
|
||||||
"wp-coding-standards/wpcs": "^2.3",
|
"wp-coding-standards/wpcs": "^2.3",
|
||||||
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0"
|
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
|
||||||
|
"10up/wp_mock": "0.3.0",
|
||||||
|
"antecedent/patchwork": "^2.1.21"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
@@ -1 +1,31 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Core functionality for the plugin
|
||||||
|
*
|
||||||
|
* @package WPALLSTARS\PluginStarterTemplate
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace WPALLSTARS\PluginStarterTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Core class
|
||||||
|
*/
|
||||||
|
class Core {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
// Initialize hooks
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example method to filter content
|
||||||
|
*
|
||||||
|
* @param string $content The content to filter.
|
||||||
|
* @return string The filtered content.
|
||||||
|
*/
|
||||||
|
public function filter_content( $content ) {
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1,54 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Main plugin class
|
||||||
|
*
|
||||||
|
* @package WPALLSTARS\PluginStarterTemplate
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace WPALLSTARS\PluginStarterTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plugin class
|
||||||
|
*/
|
||||||
|
class Plugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Core instance
|
||||||
|
*
|
||||||
|
* @var Core
|
||||||
|
*/
|
||||||
|
private $core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plugin file
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $plugin_file;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plugin version
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param string $plugin_file Main plugin file path.
|
||||||
|
* @param string $version Plugin version.
|
||||||
|
*/
|
||||||
|
public function __construct($plugin_file, $version) {
|
||||||
|
$this->plugin_file = $plugin_file;
|
||||||
|
$this->version = $version;
|
||||||
|
$this->core = new Core();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the plugin
|
||||||
|
*/
|
||||||
|
public function init() {
|
||||||
|
// Initialize plugin.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1,58 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Updater functionality for the plugin
|
||||||
|
*
|
||||||
|
* @package WPALLSTARS\PluginStarterTemplate
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace WPALLSTARS\PluginStarterTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updater class
|
||||||
|
*/
|
||||||
|
class Updater {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plugin file
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $plugin_file;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param string $plugin_file Main plugin file path.
|
||||||
|
*/
|
||||||
|
public function __construct($plugin_file) {
|
||||||
|
$this->plugin_file = $plugin_file;
|
||||||
|
$this->init();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the updater
|
||||||
|
*/
|
||||||
|
public function init() {
|
||||||
|
add_filter('plugin_action_links_' . plugin_basename($this->plugin_file), array($this, 'add_update_source_link'));
|
||||||
|
add_action('admin_post_wpst_update_source', array($this, 'handle_update_source'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add update source link to plugin actions
|
||||||
|
*
|
||||||
|
* @param array $links Plugin action links.
|
||||||
|
* @return array Modified plugin action links.
|
||||||
|
*/
|
||||||
|
public function add_update_source_link($links) {
|
||||||
|
$update_source_link = '<a href="' . admin_url('admin-post.php?action=wpst_update_source&plugin=' . plugin_basename($this->plugin_file)) . '">' . esc_html__('Update Source', 'wp-plugin-starter-template') . '</a>';
|
||||||
|
array_unshift($links, $update_source_link);
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle update source selection
|
||||||
|
*/
|
||||||
|
public function handle_update_source() {
|
||||||
|
// Handle update source selection.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ use WPALLSTARS\PluginStarterTemplate\Core;
|
|||||||
/**
|
/**
|
||||||
* Admin test case.
|
* Admin test case.
|
||||||
*/
|
*/
|
||||||
class AdminTest extends WP_Mock\Tools\TestCase {
|
class AdminTest extends \WP_Mock\Tools\TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test instance
|
* Test instance
|
||||||
@@ -30,7 +30,7 @@ class AdminTest extends WP_Mock\Tools\TestCase {
|
|||||||
/**
|
/**
|
||||||
* Set up test environment
|
* Set up test environment
|
||||||
*/
|
*/
|
||||||
public function setUp(): void {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
// Set up mocks
|
// Set up mocks
|
||||||
@@ -52,7 +52,7 @@ class AdminTest extends WP_Mock\Tools\TestCase {
|
|||||||
/**
|
/**
|
||||||
* Tear down test environment
|
* Tear down test environment
|
||||||
*/
|
*/
|
||||||
public function tearDown(): void {
|
public function tearDown() {
|
||||||
WP_Mock::tearDown();
|
WP_Mock::tearDown();
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -10,7 +10,7 @@ use WPALLSTARS\PluginStarterTemplate\Core;
|
|||||||
/**
|
/**
|
||||||
* Core test case.
|
* Core test case.
|
||||||
*/
|
*/
|
||||||
class CoreTest extends WP_Mock\Tools\TestCase {
|
class CoreTest extends \WP_Mock\Tools\TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test instance
|
* Test instance
|
||||||
@@ -22,7 +22,7 @@ class CoreTest extends WP_Mock\Tools\TestCase {
|
|||||||
/**
|
/**
|
||||||
* Set up test environment
|
* Set up test environment
|
||||||
*/
|
*/
|
||||||
public function setUp(): void {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
// Set up mocks
|
// Set up mocks
|
||||||
@@ -35,7 +35,7 @@ class CoreTest extends WP_Mock\Tools\TestCase {
|
|||||||
/**
|
/**
|
||||||
* Tear down test environment
|
* Tear down test environment
|
||||||
*/
|
*/
|
||||||
public function tearDown(): void {
|
public function tearDown() {
|
||||||
WP_Mock::tearDown();
|
WP_Mock::tearDown();
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,12 +27,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// If this file is called directly, abort.
|
// If this file is called directly, abort.
|
||||||
if (!defined('WPINC')) {
|
if ( ! defined( 'WPINC' ) ) {
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the main plugin class
|
// Load the main plugin class.
|
||||||
require_once plugin_dir_path(__FILE__) . 'includes/plugin.php';
|
require_once plugin_dir_path( __FILE__ ) . 'includes/plugin.php';
|
||||||
|
|
||||||
// Initialize the plugin
|
// Initialize the plugin.
|
||||||
new WPALLSTARS\PluginStarterTemplate\Plugin(__FILE__, '0.1.6');
|
new WPALLSTARS\PluginStarterTemplate\Plugin( __FILE__, '0.1.7' );
|
||||||
Reference in new issue
Block a user