PHPackages                             ksfraser/mock-woocommerce - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ksfraser/mock-woocommerce

ActiveLibrary

ksfraser/mock-woocommerce
=========================

WooCommerce mocks, factories, and assertions for unit testing WooCommerce plugins

00PHP

Since Mar 22Pushed 1mo agoCompare

[ Source](https://github.com/ksfraser/Mock-Woocommerce)[ Packagist](https://packagist.org/packages/ksfraser/mock-woocommerce)[ RSS](/packages/ksfraser-mock-woocommerce/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Mock WooCommerce
================

[](#mock-woocommerce)

WooCommerce-specific mocks and test utilities for unit testing WooCommerce plugins without requiring a full WooCommerce installation.

**Namespace**: `ksfraser\MockWooCommerce\`
**Requirement**: PHP 7.3+
**Dependencies**: [ksfraser/mock-wordpress](../mock-wordpress)

Features
--------

[](#features)

- **WC Product Mock** (`WCProduct`) - Simulates WC\_Product with all essential methods
- **WC Order Mock** (`WCOrder`) - Simulates WC\_Order for order testing
- **Product Factory** - Fluent builder for test products
- **Order Factory** - Fluent builder for test orders
- **Payment Assertions** - Verify payment processing

Installation
------------

[](#installation)

```
composer require ksfraser/mock-woocommerce --dev
```

Or use file-based repository during development:

```
{
  "repositories": [
    {"type": "path", "url": "../mock-wordpress"},
    {"type": "path", "url": "../mock-woocommerce"}
  ],
  "require-dev": {
    "ksfraser/mock-woocommerce": "^1.0"
  }
}
```

Usage
-----

[](#usage)

### Creating Test Products

[](#creating-test-products)

```
use ksfraser\MockWooCommerce\Factory\ProductFactory;

$product = (new ProductFactory())
    ->name('Auction Item')
    ->price(99.99)
    ->regularPrice(149.99)
    ->stock(5)
    ->sku('AUCTION-001')
    ->description('Premium auction item')
    ->build();

echo $product->get_name(); // "Auction Item"
echo $product->get_price(); // 99.99
echo $product->is_in_stock(); // true
```

### Creating Test Orders

[](#creating-test-orders)

```
use ksfraser\MockWooCommerce\Factory\OrderFactory;

$order = (new OrderFactory())
    ->customerId(42)
    ->total(99.99)
    ->status('completed')
    ->paymentMethod('stripe')
    ->transactionId('txn_12345')
    ->addProduct(product_id: 1, quantity: 1, total: 99.99)
    ->build();

echo $order->get_id(); // Auto-incremented order ID
echo $order->get_total(); // 99.99
echo $order->is_paid(); // true
```

### Product Testing

[](#product-testing)

```
use ksfraser\MockWooCommerce\Mock\WCProduct;

$product = new WCProduct(123);
$product->set_name('Test Product');
$product->set_price(29.99);
$product->set_stock_quantity(10);
$product->set_sku('TEST-001');
$product->set_meta('_auction_price', '24.99');

if ($product->is_in_stock()) {
    echo "Product in stock";
}

$auction_price = $product->get_meta('_auction_price');
```

### Order Testing

[](#order-testing)

```
use ksfraser\MockWooCommerce\Mock\WCOrder;

$order = new WCOrder(456);
$order->set_customer_id(42);
$order->set_status('pending');
$order->set_payment_method('stripe');
$order->set_total(199.99);

$order->add_item([
    'product_id' => 1,
    'quantity' => 2,
    'total' => 199.99,
]);

$order->payment_complete();
echo $order->get_status(); // "processing"
```

Components
----------

[](#components)

### WCProduct

[](#wcproduct)

Mock WooCommerce product:

```
$product = new WCProduct(product_id: 1);

// Setters
$product->set_name('Name');
$product->set_price(9.99);
$product->set_regular_price(19.99);
$product->set_sale_price(9.99);
$product->set_type('simple');
$product->set_status('publish');
$product->set_description('Description');
$product->set_sku('SKU-001');
$product->set_stock_quantity(10);
$product->set_manage_stock(true);
$product->set_meta('key', 'value');

// Getters
$product->get_id();
$product->get_name();
$product->get_price();
$product->get_regular_price();
$product->get_sale_price();
$product->get_type();
$product->get_status();
$product->get_description();
$product->get_sku();
$product->get_stock_quantity();
$product->get_manage_stock();
$product->get_meta('key');
$product->is_in_stock();
$product->get_data();
```

### WCOrder

[](#wcorder)

Mock WooCommerce order:

```
$order = new WCOrder(order_id: 1);

// Setters
$order->set_customer_id(42);
$order->set_status('completed');
$order->set_total(99.99);
$order->set_currency('USD');
$order->set_payment_method('stripe');
$order->set_transaction_id('txn_12345');
$order->set_meta('key', 'value');

// Getters
$order->get_id();
$order->get_customer_id();
$order->get_status();
$order->get_total();
$order->get_currency();
$order->get_payment_method();
$order->get_transaction_id();
$order->get_meta('key');
$order->get_items();
$order->get_item(item_id: 1);
$order->is_paid();
$order->get_formatted_order_total();

// Item management
$order->add_item(['product_id' => 1, 'quantity' => 2]);

// Payment
$order->payment_complete(); // Sets status to 'processing'
```

### ProductFactory

[](#productfactory)

Fluent builder for WooCommerce products:

```
$product = (new ProductFactory())
    ->id(123)
    ->name('Product Name')
    ->price(99.99)
    ->regularPrice(149.99)
    ->salePrice(79.99)
    ->type('simple')  // or 'variable'
    ->stock(10)
    ->sku('SKU-001')
    ->description('Product description')
    ->shortDescription('Short desc')
    ->meta('_custom_field', 'value')
    ->inStock()  // Helper
    ->simple()  // Helper for type
    ->build();
```

### OrderFactory

[](#orderfactory)

Fluent builder for WooCommerce orders:

```
$order = (new OrderFactory())
    ->id(456)
    ->customerId(42)
    ->status('completed')  // or pending(), processing(), refunded()
    ->total(99.99)
    ->currency('USD')
    ->paymentMethod('stripe')
    ->transactionId('txn_12345')
    ->addProduct(product_id: 1, quantity: 2, total: 99.99)
    ->addItem(['product_id' => 2, 'quantity' => 1, 'total' => 49.99])
    ->build();
```

Running Tests
-------------

[](#running-tests)

```
vendor/bin/phpunit
vendor/bin/phpunit tests/Factory/ProductFactoryTest.php
vendor/bin/phpunit --coverage-html=coverage
```

Test Coverage
-------------

[](#test-coverage)

- Comprehensive tests for all mocks and factories
- 100% code coverage for mock components
- Run with: ```
    composer test-coverage
    ```

Dependencies
------------

[](#dependencies)

- PHPUnit 9.6+
- PHP 7.3+
- [ksfraser/mock-wordpress](../mock-wordpress) - WordPress mocks

Related Packages
----------------

[](#related-packages)

- [ksfraser/mock-wordpress](../mock-wordpress) - WordPress mocks (dependency)
- [ksfraser/test-factories](../test-factories) - Auction-specific test builders

License
-------

[](#license)

GPL 3.0 or later

Contributing
------------

[](#contributing)

When extending mocks:

1. Follow PSR-12 code standards
2. Add PHPDoc documentation with `@requirement` tags
3. Ensure fluent interfaces for factories
4. Include 100% unit test coverage
5. Update this README with usage examples

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance60

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c8870cc04b29a973eed9ad367a936ab274d744de37ff0c35fa0540a932905271?d=identicon)[ksfraser](/maintainers/ksfraser)

---

Top Contributors

[![ksfraser](https://avatars.githubusercontent.com/u/54461925?v=4)](https://github.com/ksfraser "ksfraser (1 commits)")

### Embed Badge

![Health badge](/badges/ksfraser-mock-woocommerce/health.svg)

```
[![Health](https://phpackages.com/badges/ksfraser-mock-woocommerce/health.svg)](https://phpackages.com/packages/ksfraser-mock-woocommerce)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
