You've already forked wc-composable-product
Add PHPUnit test suite, PSR-4 refactor, lint+test CI jobs (v1.3.1)
- 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>
This commit is contained in:
11
tests/stubs/class-wc-admin-settings.php
Normal file
11
tests/stubs/class-wc-admin-settings.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Minimal WC_Admin_Settings stub for unit testing.
|
||||
*/
|
||||
class WC_Admin_Settings {
|
||||
public static function output_fields($options) {
|
||||
}
|
||||
|
||||
public static function save_fields($options) {
|
||||
}
|
||||
}
|
||||
15
tests/stubs/class-wc-cart.php
Normal file
15
tests/stubs/class-wc-cart.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Minimal WC_Cart stub for unit testing.
|
||||
*/
|
||||
class WC_Cart {
|
||||
protected $cart_contents = [];
|
||||
|
||||
public function get_cart() {
|
||||
return $this->cart_contents;
|
||||
}
|
||||
|
||||
public function set_cart_contents($contents) {
|
||||
$this->cart_contents = $contents;
|
||||
}
|
||||
}
|
||||
35
tests/stubs/class-wc-data.php
Normal file
35
tests/stubs/class-wc-data.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Minimal WC_Data stub for unit testing.
|
||||
*/
|
||||
class WC_Data {
|
||||
protected $id = 0;
|
||||
protected $data = [];
|
||||
protected $meta_data = [];
|
||||
|
||||
public function __construct($id = 0) {
|
||||
if (is_numeric($id) && $id > 0) {
|
||||
$this->id = (int) $id;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function set_id($id) {
|
||||
$this->id = (int) $id;
|
||||
}
|
||||
|
||||
public function get_meta($key, $single = true, $context = 'view') {
|
||||
return $this->meta_data[$key] ?? ($single ? '' : []);
|
||||
}
|
||||
|
||||
public function update_meta_data($key, $value, $meta_id = 0) {
|
||||
$this->meta_data[$key] = $value;
|
||||
}
|
||||
|
||||
public function save() {
|
||||
return $this->get_id();
|
||||
}
|
||||
}
|
||||
28
tests/stubs/class-wc-order-item-product.php
Normal file
28
tests/stubs/class-wc-order-item-product.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Minimal WC_Order_Item_Product stub for unit testing.
|
||||
*/
|
||||
class WC_Order_Item_Product extends WC_Data {
|
||||
protected $product = null;
|
||||
protected $quantity = 1;
|
||||
|
||||
public function get_product() {
|
||||
return $this->product;
|
||||
}
|
||||
|
||||
public function set_product($product) {
|
||||
$this->product = $product;
|
||||
}
|
||||
|
||||
public function get_quantity() {
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
public function set_quantity($quantity) {
|
||||
$this->quantity = $quantity;
|
||||
}
|
||||
|
||||
public function add_meta_data($key, $value, $unique = false) {
|
||||
$this->meta_data[$key] = $value;
|
||||
}
|
||||
}
|
||||
24
tests/stubs/class-wc-order.php
Normal file
24
tests/stubs/class-wc-order.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Minimal WC_Order stub for unit testing.
|
||||
*/
|
||||
class WC_Order extends WC_Data {
|
||||
protected $items = [];
|
||||
protected $order_notes = [];
|
||||
|
||||
public function get_items($type = '') {
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
public function set_items($items) {
|
||||
$this->items = $items;
|
||||
}
|
||||
|
||||
public function add_order_note($note) {
|
||||
$this->order_notes[] = $note;
|
||||
}
|
||||
|
||||
public function get_order_notes() {
|
||||
return $this->order_notes;
|
||||
}
|
||||
}
|
||||
88
tests/stubs/class-wc-product.php
Normal file
88
tests/stubs/class-wc-product.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* Minimal WC_Product stub for unit testing.
|
||||
*/
|
||||
class WC_Product extends WC_Data {
|
||||
protected $supports = [];
|
||||
protected $data = [
|
||||
'name' => '',
|
||||
'price' => '',
|
||||
'regular_price' => '',
|
||||
'status' => 'publish',
|
||||
];
|
||||
|
||||
public function get_type() {
|
||||
return 'simple';
|
||||
}
|
||||
|
||||
public function get_name($context = 'view') {
|
||||
return $this->data['name'] ?? '';
|
||||
}
|
||||
|
||||
public function get_price($context = 'view') {
|
||||
return $this->data['price'] ?? '';
|
||||
}
|
||||
|
||||
public function get_regular_price($context = 'view') {
|
||||
return $this->data['regular_price'] ?? '';
|
||||
}
|
||||
|
||||
public function get_price_html() {
|
||||
return '';
|
||||
}
|
||||
|
||||
public function get_permalink() {
|
||||
return '';
|
||||
}
|
||||
|
||||
public function get_image_id($context = 'view') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function get_stock_quantity($context = 'view') {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_stock_status($context = 'view') {
|
||||
return 'instock';
|
||||
}
|
||||
|
||||
public function get_children() {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function is_type($type) {
|
||||
return $this->get_type() === $type;
|
||||
}
|
||||
|
||||
public function is_purchasable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function is_in_stock() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function managing_stock() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function backorders_allowed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function is_sold_individually() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function set_price($price) {
|
||||
$this->data['price'] = $price;
|
||||
}
|
||||
|
||||
public function set_stock_quantity($quantity) {
|
||||
}
|
||||
|
||||
public function supports($feature) {
|
||||
return in_array($feature, $this->supports, true);
|
||||
}
|
||||
}
|
||||
29
tests/stubs/class-wc-settings-page.php
Normal file
29
tests/stubs/class-wc-settings-page.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Minimal WC_Settings_Page stub for unit testing.
|
||||
*/
|
||||
class WC_Settings_Page {
|
||||
protected $id = '';
|
||||
protected $label = '';
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function get_id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function get_settings() {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function output() {
|
||||
}
|
||||
|
||||
public function save() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user