Files
wc-bootstrap/tests/Stubs/TwigService.php

54 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* Stub for WPBootstrap\Twig\TwigService.
*
* Provides just enough surface for TemplateOverride to resolve
* and render templates during unit tests.
*/
namespace WPBootstrap\Twig;
class TwigService
{
private static ?self $instance = null;
/** @var callable|null Render callback set by tests. */
private static $renderCallback = null;
public static function getInstance(): self
{
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Allow tests to override the render behaviour.
*/
public static function setRenderCallback(?callable $callback): void
{
self::$renderCallback = $callback;
}
/**
* Render a template with the given context.
*/
public function render(string $template, array $context = []): string
{
if (null !== self::$renderCallback) {
return (self::$renderCallback)($template, $context);
}
return '';
}
/**
* Reset singleton between tests.
*/
public static function reset(): void
{
self::$instance = null;
self::$renderCallback = null;
}
}