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:
Jon Surrell 2016-12-15 20:52:24 +01:00
parent 4318b3aa53
commit 9ba616b2c1
2 changed files with 19 additions and 4 deletions

View File

@ -1416,11 +1416,12 @@ function wc_get_rounding_precision() {
* @return WC_Logger
*/
function wc_get_logger() {
if ( ! class_exists( 'WC_Logger' ) ) {
include_once( dirname( __FILE__ ) . '/class-wc-logger.php' );
static $logger = null;
if ( null === $logger ) {
$class = apply_filters( 'woocommerce_logging_class', 'WC_Logger' );
$logger = new $class;
}
$class = apply_filters( 'woocommerce_logging_class', 'WC_Logger' );
return new $class;
return $logger;
}
/**

View File

@ -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' ) );
}
/**
* 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().
*