fix(tests): stub get_temp_dir/wp_get_image_editor/is_wp_error in GD-rung test

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
This commit is contained in:
peptiderepo
2026-06-12 13:58:09 +00:00
parent b0fde2b686
commit e6761c8fdf

View File

@@ -340,6 +340,19 @@ class ImageComposerTest extends BaseTestCase {
$renderer->expects( $this->never() )->method( 'compose_og' ); $renderer->expects( $this->never() )->method( 'compose_og' );
$renderer->expects( $this->never() )->method( 'compose_square' ); $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 ); $composer = new \PRAutoBlogger_Image_Composer( $renderer );
$variants = $composer->compose( $this->image_data, $this->context() ); $variants = $composer->compose( $this->image_data, $this->context() );