Fix dynamic property creation warning in `class-woocommerce.php` (#36545)

Declares $api as a public property to the WooCommerce class in order to avoid a deprecation warning that will eventually be an error in upcoming PHP versions.
This commit is contained in:
Willington Vega 2023-01-25 20:25:27 -05:00 committed by GitHub
parent a274057a6e
commit 7ef4fef53a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Define a public `api` property in the WooCommerce class to prevent a PHP deprecation warning

View File

@ -65,6 +65,13 @@ final class WooCommerce {
*/
public $query = null;
/**
* API instance
*
* @var WC_API
*/
public $api;
/**
* Product factory instance.
*

View File

@ -0,0 +1,17 @@
<?php
/**
* Unit tests for the WooCommerce class.
*/
class WooCommerce_Test extends \WC_Unit_Test_Case {
/**
* Test that the $api property is defined, public and initialized correctly.
*/
public function test_api_property(): void {
$property = new ReflectionProperty( WooCommerce::class, 'api' );
$this->assertTrue( $property->isPublic() );
$this->assertInstanceOf( WC_API::class, $property->getValue( WC() ) );
}
}