Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/wp-includes/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -810,13 +810,19 @@ function wp_set_wpdb_vars() {
function wp_using_ext_object_cache( $using = null ) {
global $_wp_using_ext_object_cache;

// Save the current state to return later.
$current_using = $_wp_using_ext_object_cache;

if ( null !== $using ) {
$_wp_using_ext_object_cache = $using;
$_wp_using_ext_object_cache = (bool) $using;
}

return $current_using;
if ( null === $_wp_using_ext_object_cache ) {
// If the global is uninitialized, the value would be null, which violates the type signature.
return false;
}

return (bool) $current_using;
}

/**
Expand Down
32 changes: 32 additions & 0 deletions tests/phpunit/tests/load/wpUsingExtObjectCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* Tests for wp_using_ext_object_cache().
*
* @group load
*
* @covers ::wp_using_ext_object_cache
*/
class Tests_Load_wpUsingExtObjectCache extends WP_UnitTestCase {

private $orig_using_ext_cache;

public function set_up() {
parent::set_up();
global $_wp_using_ext_object_cache;

$this->orig_using_ext_cache = $_wp_using_ext_object_cache;
}

public function tear_down() {
global $_wp_using_ext_object_cache;

$_wp_using_ext_object_cache = $this->orig_using_ext_cache;
parent::tear_down();
}

public function test_should_always_return_boolean() {
wp_using_ext_object_cache( 1 );
$this->assertIsBool( wp_using_ext_object_cache() );
}
}
Loading