You've already forked wc-bootstrap
Add PHPUnit test suite with Brain\Monkey (v0.1.6)
Add test infrastructure for isolated unit testing without WordPress/WooCommerce: - 27 tests (54 assertions) covering TemplateOverride and WooCommerceExtension - Brain\Monkey for WordPress function mocking, class stubs for TwigService and WC_Product - PHPUnit test job added to Gitea CI pipeline between lint and build-release - Test artifacts excluded from release packages Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
53
tests/Stubs/TwigService.php
Normal file
53
tests/Stubs/TwigService.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
21
tests/Stubs/WcProduct.php
Normal file
21
tests/Stubs/WcProduct.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* Stub for WC_Product.
|
||||
*
|
||||
* Minimal implementation for type-hint satisfaction in unit tests.
|
||||
*/
|
||||
|
||||
class WC_Product
|
||||
{
|
||||
private int $id;
|
||||
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function get_id(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user