Skip to content

Commit d59f5f3

Browse files
test: add WP-CLI mock helper for unit tests
- Add wordpress-cli.php helper file with mock WP_CLI class - Include WP-CLI mock in TinyTestCase for all test files - Provides mock implementations for WP_CLI methods like log, success, warning - Includes WP_CLI\Utils\make_progress_bar mock with MockProgressBar class
1 parent ad2ed3c commit d59f5f3

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

test/helpers/wordpress-cli.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/**
4+
* Mock WP_CLI to be used in php unit tests
5+
*/
6+
class WP_CLI
7+
{
8+
public static function log($message) {}
9+
10+
public static function success($message) {}
11+
12+
public static function warning($message) {}
13+
14+
public static function add_command($name, $command) {}
15+
}
16+
17+
namespace WP_CLI\Utils {
18+
class MockProgressBar
19+
{
20+
public function tick() {}
21+
22+
public function finish() {}
23+
}
24+
25+
function make_progress_bar($label, $count)
26+
{
27+
return new MockProgressBar();
28+
}
29+
}

test/unit/TinyTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require_once dirname( __FILE__ ) . '/../helpers/mock-http-stream-wrapper.php';
44
require_once dirname( __FILE__ ) . '/../helpers/mock-tinify-client.php';
55
require_once dirname( __FILE__ ) . '/../helpers/wordpress.php';
6+
require_once dirname( __FILE__ ) . '/../helpers/wordpress-cli.php';
67
require_once dirname( __FILE__ ) . '/../../src/config/class-tiny-config.php';
78
require_once 'vendor/autoload.php';
89

0 commit comments

Comments
 (0)