Skip to content

Commit 8efea15

Browse files
Sarthak JaiswalSarthak Jaiswal
authored andcommitted
Update test case for ignored lined
1 parent a248246 commit 8efea15

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

plugins/auto-sizes/includes/auto-sizes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function auto_sizes_update_image_attributes( $attr ): array {
4949
*/
5050
function auto_sizes_update_content_img_tag( $html ): string {
5151
if ( ! is_string( $html ) ) {
52-
$html = ''; // @codeCoverageIgnore
52+
$html = '';
5353
}
5454

5555
$processor = new WP_HTML_Tag_Processor( $html );

plugins/auto-sizes/includes/improve-calculate-sizes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
function auto_sizes_prime_attachment_caches( $content ): string {
1818
if ( ! is_string( $content ) ) {
19-
return ''; // @codeCoverageIgnore
19+
return '';
2020
}
2121

2222
$processor = new WP_HTML_Tag_Processor( $content );

plugins/auto-sizes/tests/test-auto-sizes.php

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,6 @@ public function data_provider_for_auto_sizes_update_image_attributes(): array {
346346
'sizes' => 'auto, 100vw',
347347
),
348348
),
349-
350-
// Test when $attr is not an array.
351-
array(
352-
'attr' => array(),
353-
'expected' => array(),
354-
),
355349
);
356350
}
357351

@@ -366,4 +360,31 @@ public function data_provider_for_auto_sizes_update_image_attributes(): array {
366360
public function test_auto_sizes_update_image_attributes( array $attr, array $expected ): void {
367361
$this->assertSame( $expected, auto_sizes_update_image_attributes( $attr ) );
368362
}
363+
364+
/**
365+
* @covers ::auto_sizes_update_content_img_tag
366+
*/
367+
public function test_auto_sizes_update_content_img_tag_non_string_input(): void {
368+
/*
369+
These tests are separate from the data provider approach because the function
370+
auto_sizes_update_content_img_tag() expects a string as an argument. Passing a non-string
371+
value would cause a TypeError. These tests ensure that the function behaves as expected
372+
when it receives non-string inputs.
373+
*/
374+
$this->assertSame( '', auto_sizes_update_content_img_tag( array() ) );
375+
}
376+
377+
/**
378+
* @covers ::auto_sizes_update_image_attributes
379+
*/
380+
public function test_auto_sizes_update_image_attributes_with_null_input(): void {
381+
/*
382+
This test is separate because the main test method uses a data provider
383+
that expects the $attr parameter to be an array. Passing null directly
384+
would cause a TypeError due to the type hint. By testing null separately,
385+
we ensure that the function can handle null inputs gracefully without
386+
modifying the type hint in the main test method.
387+
*/
388+
$this->assertSame( array(), auto_sizes_update_image_attributes( null ) );
389+
}
369390
}

0 commit comments

Comments
 (0)