Skip to content

Commit

Permalink
Clear up test caching
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Jun 17, 2024
1 parent 3d05810 commit b879472
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions phpunit/block-supports/block-style-variations-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,41 @@
*/

class WP_Block_Supports_Block_Style_Variations_Test extends WP_UnitTestCase {
/**
* Administrator ID.
*
* @var int
*/
protected static $administrator_id;

/**
* WP_Theme_JSON_Resolver_Gutenberg::$blocks_cache property.
*
* @var ReflectionProperty
*/
private static $property_blocks_cache;

/**
* Original value of the WP_Theme_JSON_Resolver_Gutenberg::$blocks_cache property.
*
* @var array
*/
private static $property_blocks_cache_orig_value;

/**
* WP_Theme_JSON_Resolver_Gutenberg::$core property.
*
* @var ReflectionProperty
*/
private static $property_core;

/**
* Original value of the WP_Theme_JSON_Resolver_Gutenberg::$core property.
*
* @var WP_Theme_JSON_Gutenberg
*/
private static $property_core_orig_value;

/**
* Theme root directory.
*
Expand All @@ -23,6 +58,31 @@ class WP_Block_Supports_Block_Style_Variations_Test extends WP_UnitTestCase {
*/
private $orig_theme_dir;

public static function set_up_before_class() {
parent::set_up_before_class();

self::$administrator_id = self::factory()->user->create(
array(
'role' => 'administrator',
'user_email' => 'administrator@example.com',
)
);

static::$property_blocks_cache = new ReflectionProperty( WP_Theme_JSON_Resolver_Gutenberg::class, 'blocks_cache' );
static::$property_blocks_cache->setAccessible( true );
static::$property_blocks_cache_orig_value = static::$property_blocks_cache->getValue();

static::$property_core = new ReflectionProperty( WP_Theme_JSON_Resolver_Gutenberg::class, 'core' );
static::$property_core->setAccessible( true );
static::$property_core_orig_value = static::$property_core->getValue();
}

public static function tear_down_after_class() {
static::$property_blocks_cache->setValue( null, static::$property_blocks_cache_orig_value );
static::$property_core->setValue( null, static::$property_core_orig_value );
parent::tear_down_after_class();
}

public function set_up() {
parent::set_up();
$this->theme_root = realpath( dirname( __DIR__ ) . '/data/themedir1' );
Expand Down

0 comments on commit b879472

Please sign in to comment.