From c2e28b2b050f5fa4b1d220f4ffda0551a0e2a309 Mon Sep 17 00:00:00 2001 From: Nestor Soriano Date: Fri, 24 Jul 2020 14:51:37 +0200 Subject: [PATCH] Replace array_merge_recursive in MockableLegacyProxy with custom code test_static_mocks_can_be_used_via_injected_legacy_proxy_and_woocommerce_object was failing in PHP 7.0, this replacement fixes it. Suspected cause: https://bugs.php.net/bug.php?id=76505 --- .../DependencyManagement/MockableLegacyProxy.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/Tools/DependencyManagement/MockableLegacyProxy.php b/tests/Tools/DependencyManagement/MockableLegacyProxy.php index 7c6ed9e3894..abd1ce95d32 100644 --- a/tests/Tools/DependencyManagement/MockableLegacyProxy.php +++ b/tests/Tools/DependencyManagement/MockableLegacyProxy.php @@ -86,7 +86,16 @@ class MockableLegacyProxy extends \Automattic\WooCommerce\Proxies\LegacyProxy { } } - $this->mocked_statics = array_merge_recursive( $this->mocked_statics, $mocks ); + // TODO: replace the following with just "$this->mocked_statics = array_merge_recursive( $this->mocked_statics, $mocks )" once the minimum PHP version is bumped to 7.1 or newer (see https://bugs.php.net/bug.php?id=76505). + + $class_names = array_keys( $mocks ); + foreach ( $class_names as $class_name ) { + if ( array_key_exists( $class_name, $this->mocked_statics ) ) { + $this->mocked_statics[ $class_name ] = array_merge( $this->mocked_statics[ $class_name ], $mocks[ $class_name ] ); + } else { + $this->mocked_statics[ $class_name ] = $mocks[ $class_name ]; + } + } } /**