You've already forked wc-composable-product
- 57 unit tests covering ProductType, StockManager, CartHandler, Plugin, Admin/ProductData, Admin/Settings using Brain Monkey + Mockery - WooCommerce class stubs for testing without WP installation - PHP lint and test jobs in release workflow (test gate blocks release) - PSR-4 namespace change: WC_Composable_Product -> Magdev\WcComposableProduct - PascalCase filenames for all classes under includes/ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
73 lines
1.9 KiB
PHP
73 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Tests
|
|
*
|
|
* @package Magdev\WcComposableProduct\Tests
|
|
*/
|
|
|
|
namespace Magdev\WcComposableProduct\Tests\Unit;
|
|
|
|
use Magdev\WcComposableProduct\Tests\TestCase;
|
|
use Magdev\WcComposableProduct\Plugin;
|
|
use Brain\Monkey\Functions;
|
|
|
|
class PluginTest extends TestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
// Reset the singleton instance between tests
|
|
$reflection = new \ReflectionClass(Plugin::class);
|
|
$property = $reflection->getProperty('instance');
|
|
$property->setAccessible(true);
|
|
$property->setValue(null, null);
|
|
}
|
|
|
|
public function testInstance_ReturnsSingleton(): void
|
|
{
|
|
$instance1 = Plugin::instance();
|
|
$instance2 = Plugin::instance();
|
|
|
|
$this->assertSame($instance1, $instance2);
|
|
}
|
|
|
|
public function testInstance_ReturnsPluginClass(): void
|
|
{
|
|
$instance = Plugin::instance();
|
|
|
|
$this->assertInstanceOf(Plugin::class, $instance);
|
|
}
|
|
|
|
public function testAddProductType_AddsComposableToTypes(): void
|
|
{
|
|
$plugin = Plugin::instance();
|
|
$types = $plugin->add_product_type([]);
|
|
|
|
$this->assertArrayHasKey('composable', $types);
|
|
}
|
|
|
|
public function testProductClass_ReturnsCustomClassForComposable(): void
|
|
{
|
|
$plugin = Plugin::instance();
|
|
$class = $plugin->product_class('WC_Product', 'composable');
|
|
|
|
$this->assertSame('Magdev\WcComposableProduct\ProductType', $class);
|
|
}
|
|
|
|
public function testProductClass_PassesThroughForOtherTypes(): void
|
|
{
|
|
$plugin = Plugin::instance();
|
|
$class = $plugin->product_class('WC_Product', 'simple');
|
|
|
|
$this->assertSame('WC_Product', $class);
|
|
}
|
|
|
|
public function testGetTwig_ReturnsTwigEnvironment(): void
|
|
{
|
|
$plugin = Plugin::instance();
|
|
|
|
$this->assertInstanceOf(\Twig\Environment::class, $plugin->get_twig());
|
|
}
|
|
}
|