You've already forked wp-prometheus
189 tests across 8 test classes covering all core plugin classes: CustomMetricBuilder, StorageFactory, Authentication, DashboardProvider, RuntimeCollector, Installer, Collector, and MetricsEndpoint. Added test job to Gitea release workflow that gates build-release. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Magdev\WpPrometheus\Tests\Helpers;
|
|
|
|
/**
|
|
* Controllable state for global WordPress function stubs.
|
|
*
|
|
* Used by the bootstrap's global get_option() stub so that tests
|
|
* for global-scope functions (e.g., wp_prometheus_authenticate_request)
|
|
* can control return values without php-mock (which requires namespaces).
|
|
*/
|
|
class GlobalFunctionState
|
|
{
|
|
/** @var array<string, mixed> Simulated WordPress options. */
|
|
public static array $options = [];
|
|
|
|
/** @var array<string, int> Track function call counts. */
|
|
public static array $callCounts = [];
|
|
|
|
/** @var array<string, list<mixed>> Track arguments passed to functions. */
|
|
public static array $callArgs = [];
|
|
|
|
/**
|
|
* Reset all state. Call in setUp()/tearDown().
|
|
*/
|
|
public static function reset(): void
|
|
{
|
|
self::$options = [];
|
|
self::$callCounts = [];
|
|
self::$callArgs = [];
|
|
}
|
|
|
|
/**
|
|
* Record a function call for later assertions.
|
|
*/
|
|
public static function recordCall(string $function, mixed ...$args): void
|
|
{
|
|
self::$callCounts[$function] = (self::$callCounts[$function] ?? 0) + 1;
|
|
self::$callArgs[$function][] = $args;
|
|
}
|
|
|
|
/**
|
|
* Get call count for a function.
|
|
*/
|
|
public static function getCallCount(string $function): int
|
|
{
|
|
return self::$callCounts[$function] ?? 0;
|
|
}
|
|
}
|