Commit 77024ba0359 for woocommerce
commit 77024ba0359b0c5f39cb42e3f9bd6bf168e5ac01
Author: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com>
Date: Thu Jul 9 13:47:10 2026 +0300
php tests: Replace deprecated PHPUnit at() matcher in CartItems test (#66424)
diff --git a/plugins/woocommerce/changelog/phpunit-at-matcher-deprecation b/plugins/woocommerce/changelog/phpunit-at-matcher-deprecation
new file mode 100644
index 00000000000..a103b2fe0db
--- /dev/null
+++ b/plugins/woocommerce/changelog/phpunit-at-matcher-deprecation
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Replace deprecated PHPUnit at() matcher in Store API CartItems image-filtering test with an order-independent captured-arguments assertion.
diff --git a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/CartItems.php b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/CartItems.php
index c81f7cd78c3..fec10713425 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/CartItems.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/CartItems.php
@@ -364,6 +364,18 @@ class CartItems extends ControllerTestCase {
$routes = new \Automattic\WooCommerce\StoreApi\RoutesController( new \Automattic\WooCommerce\StoreApi\SchemaController( $this->mock_extend ) );
$controller = $routes->get( 'cart-items', 'v1' );
$cart = WC()->cart->get_cart();
+ $image_id = $this->products[0]->get_image_id();
+
+ // Capture warnings in the order they are logged so we can assert on them
+ // without relying on the deprecated at() matcher.
+ $logged_warnings = array();
+ $this->mock_logger
+ ->method( 'warning' )
+ ->willReturnCallback(
+ function ( $message ) use ( &$logged_warnings ) {
+ $logged_warnings[] = $message;
+ }
+ );
// Ensure warning is logged when image has invalid src.
add_filter(
@@ -378,14 +390,15 @@ class CartItems extends ControllerTestCase {
1
);
- $this->mock_logger
- ->expects( $this->at( 0 ) )
- ->method( 'warning' )
- ->with( sprintf( 'After passing through woocommerce_cart_item_images filter, image with id %s did not have a valid src property.', $this->products[0]->get_image_id() ) );
-
$controller->prepare_item_for_response( current( $cart ), new \WP_REST_Request() );
remove_all_filters( 'woocommerce_store_api_cart_item_images' );
+ $this->assertContains(
+ sprintf( 'After passing through woocommerce_cart_item_images filter, image with id %s did not have a valid src property.', $image_id ),
+ $logged_warnings,
+ 'Expected a warning to be logged when the filtered image has an invalid src.'
+ );
+
// Ensure warning is logged when image has invalid thumbnail.
add_filter(
'woocommerce_store_api_cart_item_images',
@@ -399,14 +412,15 @@ class CartItems extends ControllerTestCase {
1
);
- $this->mock_logger
- ->expects( $this->at( 0 ) )
- ->method( 'warning' )
- ->with( sprintf( 'After passing through woocommerce_cart_item_images filter, image with id %s did not have a valid thumbnail property.', $this->products[0]->get_image_id() ) );
-
$controller->prepare_item_for_response( current( $cart ), new \WP_REST_Request() );
remove_all_filters( 'woocommerce_store_api_cart_item_images' );
+ $this->assertContains(
+ sprintf( 'After passing through woocommerce_cart_item_images filter, image with id %s did not have a valid thumbnail property.', $image_id ),
+ $logged_warnings,
+ 'Expected a warning to be logged when the filtered image has an invalid thumbnail.'
+ );
+
// Ensure original images are returned if filter returns a non-array.
add_filter(
'woocommerce_store_api_cart_item_images',