forked from Solo-Web-Works/Projects-Portfolio
84 lines
2.8 KiB
PHP
84 lines
2.8 KiB
PHP
<?php
|
|
// Load Composer dev autoload (PHPUnit + Brain\Monkey + polyfills).
|
|
$autoload = dirname( __DIR__ ) . '/vendor/autoload.php';
|
|
if ( ! file_exists( $autoload ) ) {
|
|
fwrite( STDERR, "Run `composer install` before running tests.\n" );
|
|
exit( 1 );
|
|
}
|
|
require_once $autoload;
|
|
|
|
// Brain\Monkey sets up minimal function stubs (apply_filters, plugin_dir_path, etc.).
|
|
\Brain\Monkey\setUp();
|
|
|
|
// Define WP constants the helpers rely on.
|
|
if ( ! defined( 'HOUR_IN_SECONDS' ) ) {
|
|
define( 'HOUR_IN_SECONDS', 3600 );
|
|
}
|
|
if ( ! defined( 'WPINC' ) ) {
|
|
define( 'WPINC', 'wp-includes' );
|
|
}
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
define( 'ABSPATH', __DIR__ . '/' );
|
|
}
|
|
|
|
// Provide minimal WordPress function stubs used by the providers under test.
|
|
if ( ! function_exists( 'get_option' ) ) {
|
|
function get_option( $key, $default = false ) { return $default; }
|
|
}
|
|
if ( ! function_exists( 'get_transient' ) ) {
|
|
function get_transient( $key ) { return false; }
|
|
}
|
|
if ( ! function_exists( 'set_transient' ) ) {
|
|
function set_transient( $key, $value, $expiration ) { return true; }
|
|
}
|
|
if ( ! function_exists( 'delete_transient' ) ) {
|
|
function delete_transient( $key ) { return true; }
|
|
}
|
|
if ( ! function_exists( 'wp_remote_get' ) ) {
|
|
function wp_remote_get( $url, $args = [] ) { return new \WP_Error( 'no_http', 'no http' ); }
|
|
}
|
|
if ( ! function_exists( 'is_wp_error' ) ) {
|
|
function is_wp_error( $thing ) { return $thing instanceof \WP_Error; }
|
|
}
|
|
if ( ! function_exists( 'wp_remote_retrieve_response_code' ) ) {
|
|
function wp_remote_retrieve_response_code( $response ) {
|
|
if ( $response instanceof \WP_Error ) { return 0; }
|
|
return $response['response']['code'] ?? 0;
|
|
}
|
|
}
|
|
if ( ! function_exists( 'wp_remote_retrieve_body' ) ) {
|
|
function wp_remote_retrieve_body( $response ) {
|
|
if ( $response instanceof \WP_Error ) { return ''; }
|
|
return $response['body'] ?? '';
|
|
}
|
|
}
|
|
if ( ! function_exists( 'wp_remote_retrieve_header' ) ) {
|
|
function wp_remote_retrieve_header( $response, $header ) {
|
|
if ( $response instanceof \WP_Error ) { return ''; }
|
|
$headers = $response['headers'] ?? [];
|
|
$key = strtolower( $header );
|
|
return $headers[ $key ] ?? '';
|
|
}
|
|
}
|
|
if ( ! function_exists( 'error_log' ) ) {
|
|
function error_log( $message ) { /* swallow during tests */ }
|
|
}
|
|
|
|
// Minimal WP_Error stub if Brain\Monkey doesn't supply one.
|
|
if ( ! class_exists( 'WP_Error' ) ) {
|
|
class WP_Error {
|
|
private $code;
|
|
private $message;
|
|
public function __construct( $code = '', $message = '' ) {
|
|
$this->code = $code;
|
|
$this->message = $message;
|
|
}
|
|
public function get_error_code() { return $this->code; }
|
|
public function get_error_message() { return $this->message; }
|
|
}
|
|
}
|
|
|
|
register_shutdown_function( function () {
|
|
\Brain\Monkey\tearDown();
|
|
} );
|