Skip to content

Commit

Permalink
Switch to ReflectionProperty to setStaticPropertyValue
Browse files Browse the repository at this point in the history
  • Loading branch information
luisherranz committed Dec 23, 2023
1 parent 76e8726 commit f0fa726
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions tests/phpunit/tests/modules/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,21 @@ class Tests_Modules_Functions extends WP_UnitTestCase {
public function set_up() {
parent::set_up();

$this->registered = new ReflectionProperty( 'WP_Modules', 'registered' );
$this->registered->setAccessible( true );
$this->old_registered = $this->registered->getValue();
$this->registered->setValue( array() );

$this->enqueued_before_registered = new ReflectionProperty( 'WP_Modules', 'enqueued_before_registered' );
$this->enqueued_before_registered->setAccessible( true );
$this->old_enqueued_before_registered = $this->enqueued_before_registered->getValue();
$this->enqueued_before_registered->setValue( array() );
$wp_modules = new ReflectionClass( 'WP_Modules' );

$this->old_registered = $wp_modules->getStaticPropertyValue( 'registered' );
$this->old_enqueued_before_registered = $wp_modules->getStaticPropertyValue( 'enqueued_before_registered' );

$wp_modules->setStaticPropertyValue( 'registered', array() );
$wp_modules->setStaticPropertyValue( 'enqueued_before_registered', array() );
}

public function tear_down() {
$this->registered->setValue( $this->old_registered );
$this->enqueued_before_registered->setValue( $this->old_enqueued_before_registered );
$wp_modules = new ReflectionClass( 'WP_Modules' );

$wp_modules->setStaticPropertyValue( 'registered', $this->old_registered );
$wp_modules->setStaticPropertyValue( 'enqueued_before_registered', $this->old_enqueued_before_registered );

parent::tear_down();
}

Expand Down

0 comments on commit f0fa726

Please sign in to comment.