diff --git a/.github/workflows/gemini.yml b/.github/workflows/gemini.yml index 73549f8c3cf..0e658d5de2b 100644 --- a/.github/workflows/gemini.yml +++ b/.github/workflows/gemini.yml @@ -45,7 +45,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: "8.4" - extensions: mysqli, uopz + extensions: mysqli env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get Composer Cache Directory diff --git a/.github/workflows/php-lint-tests.yml b/.github/workflows/php-lint-tests.yml index 2a34aa79432..7986c84efa5 100644 --- a/.github/workflows/php-lint-tests.yml +++ b/.github/workflows/php-lint-tests.yml @@ -191,7 +191,7 @@ jobs: - name: Setup PHP for Tests uses: shivammathur/setup-php@v2 with: - extensions: mysqli, uopz + extensions: mysqli php-version: ${{ matrix.php_version }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/tests/phpunit/integration/Core/Tags/Guards/Tag_Environment_Type_GuardTest.php b/tests/phpunit/integration/Core/Tags/Guards/Tag_Environment_Type_GuardTest.php index a0b1c5d3ba5..bd1f5b23acb 100644 --- a/tests/phpunit/integration/Core/Tags/Guards/Tag_Environment_Type_GuardTest.php +++ b/tests/phpunit/integration/Core/Tags/Guards/Tag_Environment_Type_GuardTest.php @@ -15,6 +15,11 @@ class Tag_Environment_Type_GuardTest extends TestCase { + public function tear_down() { + remove_all_filters( 'googlesitekit_allowed_tag_environment_types' ); + parent::tear_down(); + } + public function test_can_activate_on_post_5_5_version() { if ( ! function_exists( 'wp_get_environment_type' ) ) { // This environment is pre WP-5.5.0 and is skipped. @@ -33,44 +38,45 @@ public function test_can_activate_on_older_versions() { $this->assertTrue( $tagproduction->can_activate(), 'Tag should be able to activate on older versions.' ); } - public function test_can_not_activate_in_development() { - // Pre WP-5.5.0 + public function test_can_not_activate_when_environment_not_allowed() { if ( ! function_exists( 'wp_get_environment_type' ) ) { $this->markTestSkipped( 'Missing wp_get_environment_type() function.' ); } - if ( ! function_exists( 'uopz_set_static' ) ) { - $this->markTestSkipped( 'The uopz extension is not available.' ); - } - $env_type = wp_get_environment_type(); - $tagproduction = new Tag_Environment_Type_Guard(); - uopz_set_static( 'wp_get_environment_type', array( 'current_env' => 'development' ) ); - $this->assertFalse( $tagproduction->can_activate(), 'Tag should not be able to activate in development environment.' ); - uopz_set_static( 'wp_get_environment_type', array( 'current_env' => $env_type ) ); + + $current_env = wp_get_environment_type(); + + add_filter( + 'googlesitekit_allowed_tag_environment_types', + function () use ( $current_env ) { + return array_values( + array_diff( array( 'local', 'development', 'staging', 'production' ), array( $current_env ) ) + ); + } + ); + + $this->assertFalse( + ( new Tag_Environment_Type_Guard() )->can_activate(), + 'Tag should not activate when the current environment is excluded from the allowed list.' + ); } - public function test_can_activate_in_development() { - // Pre WP-5.5.0 + public function test_can_activate_when_environment_is_allowed() { if ( ! function_exists( 'wp_get_environment_type' ) ) { $this->markTestSkipped( 'Missing wp_get_environment_type() function.' ); } - if ( ! function_exists( 'uopz_set_static' ) ) { - $this->markTestSkipped( 'The uopz extension is not available.' ); - } - $env_type = wp_get_environment_type(); - $tagproduction = new Tag_Environment_Type_Guard(); - uopz_set_static( 'wp_get_environment_type', array( 'current_env' => 'development' ) ); - $this->assertFalse( $tagproduction->can_activate(), 'Tag should not be able to activate in development environment by default.' ); - remove_all_filters( 'googlesitekit_allowed_tag_environment_types' ); + $current_env = wp_get_environment_type(); + add_filter( 'googlesitekit_allowed_tag_environment_types', - function ( $allowed_environments ) { - $allowed_environments[] = 'development'; - return $allowed_environments; + function () use ( $current_env ) { + return array( $current_env ); } ); - $this->assertTrue( $tagproduction->can_activate(), 'Tag should be able to activate in development environment when allowed.' ); - uopz_set_static( 'wp_get_environment_type', array( 'current_env' => $env_type ) ); + $this->assertTrue( + ( new Tag_Environment_Type_Guard() )->can_activate(), + 'Tag should activate when the current environment is in the allowed list.' + ); } }