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
+254
-30
No files matched your search
+14
-14
@@ -11,7 +11,7 @@ use WPALLSTARS\PluginStarterTemplate\Core;
|
||||
/**
|
||||
* Admin test case.
|
||||
*/
|
||||
class AdminTest extends WP_Mock\Tools\TestCase {
|
||||
class AdminTest extends \WP_Mock\Tools\TestCase {
|
||||
|
||||
/**
|
||||
* Test instance
|
||||
@@ -30,21 +30,21 @@ class AdminTest extends WP_Mock\Tools\TestCase {
|
||||
/**
|
||||
* Set up test environment
|
||||
*/
|
||||
public function setUp(): void {
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
|
||||
// Set up mocks
|
||||
WP_Mock::setUp();
|
||||
|
||||
|
||||
// Mock Core class
|
||||
$this->core = $this->createMock(Core::class);
|
||||
|
||||
|
||||
// Set up WordPress function mocks
|
||||
WP_Mock::userFunction('add_action', [
|
||||
'times' => 1,
|
||||
'args' => ['admin_enqueue_scripts', \WP_Mock\Functions::type('array')],
|
||||
]);
|
||||
|
||||
|
||||
// Create instance of Admin class
|
||||
$this->admin = new Admin($this->core);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class AdminTest extends WP_Mock\Tools\TestCase {
|
||||
/**
|
||||
* Tear down test environment
|
||||
*/
|
||||
public function tearDown(): void {
|
||||
public function tearDown() {
|
||||
WP_Mock::tearDown();
|
||||
parent::tearDown();
|
||||
}
|
||||
@@ -74,38 +74,38 @@ class AdminTest extends WP_Mock\Tools\TestCase {
|
||||
'times' => 1,
|
||||
'args' => ['wpst-admin-styles', \WP_Mock\Functions::type('string'), [], \WP_Mock\Functions::type('string')],
|
||||
]);
|
||||
|
||||
|
||||
WP_Mock::userFunction('wp_enqueue_script', [
|
||||
'times' => 1,
|
||||
'args' => ['wpst-admin-scripts', \WP_Mock\Functions::type('string'), ['jquery'], \WP_Mock\Functions::type('string'), true],
|
||||
]);
|
||||
|
||||
|
||||
WP_Mock::userFunction('wp_localize_script', [
|
||||
'times' => 1,
|
||||
'args' => ['wpst-admin-scripts', 'wpstData', \WP_Mock\Functions::type('array')],
|
||||
]);
|
||||
|
||||
|
||||
WP_Mock::userFunction('esc_html__', [
|
||||
'times' => 2,
|
||||
'args' => [\WP_Mock\Functions::type('string'), 'wp-plugin-starter-template'],
|
||||
'return' => 'Translated string',
|
||||
]);
|
||||
|
||||
|
||||
WP_Mock::userFunction('admin_url', [
|
||||
'times' => 1,
|
||||
'args' => ['admin-ajax.php'],
|
||||
'return' => 'http://example.org/wp-admin/admin-ajax.php',
|
||||
]);
|
||||
|
||||
|
||||
WP_Mock::userFunction('wp_create_nonce', [
|
||||
'times' => 1,
|
||||
'args' => ['wpst-admin-nonce'],
|
||||
'return' => '1234567890',
|
||||
]);
|
||||
|
||||
|
||||
// Call the method
|
||||
$this->admin->enqueue_admin_assets('plugins.php');
|
||||
|
||||
|
||||
// If we get here, the test passed
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
+6
-6
@@ -10,7 +10,7 @@ use WPALLSTARS\PluginStarterTemplate\Core;
|
||||
/**
|
||||
* Core test case.
|
||||
*/
|
||||
class CoreTest extends WP_Mock\Tools\TestCase {
|
||||
class CoreTest extends \WP_Mock\Tools\TestCase {
|
||||
|
||||
/**
|
||||
* Test instance
|
||||
@@ -22,12 +22,12 @@ class CoreTest extends WP_Mock\Tools\TestCase {
|
||||
/**
|
||||
* Set up test environment
|
||||
*/
|
||||
public function setUp(): void {
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
|
||||
// Set up mocks
|
||||
WP_Mock::setUp();
|
||||
|
||||
|
||||
// Create instance of Core class
|
||||
$this->core = new Core();
|
||||
}
|
||||
@@ -35,7 +35,7 @@ class CoreTest extends WP_Mock\Tools\TestCase {
|
||||
/**
|
||||
* Tear down test environment
|
||||
*/
|
||||
public function tearDown(): void {
|
||||
public function tearDown() {
|
||||
WP_Mock::tearDown();
|
||||
parent::tearDown();
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class CoreTest extends WP_Mock\Tools\TestCase {
|
||||
*/
|
||||
public function test_filter_content() {
|
||||
$content = 'Test content';
|
||||
|
||||
|
||||
// Test that filter_content returns the content
|
||||
$this->assertEquals($content, $this->core->filter_content($content));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user