Return single instance from wc_get_logger
Remove class include from wc_get_logger (should be autoloaded). Add tests for wc_get_logger.
This commit is contained in:
parent
4318b3aa53
commit
9ba616b2c1
|
@ -1416,11 +1416,12 @@ function wc_get_rounding_precision() {
|
||||||
* @return WC_Logger
|
* @return WC_Logger
|
||||||
*/
|
*/
|
||||||
function wc_get_logger() {
|
function wc_get_logger() {
|
||||||
if ( ! class_exists( 'WC_Logger' ) ) {
|
static $logger = null;
|
||||||
include_once( dirname( __FILE__ ) . '/class-wc-logger.php' );
|
if ( null === $logger ) {
|
||||||
|
$class = apply_filters( 'woocommerce_logging_class', 'WC_Logger' );
|
||||||
|
$logger = new $class;
|
||||||
}
|
}
|
||||||
$class = apply_filters( 'woocommerce_logging_class', 'WC_Logger' );
|
return $logger;
|
||||||
return new $class;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -238,6 +238,20 @@ class WC_Tests_Core_Functions extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( $log_dir . 'unit-tests-' . $hash_name . '.log', wc_get_log_file_path( 'unit-tests' ) );
|
$this->assertEquals( $log_dir . 'unit-tests-' . $hash_name . '.log', wc_get_log_file_path( 'unit-tests' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test wc_get_logger().
|
||||||
|
*
|
||||||
|
* @since 2.8
|
||||||
|
*/
|
||||||
|
public function test_wc_get_logger() {
|
||||||
|
$log_a = wc_get_logger();
|
||||||
|
$log_b = wc_get_logger();
|
||||||
|
|
||||||
|
$this->assertInstanceOf( WC_Logger::class, $log_a );
|
||||||
|
$this->assertInstanceOf( WC_Logger::class, $log_b );
|
||||||
|
$this->assertSame( $log_a, $log_b, '`wc_get_logger()` should return the same instance' );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test wc_get_core_supported_themes().
|
* Test wc_get_core_supported_themes().
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue