From ec1efee5e6557193340a80c460cd76ff65bb0515 Mon Sep 17 00:00:00 2001 From: peptiderepo Date: Tue, 21 Apr 2026 08:46:48 +0700 Subject: [PATCH] test(cost): widen $wpdb mock so ResearchReaperTest actually runs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- tests/unit/Core/ResearchReaperTest.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/unit/Core/ResearchReaperTest.php b/tests/unit/Core/ResearchReaperTest.php index 476a1d6..75d0a73 100644 --- a/tests/unit/Core/ResearchReaperTest.php +++ b/tests/unit/Core/ResearchReaperTest.php @@ -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 );