From 666d0736f45cfa133fb888eb18dfef760b849fb8 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 15 Dec 2015 18:28:55 +0000 Subject: [PATCH] Ensure `wp_list_pluck()` throws a warning when not being passed an array. We should not paper over the code and hide warnings from developers by casting values to an array. See #35087. git-svn-id: https://develop.svn.wordpress.org/trunk@35949 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/functions/listFilter.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/phpunit/tests/functions/listFilter.php b/tests/phpunit/tests/functions/listFilter.php index 9fe640a261..6532f97879 100644 --- a/tests/phpunit/tests/functions/listFilter.php +++ b/tests/phpunit/tests/functions/listFilter.php @@ -110,6 +110,19 @@ class Tests_Functions_ListFilter extends WP_UnitTestCase { $this->assertEquals( array( 'f' => 'foo', 'b' => 'bar', 'z' => 'baz' ), $list ); } + /** + * When not being passed an array, the function should throw a warning. + * + * @ticket 35087 + * @expectedException PHPUnit_Framework_Error_Warning + */ + function test_wp_list_pluck_non_array() { + $object = new stdClass(); + $object->foo = 'abc'; + $object->bar = 'def'; + wp_list_pluck( $object, 'test' ); + } + function test_filter_object_list_nested_array_and() { $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'blue' ) ), 'AND' ); $this->assertEquals( 1, count( $list ) );