test(cost): widen $wpdb mock so ResearchReaperTest actually runs

BaseTestCase::create_mock_wpdb() only adds methods
[prepare, get_var, get_results, insert, query, get_row, update] — the
reaper and amortize_research_costs also call `delete` and `get_col`,
which the default mock can't stub. CI on PR #100 fired all five new
ResearchReaperTest cases as errors at the first `->method('delete')`
call during setUp.

Fix: build a bespoke $wpdb mock in this file's setUp with the full
superset of methods it needs. Self-contained; no change to
BaseTestCase so existing tests aren't affected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
peptiderepo
2026-04-21 08:46:48 +07:00
parent 9d86b75a5a
commit ec1efee5e6

View File

@@ -60,8 +60,16 @@ class ResearchReaperTest extends BaseTestCase {
$this->orphan_fixtures = [];
$this->gen_log_post_ids = [];
$this->wpdb = $this->create_mock_wpdb();
$this->wpdb->insert_id = 1;
// Bespoke $wpdb mock — BaseTestCase::create_mock_wpdb() doesn't
// stub `delete` or `get_col`, both of which the reaper + amortize
// call into. Wide-method mock keeps the test scope self-contained.
$this->wpdb = $this->getMockBuilder( \stdClass::class )
->addMethods( [ 'prepare', 'get_var', 'get_results', 'get_row', 'get_col', 'insert', 'delete', 'update', 'query' ] )
->getMock();
$this->wpdb->prefix = 'wp_';
$this->wpdb->insert_id = 1;
$this->wpdb->last_error = '';
$this->wpdb->prab_cost_logs = 'wp_prab_cost_logs';
$this->wpdb->method( 'insert' )->willReturnCallback(
function ( $table, $row ) {
$this->inserted_rows[] = array_merge( [ '__table' => $table ], $row );