Skip to content

Commit 863d5e3

Browse files
paulopmt1claude
andcommitted
Survicate tests: inline function stubs, drop fixtures dir
The three fixture files only existed to dodge PHP's "function already declared" rule across tests. Each stub is now declared inline inside its test method — namespaced (\WPForTeams\is_wpforteams_site) and global (has_blog_sticker) stubs both go through an eval'd namespace block since the test file itself lives in namespace A8C\FSE. @runInSeparateProcess on each test keeps the function table fresh. Removes tests/php/features/survicate/fixtures/. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 79aa948 commit 863d5e3

4 files changed

Lines changed: 7 additions & 60 deletions

File tree

projects/packages/jetpack-mu-wpcom/tests/php/features/survicate/Survicate_Test.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ public function test_should_load_returns_false_on_p2_site_via_wpforteams() {
282282
define( 'IS_WPCOM', true );
283283
}
284284

285-
require_once __DIR__ . '/fixtures/wpforteams-stub.php';
285+
// Status\Host::is_p2_site() calls \WPForTeams\is_wpforteams_site(); namespaced
286+
// functions can't be declared in a method body, so eval a namespace block.
287+
eval( 'namespace WPForTeams { function is_wpforteams_site( $blog_id ) { return true; } }' ); // phpcs:ignore Squiz.PHP.Eval.Discouraged,MediaWiki.Usage.ForbiddenFunctions.eval
286288

287289
$this->set_admin_context();
288290
$this->create_and_login_user();
@@ -412,7 +414,9 @@ public function test_get_visitor_traits_returns_is_big_sky_site_false_by_default
412414
#[RunInSeparateProcess]
413415
#[PreserveGlobalState( false )]
414416
public function test_get_visitor_traits_returns_is_big_sky_site_true_for_big_sky_enabled_sticker() {
415-
require_once __DIR__ . '/fixtures/big-sky-enabled-sticker-stub.php';
417+
// wpcom_has_blog_sticker() in src/utils.php proxies to the global has_blog_sticker().
418+
// This file lives in namespace A8C\FSE, so use an eval'd global namespace block.
419+
eval( 'namespace { function has_blog_sticker( $sticker, $blog_id ) { return $sticker === "big-sky-enabled"; } }' ); // phpcs:ignore Squiz.PHP.Eval.Discouraged,MediaWiki.Usage.ForbiddenFunctions.eval
416420

417421
global $pagenow;
418422
$pagenow = 'index.php';
@@ -433,7 +437,7 @@ public function test_get_visitor_traits_returns_is_big_sky_site_true_for_big_sky
433437
#[RunInSeparateProcess]
434438
#[PreserveGlobalState( false )]
435439
public function test_get_visitor_traits_returns_is_big_sky_site_true_for_big_sky_free_trial_sticker() {
436-
require_once __DIR__ . '/fixtures/big-sky-free-trial-sticker-stub.php';
440+
eval( 'namespace { function has_blog_sticker( $sticker, $blog_id ) { return $sticker === "big-sky-free-trial"; } }' ); // phpcs:ignore Squiz.PHP.Eval.Discouraged,MediaWiki.Usage.ForbiddenFunctions.eval
437441

438442
global $pagenow;
439443
$pagenow = 'index.php';

projects/packages/jetpack-mu-wpcom/tests/php/features/survicate/fixtures/big-sky-enabled-sticker-stub.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

projects/packages/jetpack-mu-wpcom/tests/php/features/survicate/fixtures/big-sky-free-trial-sticker-stub.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

projects/packages/jetpack-mu-wpcom/tests/php/features/survicate/fixtures/wpforteams-stub.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)