我试着在WC_VERSION
常数
主要类别:
class WC_Custom_Variable_Products_Dependencies {
/** minimum WooCommerce version required by this plugin */
const MINIMUM_WC_VERSION = \'3.7.9\';
public function __construct() {
add_action( \'admin_init\', [$this, \'check_wc_version\']);
}
protected function check_wc_version() {
return version_compare(WC_VERSION, self::MINIMUM_WC_VERSION , \'>=\');
}
}
测试类别:
require_once \'includes/class-wc-custom-variable-products-dependencies.php\';
class WC_Custom_Variable_Products_DependenciesTest extends WP_UnitTestCase {
public function setUp() {
parent::setUp();
$this->class_instance = new WC_Custom_Variable_Products_Dependencies();
}
/**
* Tests the protected functions
*
* @param Object $method
* @return bool
*/
private function makeReflection($method) {
$reflection = new ReflectionClass(\'WC_Custom_Variable_Products_Dependencies\');
$protectedMethod = $reflection->getMethod($method);
$protectedMethod->setAccessible(true);
return $protectedMethod->invokeArgs($this->class_instance, [\'\']);
}
public function test_check_wc_version() {
$result = $this->makeReflection(\'check_wc_version\');
$this->assertTrue($result);
}
}
和PHPunit返回:
Use of undefined constant WC_VERSION - assumed \'WC_VERSION\'
这是否意味着在测试中没有加载Woocommerce?