Last active
June 3, 2025 13:30
-
-
Save pramodjodhani/e1437b6db8dda9a303be0da3bb8ffce5 to your computer and use it in GitHub Desktop.
Clock simulation code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use StellarPay\Core\ValueObjects\WebhookEventType; | |
use StellarPay\Core\Support\Facades\DateTime\Temporal; | |
use StellarPay\Core\Support\Facades\DateTime\TemporalFacade; | |
use StellarPay\Core\Webhooks\EventProcessor; | |
use StellarPay\Core\Webhooks\EventResponse; | |
use StellarPay\PaymentGateways\Stripe\Webhook\WebhookRegisterer; | |
use function StellarPay\Core\container; | |
const SP_CLOCK_TEST_OPTION_NAME = 'stellarpay_clock_test_frozen_timestamp'; | |
function sp_clock_test_init() { | |
class TestHelperTestClockReady extends EventProcessor { | |
public function __construct( | |
EventResponse $eventResponse, | |
) { | |
parent::__construct($eventResponse); | |
} | |
public function processEvent(): EventResponse | |
{ | |
$eventDTO = $this->getEventDTO(); | |
$frozenTimestamp = $eventDTO->getFrozenTime(); | |
update_option(SP_CLOCK_TEST_OPTION_NAME, $frozenTimestamp); | |
echo 'Timestamp: ' . $frozenTimestamp; | |
die(); | |
} | |
} | |
container(WebhookRegisterer::class)->registerEventHandlers([ | |
WebhookEventType::TEST_HELPER_TEST_CLOCK_READY => TestHelperTestClockReady::class, | |
]); | |
class MockTemporalFacade extends TemporalFacade | |
{ | |
public function getCurrentDateTime(): DateTime | |
{ | |
// echo 'pass'; | |
$frozenTimestamp = get_option(SP_CLOCK_TEST_OPTION_NAME); | |
if (!$frozenTimestamp) { | |
return parent::getCurrentDateTime(); | |
} | |
return new DateTime('@' . $frozenTimestamp, wp_timezone()); | |
} | |
} | |
container()->bind(TemporalFacade::class, MockTemporalFacade::class); | |
// Uncomment to confirm that the clock is frozen. | |
// var_export(Temporal::getCurrentDateTime());` | |
} | |
add_action( 'plugins_loaded', 'sp_clock_test_init', 100 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment