From e6761c8fdfd6b37c2a1e07c71f899f8e50367ccf Mon Sep 17 00:00:00 2001 From: peptiderepo Date: Fri, 12 Jun 2026 13:58:09 +0000 Subject: [PATCH] fix(tests): stub get_temp_dir/wp_get_image_editor/is_wp_error in GD-rung test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test test_gd_rung_emits_passthrough_featured_and_single_warning forced the capability to 'gd' via the filter override, causing the orchestrator to instantiate PRAutoBlogger_Image_Composer_Editor and call compose_variants(). Inside cover_crop(), get_temp_dir() was the first WP function called — unstubbed, Brain Monkey 2.x threw LogicException on all three PHP versions. Add the three stubs that ImageComposerEditorTest already uses for the same code path (same house pattern): - get_temp_dir → sys_get_temp_dir() . '/' - wp_get_image_editor → WP_Error (no GD editor in test env) - is_wp_error → isinstance alias With wp_get_image_editor returning WP_Error, cover_crop() returns null for every role → compose_variants() returns [] → the GD rung emits array_merge($passthrough, []) = only the pass-through featured. The existing assertions (assertNotEmpty, assertSame 'featured', assertSame 'raw_base_bytes') all fire against a real execution path and cannot pass trivially — this is the actual degradation-to-passthrough contract. Assertions are not weakened. Agent-Session: engineer-prab-maint-fix-20260612 --- tests/unit/Core/ImageComposerTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/unit/Core/ImageComposerTest.php b/tests/unit/Core/ImageComposerTest.php index 502bfa4..3df7596 100644 --- a/tests/unit/Core/ImageComposerTest.php +++ b/tests/unit/Core/ImageComposerTest.php @@ -340,6 +340,19 @@ class ImageComposerTest extends BaseTestCase { $renderer->expects( $this->never() )->method( 'compose_og' ); $renderer->expects( $this->never() )->method( 'compose_square' ); + // Stub the WP functions that cover_crop() calls inside the GD rung. + // get_temp_dir() is called first; wp_get_image_editor() returning WP_Error + // makes cover_crop() return null for every role → compose_variants() returns [] + // → the GD rung emits only the pass-through featured (array_merge($passthrough, [])). + // This is the real degradation-to-passthrough path the test is designed to assert. + Functions\when( 'get_temp_dir' )->justReturn( sys_get_temp_dir() . '/' ); + Functions\when( 'wp_get_image_editor' )->justReturn( + new \WP_Error( 'no_editor', 'Mock: no GD editor in test environment' ) + ); + Functions\when( 'is_wp_error' )->alias( static function ( $val ) { + return $val instanceof \WP_Error; + } ); + $composer = new \PRAutoBlogger_Image_Composer( $renderer ); $variants = $composer->compose( $this->image_data, $this->context() );