Code Modernization: Remove dynamic properties in Tests_Media_GetPostGalleries.

Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.

In this particular case, the test class contains a `set_up()` method that sets the `$img_meta` property, which is ''used'' by the tests, but never ''changed'' by the tests.

In other words, setting this property in the `set_up()` is an unnecessary overhead and the property should be changed to a class constant.

Includes renaming the test class to match the [https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization naming conventions].

Follow-up to [52190], [53557], [53558], [53850], [53851].

Props jrf.
See #56033.

git-svn-id: https://develop.svn.wordpress.org/trunk@53852 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2022-08-07 14:32:55 +00:00
parent 8b98406a17
commit 9d2f309e63

View File

@@ -4,16 +4,13 @@
*
* @covers ::get_post_galleries
*/
class Tests_Functions_getPostGalleries extends WP_UnitTestCase {
class Tests_Media_GetPostGalleries extends WP_UnitTestCase {
public function set_up() {
parent::set_up();
$this->img_meta = array(
'width' => 100,
'height' => 100,
'sizes' => '',
);
}
const IMG_META = array(
'width' => 100,
'height' => 100,
'sizes' => '',
);
/**
* Tests that an empty array is returned for a post that does not exist.
@@ -569,7 +566,7 @@ BLOB;
'post_type' => 'attachment',
)
);
$metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta );
$metadata = array_merge( array( 'file' => "image$i.jpg" ), self::IMG_META );
wp_update_attachment_metadata( $attachment_id, $metadata );
$ids[] = $attachment_id;
$url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg";
@@ -658,7 +655,7 @@ BLOB;
'post_type' => 'attachment',
)
);
$metadata = array_merge( array( 'file' => 'image1.jpg' ), $this->img_meta );
$metadata = array_merge( array( 'file' => 'image1.jpg' ), self::IMG_META );
$url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . 'image1.jpg';
$global_post_id = $this->factory->post->create(
array(
@@ -838,7 +835,7 @@ BLOB;
'post_type' => 'attachment',
)
);
$metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta );
$metadata = array_merge( array( 'file' => "image$i.jpg" ), self::IMG_META );
wp_update_attachment_metadata( $attachment_id, $metadata );
$ids[] = $attachment_id;
$url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg";
@@ -902,7 +899,7 @@ BLOB;
'post_type' => 'attachment',
)
);
$metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta );
$metadata = array_merge( array( 'file' => "image$i.jpg" ), self::IMG_META );
wp_update_attachment_metadata( $attachment_id, $metadata );
$ids[] = $attachment_id;
$url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg";