Commit 07d836d4607 for woocommerce
commit 07d836d46076a87bf26178d2ee21ee33ba013048
Author: Karol Manijak <20098064+kmanijak@users.noreply.github.com>
Date: Fri Jun 26 18:50:01 2026 +0200
Fix deprecated AssetDataRegistry argument notice (#66036)
* Fix deprecated AssetDataRegistry argument notice
* Add changelog entry for AssetDataRegistry notice
* Fix AssetDataRegistry deprecation test setup
diff --git a/plugins/woocommerce/changelog/fix-46349-asset-data-registry-deprecated-argument b/plugins/woocommerce/changelog/fix-46349-asset-data-registry-deprecated-argument
new file mode 100644
index 00000000000..d9191d36e69
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-46349-asset-data-registry-deprecated-argument
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Warn when deprecated AssetDataRegistry key check arguments are explicitly provided.
diff --git a/plugins/woocommerce/src/Blocks/Assets/AssetDataRegistry.php b/plugins/woocommerce/src/Blocks/Assets/AssetDataRegistry.php
index 3d2a968c895..b0e523f4efa 100644
--- a/plugins/woocommerce/src/Blocks/Assets/AssetDataRegistry.php
+++ b/plugins/woocommerce/src/Blocks/Assets/AssetDataRegistry.php
@@ -303,12 +303,15 @@ class AssetDataRegistry {
* @param string $key The key used to reference the data being registered. This should use camelCase.
* @param mixed $data If not a function, registered to the registry as is. If a function, then the
* callback is invoked right before output to the screen.
- * @param boolean $check_key_exists Deprecated. If set to true, duplicate data will be ignored if the key exists.
- * If false, duplicate data will cause an exception.
+ * @param boolean $check_key_exists Deprecated. Duplicate data will be ignored if the key exists.
*/
- public function add( $key, $data, $check_key_exists = false ) {
- if ( $check_key_exists ) {
- wc_deprecated_argument( 'Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry::add()', '8.9', 'The $check_key_exists parameter is no longer used: all duplicate data will be ignored if the key exists by default' );
+ public function add( $key, $data, $check_key_exists = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- Deprecated parameter kept for backwards compatibility.
+ if ( 3 <= func_num_args() ) {
+ wc_deprecated_argument(
+ __METHOD__ . '()',
+ '8.9',
+ 'The $check_key_exists parameter is no longer used: all duplicate data will be ignored if the key exists by default'
+ );
}
$this->add_data( $key, $data );
@@ -330,12 +333,19 @@ class AssetDataRegistry {
*
* @param string $key The key used to reference the data being registered.
* @param string $path REST API path to preload.
- * @param boolean $check_key_exists If set to true, duplicate data will be ignored if the key exists.
- * If false, duplicate data will cause an exception.
+ * @param boolean $check_key_exists Deprecated. Duplicate data will be ignored if the key exists.
*
* @throws InvalidArgumentException Only throws when site is in debug mode. Always logs the error.
*/
- public function hydrate_data_from_api_request( $key, $path, $check_key_exists = false ) {
+ public function hydrate_data_from_api_request( $key, $path, $check_key_exists = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- Deprecated parameter kept for backwards compatibility.
+ if ( 3 <= func_num_args() ) {
+ wc_deprecated_argument(
+ __METHOD__ . '()',
+ '8.9',
+ 'The $check_key_exists parameter is no longer used: all duplicate data will be ignored if the key exists by default'
+ );
+ }
+
$this->add(
$key,
function () use ( $path ) {
@@ -344,8 +354,7 @@ class AssetDataRegistry {
}
$response = Package::container()->get( Hydration::class )->get_rest_api_response_data( $path );
return $response['body'] ?? '';
- },
- $check_key_exists
+ }
);
}
diff --git a/plugins/woocommerce/tests/php/src/Blocks/Assets/AssetDataRegistry.php b/plugins/woocommerce/tests/php/src/Blocks/Assets/AssetDataRegistry.php
index 2663359c8f4..4958717dbcf 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/Assets/AssetDataRegistry.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/Assets/AssetDataRegistry.php
@@ -17,6 +17,8 @@ class AssetDataRegistry extends \WP_UnitTestCase {
private $registry;
protected function setUp(): void {
+ parent::setUp();
+
$this->registry = new AssetDataRegistryMock(
Package::container()->get( API::class )
);
@@ -31,6 +33,33 @@ class AssetDataRegistry extends \WP_UnitTestCase {
$this->assertEquals( [ 'test' => 'foo' ], $this->registry->get() );
}
+ /**
+ * @testdox Deprecated key check argument triggers deprecation notice for explicit values.
+ *
+ * @dataProvider deprecated_key_check_argument_values
+ *
+ * @param bool $check_key_exists Deprecated key check argument value.
+ */
+ public function test_add_data_with_deprecated_key_check_argument_triggers_deprecation( $check_key_exists ) {
+ $this->setExpectedDeprecated( 'Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry::add()' );
+
+ $this->registry->add( 'test', 'foo', $check_key_exists );
+
+ $this->assertEquals( [ 'test' => 'foo' ], $this->registry->get() );
+ }
+
+ /**
+ * Provides explicit deprecated key check argument values.
+ *
+ * @return array[]
+ */
+ public function deprecated_key_check_argument_values() {
+ return [
+ 'true' => [ true ],
+ 'false' => [ false ],
+ ];
+ }
+
public function test_data_exists() {
$this->registry->add( 'foo', 'lorem-ipsum' );
$this->assertEquals( true, $this->registry->exists( 'foo' ) );
@@ -54,6 +83,26 @@ class AssetDataRegistry extends \WP_UnitTestCase {
$this->registry->add( [ 'some_value' ], 'foo' );
}
+ /**
+ * @testdox Hydrating data does not trigger deprecation notice when key check argument is omitted.
+ */
+ public function test_hydrate_data_from_api_request_without_key_check_argument_does_not_trigger_deprecation() {
+ $this->registry->hydrate_data_from_api_request( 'test', '/wc/store/v1/test' );
+
+ $this->assertEmpty( $this->registry->get() );
+ }
+
+ /**
+ * @testdox Hydrating data with deprecated key check argument triggers deprecation notice.
+ */
+ public function test_hydrate_data_from_api_request_with_deprecated_key_check_argument_triggers_deprecation() {
+ $this->setExpectedDeprecated( 'Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry::hydrate_data_from_api_request()' );
+
+ $this->registry->hydrate_data_from_api_request( 'test', '/wc/store/v1/test', false );
+
+ $this->assertEmpty( $this->registry->get() );
+ }
+
/**
* This tests the 'woocommerce_shared_settings' filter.
*/