<?php
/**
 * PHPUnit bootstrap for the Woo plugin unit tests.
 *
 * Plugin source files guard with `if ( ! defined( 'ABSPATH' ) ) exit;`, so ABSPATH
 * must be defined before any class is autoloaded — otherwise loading a class would
 * terminate the test process. WordPress itself is NOT loaded; WP functions are
 * stubbed per-test with Brain Monkey.
 */

// Define ABSPATH before the autoloader runs: if Composer ever autoloads a plugin
// file (classmap/files), its `if ( ! defined( 'ABSPATH' ) ) exit;` guard would
// otherwise terminate the test process at require time.
if ( ! defined( 'ABSPATH' ) ) {
	define( 'ABSPATH', __DIR__ . '/' );
}

require __DIR__ . '/../vendor/autoload.php';

// Minimal stub for the WooCommerce gateway base class so gateway classes (which
// `extends WC_Payment_Gateway`) can be loaded in isolation. WooCommerce is not present
// in the unit-test runtime; tests exercise pure methods via reflection, not WC behaviour.
if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
	class WC_Payment_Gateway {} // phpcs:ignore
}

// Minimal WC_Order stub so `WC_Order` type-hints resolve and tests can define small
// fake orders extending it. Centralized here so test files don't each carry their own
// guarded alias copy (older tests keep a local `class_exists` guard, which now no-ops).
if ( ! class_exists( 'WC_Order' ) ) {
	class WC_Order {} // phpcs:ignore
}

// Minimal WC_DateTime stub so date-bearing tests can construct real DateTime instances
// that satisfy the `?WC_DateTime` type-hint on Order_DTO_Factory::format_api_datetime().
if ( ! class_exists( 'WC_DateTime' ) ) {
	class WC_DateTime extends DateTime {} // phpcs:ignore
}

// Minimal stub for the wp-background-processing library base class (bundled by WooCommerce at
// runtime, not present in the unit-test runtime) so `SimplyIn_Background_Process extends
// WP_Background_Process` can load. Deliberately empty: tests build the SUT with the
// constructor disabled (PHPUnit mock builder) and exercise task()/createOrder() directly via
// reflection, never the real queue/cron machinery.
if ( ! class_exists( 'WP_Background_Process' ) ) {
	class WP_Background_Process {} // phpcs:ignore
}
