Skip to content

Commit

Permalink
Use \set_transient() on Bluehost Cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHenryIE committed Sep 11, 2024
1 parent 3c5bf92 commit 4d57f4e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion includes/Helpers/Transient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Transient {
*/
protected static function should_use_transients(): bool {
require_once constant( 'ABSPATH' ) . '/wp-admin/includes/plugin.php';
return ! array_key_exists( 'object-cache.php', get_dropins() );
return ! array_key_exists( 'object-cache.php', get_dropins() )
|| 'atomic' === \NewfoldLabs\WP\Context\getContext( 'platform' ); // Bluehost Cloud.
}

/**
Expand Down
27 changes: 27 additions & 0 deletions tests/phpunit/includes/Helpers/TransientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,31 @@ public function test_instance_call_method(): void {

$this->assertEquals( $return_value, $result );
}

/**
* @covers ::should_use_transients
*/
public function test_should_use_transients_bluehost_cloud(): void {

$test_transient_name = uniqid( __FUNCTION__ );

\WP_Mock::userFunction( 'get_dropins' )
->once()
->andReturn( array() );

\WP_Mock::userFunction( 'set_transient' )
->once()
->with( $test_transient_name, 'value', 999 )
->andReturnTrue();

\WP_Mock::userFunction( 'update_option' )
->never();

\NewfoldLabs\WP\Context\setContext( 'platform', 'atomic' );

Transient::set( $test_transient_name, 'value', 999 );

$this->assertConditionsMet();

}
}

0 comments on commit 4d57f4e

Please sign in to comment.