Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
68 lines
1.7 KiB
PHP
68 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
if (! class_exists('wpdb')) {
|
|
/**
|
|
* Minimal wpdb for unit tests. prepare()/esc_like() behave like the real ones
|
|
* closely enough for assertions on the generated SQL; query methods are meant
|
|
* to be mocked via Mockery::mock(wpdb::class)->makePartial().
|
|
*/
|
|
class wpdb
|
|
{
|
|
public $prefix = 'wp_';
|
|
public $posts = 'wp_posts';
|
|
public $postmeta = 'wp_postmeta';
|
|
public $usermeta = 'wp_usermeta';
|
|
public $options = 'wp_options';
|
|
public $insert_id = 0;
|
|
|
|
public function prepare($query, ...$args)
|
|
{
|
|
if (count($args) === 1 && is_array($args[0])) {
|
|
$args = $args[0];
|
|
}
|
|
// Quotes string placeholders but does not escape, so tests can assert on raw values.
|
|
$query = str_replace("'%s'", '%s', $query);
|
|
$query = str_replace('%s', "'%s'", $query);
|
|
|
|
return vsprintf($query, $args);
|
|
}
|
|
|
|
public function esc_like($text)
|
|
{
|
|
return addcslashes($text, '_%\\');
|
|
}
|
|
|
|
public function get_charset_collate()
|
|
{
|
|
return 'DEFAULT CHARACTER SET utf8mb4';
|
|
}
|
|
|
|
public function insert($table, $data, $format = null)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
public function query($query)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
public function get_col($query = null, $x = 0)
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function get_var($query = null, $x = 0, $y = 0)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public function get_results($query = null, $output = 'OBJECT')
|
|
{
|
|
return [];
|
|
}
|
|
}
|
|
}
|