Skip to content

Commit 90a6a83

Browse files
authored
Workflows
1 parent 0d4fd5f commit 90a6a83

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

.github/workflows/phpunit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
uses: ramsey/composer-install@v2
7676
with:
7777
dependency-versions: highest
78-
composer-options: "--prefer-dist --no-suggest --no-progress"
78+
composer-options: "--prefer-dist --no-progress"
7979

8080
- name: Prepare Database
8181
run: |

tests/bootstrap.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,24 @@
3535
* Manually load the plugin being tested.
3636
*/
3737
function _manually_load_plugin() {
38-
// Explicitly include the main plugin file
38+
// Define global $wp_widget_factory to prevent null reference errors
39+
global $wp_widget_factory;
40+
$wp_widget_factory = (object) ['widgets' => []];
41+
42+
// Add a mock register_widget function that works with our fake widget factory
43+
if (!function_exists('register_widget')) {
44+
function register_widget($widget) {
45+
global $wp_widget_factory;
46+
$wp_widget_factory->widgets[] = $widget;
47+
return true;
48+
}
49+
}
50+
51+
// Now load the plugin
3952
require_once dirname( __DIR__ ) . '/simple-wp-optimizer.php';
4053

41-
// Make sure the plugin gets initialized
54+
// Initialize the plugin without triggering widgets_init
55+
remove_all_actions('widgets_init');
4256
do_action('plugins_loaded');
4357
do_action('init');
4458
}

tests/test-plugin.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@
66
*/
77

88
/**
9-
* Sample test case.
9+
* Simple test case for Simple WP Optimizer plugin.
1010
*/
1111
class Test_Simple_WP_Optimizer extends WP_UnitTestCase {
1212
/**
1313
* Test that the plugin can be loaded correctly.
14+
*
15+
* This test simply checks that the plugin loads in WordPress
16+
* without causing any errors.
1417
*/
1518
public function test_plugin_loaded() {
1619
// Load the plugin directly to ensure it's available for testing
1720
require_once dirname( __DIR__ ) . '/simple-wp-optimizer.php';
1821

19-
// Check for specific functions that we know exist in the plugin
20-
$this->assertTrue(
21-
function_exists( 'es_optimizer_init_settings' ) ||
22-
function_exists( 'disable_emojis' ) ||
23-
function_exists( 'remove_jquery_migrate' ),
24-
'Plugin core functions not found, plugin may not be loaded correctly.'
25-
);
22+
// Check for at least one function to verify the plugin loaded
23+
$this->assertTrue(function_exists('es_optimizer_init_settings'), 'Plugin was not loaded correctly');
2624
}
2725
}

0 commit comments

Comments
 (0)